A Java library for structuring business rules.
bspec-java
can be included in any Java or Android application.
Add the following line to the dependencies
section of your build.gradle
file:
compile 'com.github.gchudnov.bspec:bspec:0.9.0'
The essential part of the library is a specification -- an object with the following properties:
- it can be combined with other specification-objects using
.and()
,.or()
and.not()
methods to form a composite specification and express more complex rules. - it implements
isSatisfiedBy
method -- a predicate that determines whether a candidate object does or does not satisfy some criteria.
To create a composable specification, extend CompositeSpecification
and define the isSatisfiedBy
method to check for some condition.
the and of a set of specifications is true if and only if all of its operands are true.
spec = spec1.and(spec2);
the or of a set of specifications is true if and only if one or more of its operands is true
spec = spec1.or(spec2);
not negates the specification
spec = spec1.not();
checks whether some candidate object satisfies the specification.
boolean result = spec.isSatisfiedBy(obj);
// `result` true|false value
For the details of usage, take a look at the examples section in the project.
[Grigoriy Chudnov] (mailto:[email protected])
Distributed under the The MIT License (MIT).