Class QuantityFunctions
units and quantities with Java
functional interfaces like Function.- Since:
- 2.0
- Version:
- 1.0.3
- Author:
- Otavio, Werner
-
Method Summary
Modifier and TypeMethodDescriptionfiterByExcludingUnit(Unit<Q>... units) Predicate to filter excluding these unitsfiterByUnit(Unit<Q>... units) Predicate to filter to one or more unitscreates a function to group quantities by theirunit.creates a Filter to between, lesser or equals and greater or equals, than number, ignoring unitscreates a filter to between, lesser or equals and greater or equals, than the quantity measureisGreaterThan(Number value) creates a Filter to greater than number, ignoring unitsisGreaterThan(Quantity<Q> quantity) creates a filter to greater than the quantity measureisGreaterThanOrEqualTo(Number value) creates a Filter to greater or equals than number, ignoring unitsisGreaterThanOrEqualTo(Quantity<Q> quantity) creates a filter to greater or equals than the quantity measureisLessThan(Number value) creates a Filter to lesser than number, ignoring unitsisLessThan(Quantity<Q> quantity) creates a filter to lesser than the quantity measureisLessThanOrEqualTo(Number value) creates a Filter to lesser or equals than number, ignoring unitsisLessThanOrEqualTo(Quantity<Q> quantity) creates a filter to lesser or equals than the quantity measurestatic <Q extends Quantity<Q>>
BinaryOperator<Quantity<Q>>max()Creates a BinaryOperator to calculate the maximum Quantitystatic <Q extends Quantity<Q>>
BinaryOperator<Quantity<Q>>min()Creates a BinaryOperator to calculate the minimum Quantitystatic <Q extends Quantity<Q>>
Comparator<Quantity<Q>>Creates a comparator to sort by natural order, looking to both the unit and the value.static <Q extends Quantity<Q>>
Comparator<Quantity<Q>>Creates a comparator to sort by natural order descending, looking to both the unit and the value.static <Q extends Quantity<Q>>
Comparator<Quantity<Q>>Creates a comparator to sort by number, ignoring the unit.static <Q extends Quantity<Q>>
Comparator<Quantity<Q>>Creates a comparator to sort by number descending, ignoring the unit.static <Q extends Quantity<Q>>
Comparator<Quantity<Q>>Creates a comparator to sort by name, ignoring the value.static <Q extends Quantity<Q>>
Comparator<Quantity<Q>>Creates a comparator to sort by name descending, ignoring the value.static <Q extends Quantity<Q>>
BinaryOperator<Quantity<Q>>sum()Creates a BinaryOperator to sum.static <Q extends Quantity<Q>>
BinaryOperator<Quantity<Q>>Creates a BinaryOperator to sum converting to unit
-
Method Details
-
sortNumber
Creates a comparator to sort by number, ignoring the unit.- Type Parameters:
Q- the type of quantity- Returns:
Given:
Quantity<Time> day = timeFactory.create(1, Units.DAY);
Quantity<Time> hours = timeFactory.create(18, Units.HOUR);
Quantity<Time> minutes = timeFactory.create(15, Units.HOUR);
Quantity<Time> seconds = timeFactory.create(100, Units.HOUR);
will return:
day, hours, minutes, seconds- Throws:
NullPointerException- if any of the values to compare isnull
-
sortNumberDesc
Creates a comparator to sort by number descending, ignoring the unit.- Type Parameters:
Q- the type of quantity- Returns:
Given:
Quantity<Time> day = timeFactory.create(1, Units.DAY);
Quantity<Time> hours = timeFactory.create(18, Units.HOUR);
Quantity<Time> minutes = timeFactory.create(15, Units.HOUR);
Quantity<Time> seconds = timeFactory.create(100, Units.HOUR);
will return:
seconds, hours, minutes, day- Throws:
NullPointerException- if any of the values to compare isnull
-
sortSymbol
Creates a comparator to sort by name, ignoring the value.- Type Parameters:
Q- the type of quantity- Returns:
Given:
Quantity<Time> day = timeFactory.create(1, Units.DAY);
Quantity<Time> hours = timeFactory.create(18, Units.HOUR);
Quantity<Time> minutes = timeFactory.create(15, Units.HOUR);
Quantity<Time> seconds = timeFactory.create(100, Units.HOUR);
will return:
day, hours, minutes, seconds- Throws:
NullPointerException- if any of the values to compare isnull
-
sortSymbolDesc
Creates a comparator to sort by name descending, ignoring the value.- Type Parameters:
Q- the type of quantity- Returns:
Given:
Quantity<Time> day = timeFactory.create(1, Units.DAY);
Quantity<Time> hours = timeFactory.create(18, Units.HOUR);
Quantity<Time> minutes = timeFactory.create(15, Units.HOUR);
Quantity<Time> seconds = timeFactory.create(100, Units.HOUR);
will return:
seconds, minutes, hour, day- Throws:
NullPointerException- if any of the values to compare isnull
-
sortNatural
Creates a comparator to sort by natural order, looking to both the unit and the value.- Type Parameters:
Q- the type of quantity- Returns:
Given:
Quantity<Time> day = timeFactory.create(1, Units.DAY);
Quantity<Time> hours = timeFactory.create(18, Units.HOUR);
Quantity<Time> minutes = timeFactory.create(15, Units.HOUR);
Quantity<Time> seconds = timeFactory.create(100, Units.HOUR);
will return:
seconds, minutes, hours, day- Throws:
NullPointerException- if any of the values to compare isnull
-
sortNaturalDesc
Creates a comparator to sort by natural order descending, looking to both the unit and the value.- Type Parameters:
Q- the type of quantity- Returns:
Given:
Quantity<Time> day = timeFactory.create(1, Units.DAY);
Quantity<Time> hours = timeFactory.create(18, Units.HOUR);
Quantity<Time> minutes = timeFactory.create(15, Units.HOUR);
Quantity<Time> seconds = timeFactory.create(100, Units.HOUR);
will return:
day, hour, minute, second- Throws:
NullPointerException- if any of the values to compare isnull
-
min
Creates a BinaryOperator to calculate the minimum Quantity- Type Parameters:
Q- the type of quantity- Returns:
- the min BinaryOperator, not null.
-
max
Creates a BinaryOperator to calculate the maximum Quantity- Type Parameters:
Q- the type of quantity- Returns:
- the max BinaryOperator, not null.
-
sum
Creates a BinaryOperator to sum.- Type Parameters:
Q- the type of quantity- Returns:
- the sum BinaryOperator
-
sum
Creates a BinaryOperator to sum converting to unit- Type Parameters:
Q- the type of quantity- Parameters:
unit- unit to be converting- Returns:
- the sum BinaryOperator converting to unit
-
fiterByUnit
@SafeVarargs public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> fiterByUnit(Unit<Q>... units) Predicate to filter to one or more units- Type Parameters:
Q- the type of quantity- Parameters:
units- - units to be filtered (optional)- Returns:
- A predicate to filter one or more units
-
fiterByExcludingUnit
@SafeVarargs public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> fiterByExcludingUnit(Unit<Q>... units) Predicate to filter excluding these units- Type Parameters:
Q- the type of quantity- Parameters:
units- - units to be filtered (optional)- Returns:
- A predicate to filter to not be these units
-
isGreaterThan
creates a Filter to greater than number, ignoring units- Type Parameters:
Q- the type of quantity- Parameters:
value- - the value to be used in Predicate- Returns:
- the Predicate greater than this number, ignoring units
-
isGreaterThan
creates a filter to greater than the quantity measure- Type Parameters:
Q- the type of quantity- Parameters:
quantity- - the measure to be used in filter- Returns:
- the Predicate greater than this measure
-
isGreaterThanOrEqualTo
creates a Filter to greater or equals than number, ignoring units- Type Parameters:
Q- the type of quantity- Parameters:
value- - the value to be used in Predicate- Returns:
- the Predicate greater or equals than this number, ignoring units
-
isGreaterThanOrEqualTo
public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> isGreaterThanOrEqualTo(Quantity<Q> quantity) creates a filter to greater or equals than the quantity measure- Type Parameters:
Q- the type of quantity- Parameters:
quantity- - the measure to be used in filter- Returns:
- the Predicate greater or equals than this measure
-
isLessThan
creates a Filter to lesser than number, ignoring units- Type Parameters:
Q- the type of quantity- Parameters:
value- - the value to be used in Predicate- Returns:
- the Predicate greater than this number, ignoring units
-
isLessThan
creates a filter to lesser than the quantity measure- Type Parameters:
Q- the type of quantity- Parameters:
quantity- - the measure to be used in filter- Returns:
- the Predicate lesser than this measure
-
isLessThanOrEqualTo
creates a Filter to lesser or equals than number, ignoring units- Type Parameters:
Q- the type of quantity- Parameters:
value- - the value to be used in Predicate- Returns:
- the Predicate lesser or equals than this number, ignoring units
-
isLessThanOrEqualTo
public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> isLessThanOrEqualTo(Quantity<Q> quantity) creates a filter to lesser or equals than the quantity measure- Type Parameters:
Q- the type of quantity- Parameters:
quantity- - the measure to be used in filter- Returns:
- the Predicate lesser or equals than this measure
-
isBetween
creates a Filter to between, lesser or equals and greater or equals, than number, ignoring units- Type Parameters:
Q- the type of quantity- Parameters:
min- - the min value to be used in Predicatemax- - the max value to be used in Predicate- Returns:
- the Predicate lesser or equals than this number, ignoring units
-
isBetween
public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> isBetween(Quantity<Q> min, Quantity<Q> max) creates a filter to between, lesser or equals and greater or equals, than the quantity measure- Type Parameters:
Q- the type of quantity- Parameters:
min- - the min value to be used in Predicatemax- - the max value to be used in Predicate- Returns:
- the Predicate lesser or equals than this measure
-
groupByUnit
creates a function to group quantities by theirunit.
-