com.robertboothby.djenni.sugar.EasyCompare Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
This module holds the core components of the Djenni data generator framework. By itself it provides most of the
components to create an efficient end to end data generation framework for a specific domain. It contains the
core
SupplierBuilder interfaces, implementations for the core Java data types and useful test components.
It is intended to be used in conjunction with the source-generator module that will speed up delivery of domain
specific data generation and also with common domain modules (TBD) that deliver standard generators for common
frameworks such as JAXB.
package com.robertboothby.djenni.sugar;
/**
* Piece of syntactic sugar intended to make it easier to work with Comparables.
* @author robertboothby
* @param The type of Comparable that we are working with.
*/
public class EasyCompare> {
private final T comparableValue;
/**
* Construct an EasyCompare with a comparable value.
* @param comparableValue The comparable value that we are basing the comparison on,
*/
public EasyCompare(T comparableValue) {
this.comparableValue = comparableValue;
}
/**
* Determine whether the comparable value encapsulated in this instance is less than the comparator.
* @param comparator The value to compare with,
* @return true if the comparable value is less than the comparator, false otherwise.
*/
public boolean lessThan(T comparator){
return comparableValue.compareTo(comparator) < 0;
}
/**
* Synonymous with {@link #lessThan(Comparable)}, this method is intended to be clearer when dealing with ordering.
* @param comparator The value to compare with,
* @return true if the comparable value is ordered before the comparator, false otherwise.
*/
public boolean before(T comparator){
return lessThan(comparator);
}
/**
* Determine whether the comparable value encapsulated in this instance is less than or equal to the comparator.
* @param comparator The value to compare with,
* @return true if the comparable value is less than or equal to the comparator, false otherwise.
*/
public boolean lessThanOrEqualTo(T comparator) {
return comparableValue.compareTo(comparator) <= 0;
}
/**
* Determine whether the comparable value encapsulated in this instance is greater than the comparator.
* @param comparator The value to compare with,
* @return true if the comparable value is greater than the comparator, false otherwise.
*/
public boolean greaterThan(T comparator) {
return comparableValue.compareTo(comparator) > 0;
}
/**
* Synonymous with {@link #greaterThan(Comparable)}, this method is intended to be clearer when dealing with ordering.
* @param comparator The value to compare with,
* @return true if the comparable value is ordered after the comparator, false otherwise.
*/
public boolean after(T comparator){
return greaterThan(comparator);
}
/**
* Determine whether the comparable value encapsulated in this instance is greater than or equal to the comparator.
* @param comparator The value to compare with,
* @return true if the comparable value is greater than or equal to the comparator, false otherwise.
*/
public boolean greaterThanOrEqualTo(T comparator) {
return comparableValue.compareTo(comparator) >= 0;
}
/**
* This method make it easy to determine whether the comparable value falls in the range defined by the two
* comparators (inclusive).
* @param lowComparator The low comparator to be used.
* @return an instance of {@link And} that takes the high comparator to be used and returns true if the comparable
* value falls in the range (inclusive)
*/
public And between(final T lowComparator) {
return new And() {
public Boolean and(T highComparator) {
return lessThanOrEqualTo(highComparator) && greaterThanOrEqualTo(lowComparator);
}
};
}
/**
* Return an instance of this class using the comparable value. This method uses a very short signature to avoid
* clutter.
* @param comparableValue the comparable value to use.
* @param The Comparable type.
* @return an instance of this class for usage.
*/
public static > EasyCompare $(T comparableValue) {
return new EasyCompare(comparableValue);
}
/**
* Return an instance of this class using the comparable value.
* @param comparableValue the comparable value to use.
* @param The Comparable type.
* @return an instance of this class for usage.
*/
public static > EasyCompare easyCompare(T comparableValue) {
return new EasyCompare(comparableValue);
}
}