Coder Social home page Coder Social logo

jvalidators's Introduction

jvalidators

Utility lib input validation following the Either approach.

To install

This library is not available in the maven central for now, therefore you will need to clone this repo:

git clone https://github.com/marcelus20/jvalidators

Cd into the folder:

cd jvalidators

Issue the maven clean install command:

mvn clean install

After doing the above steps, you will be able to import this lib into your project:

    <dependency>
      <groupId>com.marcelus.validators</groupId>
      <artifactId>jvalidators</artifactId>
      <version>1.0.1-SNAPSHOT</version>
    </dependency>

PS: To see what releases are available, check the tags page.


Current Features:

ArrayValidator.arrayCorrectSize(): Validates an array by checking if it contains the correct size.

Example:

    // Given
    Integer[] intArray = new Integer[]{1,5,10};
    Integer correctSize = 3;
    // When
    Either result = ArrayValidator.arrayCorrectSize(intArray, correctSize);
    // Then
    Assertions.assertTrue(result.isRight());

In the example above, the either.right() will return.

PS: If a either.left() returns, then an empty array of objects will be returned with fixed size of 0.


ListValidator.listCorrectSize(): Validates a list by checking if it contains the correct size. Example:

        // Given
        List<Integer> intArray = Arrays.asList(1,5,10);
        Integer correctSize = 50;
        // When
        Either result = ListValidator.listCorrectSize(intArray, correctSize);
        // Then
        Assertions.assertTrue(result.isLeft());

PS: either.left() returns an empty list.


NullValidator.notNull(): validates any input by checking if it is not null.

Null Arrays will return an Either.left of an array of objects with a fixed size 0.

Null Lists will return an Either.left of an empty list of the original type.

        // Given
        List<Integer> intArray = Arrays.asList(1,5,10);
        Integer correctSize = 50;
        // When
        Either result = ListValidator.listCorrectSize(intArray, correctSize);
        // Then
        Assertions.assertTrue(result.isLeft());

PS: In the example above, the Either.left is an empty list of type Integer.


FAQ

When more features are going to be added?

R: I don't have a fixed schedule for adding them nor do I know what more features to add. If I come across a situation that I need to validate something, and this validation doesn't exist in this lib, I'll go ahead and add it.

If you have an idea of what more to add, you can fill free to open an issue or open a pull request for us to discuss.

When will you add it to maven central?

R: I don't know. Perhaps if more people use it and this lib grows somehow.


Contributions

Feel free to contribute, just please consider the following:

  • Validators methods should return an Either object, where the left indicates the failure and right the success. Create methods that follow this approach.
  • All jvalidators software is distributed under the GNU General Public open source license, and your contributions will be licensed in the same way.
  • Open Pull Requests with the new codes containing passing test cases.
  • Create an issue if you want to discuss a new idea.

License

GNU GENERAL PUBLIC LICENSE

jvalidators's People

Contributors

marcelus20 avatar

Watchers

James Cloos 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.