net.contargo:validation

Validation is a small library for validation purposes

License

License

Categories

Categories

Net
GroupId

GroupId

net.contargo
ArtifactId

ArtifactId

validation
Last Version

Last Version

1.1
Release Date

Release Date

Type

Type

jar
Description

Description

net.contargo:validation
Validation is a small library for validation purposes
Project URL

Project URL

https://github.com/Contargo/validation
Project Organization

Project Organization

Contargo GmbH & Co. KG
Source Code Management

Source Code Management

https://github.com/contargo/validation

Download validation

How to add to project

<!-- https://jarcasting.com/artifacts/net.contargo/validation/ -->
<dependency>
    <groupId>net.contargo</groupId>
    <artifactId>validation</artifactId>
    <version>1.1</version>
</dependency>
// https://jarcasting.com/artifacts/net.contargo/validation/
implementation 'net.contargo:validation:1.1'
// https://jarcasting.com/artifacts/net.contargo/validation/
implementation ("net.contargo:validation:1.1")
'net.contargo:validation:jar:1.1'
<dependency org="net.contargo" name="validation" rev="1.1">
  <artifact name="validation" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.contargo', module='validation', version='1.1')
)
libraryDependencies += "net.contargo" % "validation" % "1.1"
[net.contargo/validation "1.1"]

Dependencies

provided (1)

Group / Artifact Type Version
javax.validation : validation-api jar 1.1.0.Final

test (3)

Group / Artifact Type Version
junit : junit jar 4.12
org.hamcrest : hamcrest-all jar 1.3
org.mockito : mockito-all jar 1.10.19

Project Modules

There are no modules declared in this project.

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

net.contargo

Contargo GmbH & Co. KG

Versions

Version
1.1