Giter Site home page Giter Site logo

burakim / kaptan-field-checker Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 0.0 115 KB

A Class Field Value Validation Library.

License: MIT License

Java 100.00%
java annotations input-validation pojo input-field class variables checker kaptan-field-checker opensource java-library model-checking model-view-controller validation validation-library verification regex-validator

kaptan-field-checker's Introduction

Kaptan Class Field Value Checker Build Status Codacy Badge

"Kaptan" is a Turkish word that means captain.

Kaptan is a JAVA library that checks class fields in terms of input validation and verification. If it sees any variable value violation, it immediately throws FieldViolationException.

Getting Started

How Can I Get It

Gradle

compile 'me.yesilyurt.burak:kaptan-field-checker:1.1.0'

Maven

<dependency>
  <groupId>me.yesilyurt.burak</groupId>
  <artifactId>kaptan-field-checker</artifactId>
  <version>1.1.0</version>
  <type>pom</type>
</dependency>

How Can I Use It? Javadocs

Let's say that you have a model (POJO) class whose name is User and it has username and password String fields. Let's assume that you don't want to get any null assignment for the username field and empty value assignment for the password field. You can write an input validation mechanism on your own or you can use Kaptan for checking your class fields. The below example shows a way to use Kaptan for it.

public class User {
    @MustBeNonNull
    private String username;
    @MustBeNonEmpty
    private String password;
    }

Did you realise @MustBeNonNull and @MustBeNonEmpty annotations?

Those are annotations that help Kaptan for understanding what your intentions and the structure of your class are. Since you put @MustBeNonNull above of your username field, Kaptan checks the username field if it is null. If it sees a null assignment in the username field, it throws a FieldViolationException to inform you.

Kaptan supports following annotations:

  • @MustBeNonNull
  • @MustBeNull
  • @MustBeNonEmpty
  • @MustBeEmpty
  • @EnforceSizeConstraint(min=<value>, max=<value>)
  • @EnforceRegexRule(<regex-string-value>)
  • @EnforceIntervalConstraint(min=<value>, max=<value>)
  • @MustContainsFollowingByteValues(values={,,..})
  • @MustContainsFollowingDoubleValues(values={,,..})
  • @MustContainsFollowingFloatValues(values={,,..})
  • @MustContainsFollowingIntegerValues(values={,,..})
  • @MustContainsFollowingLongValues(values={,,..})
  • @MustContainsFollowingShortIntegerValues(values={,,..})
  • @MustContainsFollowingStringValues(values={,,..})

To use Kaptan for checking your class fields

You can initiliaze a KaptanFieldChecker object, then you can continue by passing your model object (e.g. User class) into the check function of the KaptanFieldChecker object. Since it might throw a FieldViolationException, you should write a try&catch block and place the KaptanFieldChecker related code lines in your try block. You can find an example below.

try{
KaptanFieldChecker kaptanFieldChecker = new KaptanFieldChecker();
kaptanFieldChecker.check(targetObject);
}
catch(FieldViolationException e){
    // You can place your exception handling codes.
    e.printStackTrace();
}

What does Kaptan support

Kaptan supports primitives, enumerations, and data structures that are in the Java collection library, and Strings. If you want to Kaptan support your custom data structure, you can make it happen by implementing a KaptanField interface into your custom data structure.

License

This project is licensed under the MIT License - see the LICENSE file for details

Acknowledgments

This is an open-source project, we appreciate any contribution from contributors. If you want to improve Kaptan Class Field Input Checker, feel free to fork and create a pull request!

Donations

BTC: 3GaS3Vq3rowJQviRgfTBL8Qy8BMAHCpC9Q

ETH: 0x47f4b805B2927fae671751ECe7D88d2638063bE9

kaptan-field-checker's People

Contributors

burakim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.