Experimental validation mini-framework

Overview

ClinQ

Simple yet interesting validation mini-framework

Features

  • Declarative checks
ClinQ.checker(Integer.class)
    .with(i -> i % 2 == 0)
    .with(i -> i > 100)
    .with(i -> i < 1000)
    .check(myInteger)
  • Mapping on checks addition
ClinQ.checker(Integer.class)
    .and(i -> i % 2 == 0)
    .map(Double::valueOf)  // Map integer to double and do further checks with it
    .and(d -> Math.pow(d, 3.5) > 500)
    .check(myInteger);
  • Nested checks
    For example we have a sample data transfer object:
public class SampleDto { 
    private final String name;
    private final List<Integer> scores;

    public String getName() {
        return name;
    }

    public List<Integer> getScores() {
        return scores;
    }

    public SampleDto(String name, List<Integer> scores) {
        this.name = name;
        this.scores = scores;
    }
}

Then we can validate field-by-field using the nested checkers:

var checker =
    ClinQ.checker(SampleDto.class)
        .with(Objects::nonNull)
        .with(SampleDto::getName, nameChecker ->
            nameChecker
                .with(Objects::nonNull)
                .with(str -> str.length() > 2))
        .with(SampleDto::getScores, scoresChecker ->
            scoresChecker
                .with(Objects::nonNull)
                .with(scores -> scores.size() > 2)
                .with(scores -> scores.stream().allMatch(score -> score > 0)))
        .with(dto -> dto.getName().length() == dto.getScores().size());

SampleDto one = new SampleDto("hi!", List.of(1, 2, 3));
Assertions.assertTrue(checker.check(one));

Use it

Currently, this library can be fetched via JitPack:

Here are specified instructions for Gradle (for maven etc. they can be found at JitPack - just click on the badge above)

Step 1. Add the JitPack repository to your build file

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependency

dependencies {
        implementation 'com.github.theseems:ClinQ:v1.0-SNAPSHOT'
}

Todo

  • Debug tools (peek tokens, trace, etc.)
  • Propagation strategy: should we fail? where?
  • Dependent checks: make check depend on others.
You might also like...

Lattice is a powerful, lightweight business extension invoke framework. By using the Lattice framework, complex business customization can be efficiently organized and managed.

Lattice Framework Introduction Lattice is a powerful, lightweight business extension invoke framework. By using the Lattice framework, complex busines

Dec 30, 2022

Spring Boot starter module for gRPC framework.

Spring Boot starter module for gRPC framework.

Jan 4, 2023

Spring Boot starter module for gRPC framework.

Spring Boot starter module for gRPC framework.

Mar 17, 2021

High performance RPC framework based on netty

RPC(Remote Procedure Call)实战 @desc: 仅用于个人学习、了解RPC @date: 2021/01/16 技术组成: 版本一 版本二 版本三 传输层 Netty4 * * 编码层 Kryo * * 应用层 JDK动态代理 * * 服务注册与发现 手动注册+guava缓存

Nov 22, 2022

An annotation-based command framework for Bukkit

Blade Blade is an easy-to-use command framework based on annotations. It currently only supports Bukkit, but it can be easily extended to more platfor

Nov 6, 2022

Mars - Object Relational Mapping Framework for MongoDB (MongoDB ORM)

Mars   -  Object Relational Mapping  Framework for MongoDB  (MongoDB ORM)

Mars Object Relational Mapping Framework for MongoDB 致自己 造自己的轮子,让别人去说 ; What is Mars Mars is a unified driver platform product developed by Shanghai J

Nov 17, 2022

ESA ServiceKeeper is a lightweight service governance framework.

ServiceKeeper ServiceKeeper is a lightweight service governance framework that provides many awesome features such as rate limit, concurrent limit, ci

Aug 11, 2022

The Quotation Management application is a API REST created using Spring Boot framework.

The Quotation Management application is a API REST  created using Spring Boot framework.

✅ Quotation Management API - Done ✅ About • Features • Setup • Technologies • Author • License 💻 About The Quotation Management application is a API

Apr 29, 2022
Comments
  • Make `when` play with a consumer instead of requiring separate checker.

    Make `when` play with a consumer instead of requiring separate checker.

    Example:

    var checker = Clinq.<Some>checker()
        .when(some -> some.getField() == 2, someOther -> someOther
            .with(other -> other % 2 == 0))
    
    🌟 Enhancement 
    opened by TheSeems 0
  • Out-of-place error message and blocking declarations.

    Out-of-place error message and blocking declarations.

    It would be cool to have some long error messages separated from the check syntactically

    var checker = Clinq.<Some>checker()
        .and(smth)
          .error("oh smth does not work")
    

    with blocking:

    var checker = Clinq.<Some>checker()
        .and(smth)
          .error("oh smth does not work and it block everything")
          .blocking()
    
    🌟 Enhancement 
    opened by TheSeems 0
  • v1.2

    v1.2

    Tiny preview of features:

    • Added standalone validators
    • Wasted optional pipes
    • Added .then(...), .orElse(...) statements on when
    • Tiny bit of refactoring
    🌟 Enhancement 
    opened by TheSeems 0
  • What to do with optional pipes?

    What to do with optional pipes?

    Now it's just impossible to configure optional pipes. Need to figure out what to do with them.

    There are a few possible scenarios:

    • Delete them completely (i guess it's just of no frequent use)
    • Add support for their configuration.
    🌟 Enhancement ❓ Question 
    opened by TheSeems 1
Releases(v1.1)
Owner
Alexey Akhundov
18 y.o. student (HSE, Faculty of computer science), backend developer (Java, Go, C++).
Alexey Akhundov
A suite of software tools and services created to support activity planning and sequencing needs of missions with modeling, simulation, scheduling and validation capabilities

Aerie A suite of software tools and services created to support activity planning and sequencing needs of missions with modeling, simulation, scheduli

NASA Advanced Multi-Mission Operations System 31 Jan 3, 2023
A fun mini project in Java. Uses Interface, Inheritance, and other OOP concepts

Sequences---Arithmetic-and-Geometric A fun mini project in Java. Uses Interface, Sorting, Inheritance, and other OOP concepts About this project: This

Urjit Aich 2 Feb 18, 2022
A java mini project the "Currency Convertor".

Currency Convertor A Currency Convertor made using Java. Description This “Currency Convertor” Core Java Mini-Project is simply a calculator-like app

Aryan Agarwal 2 Oct 19, 2021
Lightweight and Necessary utilities for mini minecraft server

WithMyFriends Lightweight server tools for minimal servers. Contributing to us Version Strategy Why? Despite a huge amount of Server Essential Plugins

iceBear 6 Mar 4, 2022
Java, Spring Boot Mini Project - Library Management System - Free Download

Java, Spring Boot Mini Project - Library Management System Local setup Step 1: Download or clone the source code from GitHub to the local machine Step

Sibin Rasiya 15 Dec 27, 2022
Experimental Discord Mobile Rich Presence (Android)

MRPC Experimental Discord Mobile Rich Presence (Android) How does it work? It's pretty simple. Connect to the Discord Gateway as a normal Discord Clie

Duy Tran Khanh 41 Dec 25, 2022
Halo plug-in capacity experimental exploration.

Halo plugin experimental Halo 博客插件化的功能性探索。 简介 插件管理能力位于 extensions 目录下 plugins 目录下为插件示例 在插件和 Halo 主应用共用 ApplicationContext 还是 插件使用独立的 ApplicationContex

guqing 8 Jul 17, 2022
Catogram - Experimental telegram client based on official Android sources

Catogram Experimental telegram client based on official Android sources Features: Message translator TGX Style of context menu VKUI Icons and inbuilt

null 188 Dec 17, 2022
An experimental mod that converts some block entities to blockstates. This is done for performance & functionality reasons.

BetterBlockStates An experimental mod that converts some block entities to blockstates. This is done for performance & functionality reasons. Current

Fx Morin 10 Sep 17, 2022
💡极致性能的企业级Java服务器框架,RPC,游戏服务器框架,web应用服务器框架。(Extreme fast enterprise Java server framework, can be RPC, game server framework, web server framework.)

?? 为性能而生的万能服务器框架 ?? Ⅰ. zfoo简介 ?? 性能炸裂,天生异步,Actor设计思想,无锁化设计,基于Spring的MVC式用法的万能RPC框架 极致序列化,原生集成的目前二进制序列化和反序列化速度最快的 zfoo protocol 作为网络通讯协议 高可拓展性,单台服务器部署,

null 1k Jan 1, 2023