Giter VIP home page Giter VIP logo

big-decimal-validator's Introduction

Build Status

BigDecimal Validator

The BigDecimal Validator is a small library to validate java.math.BigDecimal

Features

  • Validation of BigDecimals via Service or Annotation
    • Maximal/Minimal decimal places
    • Maximal fractional places
    • Maximal/Minimal value

#Prerequisites

  • Maven 3 or higher
  • JDK 7 or higher

Examples

Annotation driven

Test if the value of an attribute of an entity and the number of the decimal and fractional places are in the correct range.

public class Price {

    @BigDecimalValidate(
     minDecimalPlaces = 1,
     maxDecimalPlaces = 3,
     maxFractionalPlaces = 2,
     minValue = 0.00,
     maxValue = 500.00
    )
    private BigDecimal value;
    
    // Getters and Setters
}

You can also specify the message that would be shown if the validation would throw an error by adding the message property.

Service driven

public void function() {

 BigDecimalValidator validator = new BigDecimalValidator();
 
 BigDecimalValidationRules rules = new BigDecimalValidationRules.Builder()
  .minDecimalPlaces(1)
  .maxDecimalPlaces(3)
  .maxFractionalPlaces(2)
  .minValue(0.00)
  .maxValue(500.00)
  .build();
 
 BigDecimalValidationResult result = validator.validate(new BigDecimal("250.00"), rules);
 
 if(!result.isValid()) {
  System.out.println(result.getFailMessage());
 }
}

#Getting started

Simply clone this repository

$ git clone https://github.com/Contargo/big-decimal-validator.git

Build

You can run a full build including all tests with

$ mvn clean install

License

BigDecimal Validator is licensed under the Apache 2.0-license

big-decimal-validator's People

Contributors

dertobsch avatar greenhalos avatar dependabot[bot] avatar sandra-thieme avatar

Watchers

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