Top Description Constructors Methods
tech.uom.lib.common.function

public final Class QuantityFunctions

extends Object
Class Inheritance
Annotations
@SuppressWarnings:rawtypes
Imports
java.util.Comparator, .Objects, java.util.function.BinaryOperator, .Function, .Predicate, javax.measure.Quantity, .Unit, tech.uom.lib.common.util.NaturalQuantityComparator

Utility methods for operating on units and quantities with Java functional interfaces like Function.
Authors
Otavio, Werner
Since
2.0
Version
1.0.3

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <
the type of quantity
Q extends Quantity<Q>
>
Predicate<Quantity<Q>>

Returns:

A predicate to filter to not be these units
fiterByExcludingUnit
(Unit<Q>...
- units to be filtered (optional)
units
)

Predicate to filter excluding these units

public static <
the type of quantity
Q extends Quantity<Q>
>
Predicate<Quantity<Q>>

Returns:

A predicate to filter one or more units
fiterByUnit
(Unit<Q>...
- units to be filtered (optional)
units
)

Predicate to filter to one or more units

public static <
the type of quantity
Q extends Quantity<Q>
>
Function<Quantity<Q>, Unit<Q>>

Returns:

the Function of Quantity grouped by Unit
groupByUnit
()

creates a function to group quantities by their unit.

public static <
the type of quantity
Q extends Quantity<Q>
>
Predicate<Quantity<Q>>

Returns:

the Predicate lesser or equals than this number, ignoring units
isBetween
(Number
- the min value to be used in Predicate
min
,
Number
- the max value to be used in Predicate
max
)

creates a Filter to between, lesser or equals and greater or equals, than number, ignoring units

public static <
the type of quantity
Q extends Quantity<Q>
>
Predicate<Quantity<Q>>

Returns:

the Predicate lesser or equals than this measure
isBetween
(Quantity<Q>
- the min value to be used in Predicate
min
,
Quantity<Q>
- the max value to be used in Predicate
max
)

creates a filter to between, lesser or equals and greater or equals, than the quantity measure

public static <
the type of quantity
Q extends Quantity<Q>
>
Predicate<Quantity<Q>>

Returns:

the Predicate greater than this number, ignoring units
isGreaterThan
(Number
- the value to be used in Predicate
value
)

creates a Filter to greater than number, ignoring units

public static <
the type of quantity
Q extends Quantity<Q>
>
Predicate<Quantity<Q>>

Returns:

the Predicate greater than this measure
isGreaterThan
(Quantity<Q>
- the measure to be used in filter
quantity
)

creates a filter to greater than the quantity measure

public static <
the type of quantity
Q extends Quantity<Q>
>
Predicate<Quantity<Q>>

Returns:

the Predicate greater or equals than this number, ignoring units
isGreaterThanOrEqualTo
(Number
- the value to be used in Predicate
value
)

creates a Filter to greater or equals than number, ignoring units

public static <
the type of quantity
Q extends Quantity<Q>
>
Predicate<Quantity<Q>>

Returns:

the Predicate greater or equals than this measure
isGreaterThanOrEqualTo
(Quantity<Q>
- the measure to be used in filter
quantity
)

creates a filter to greater or equals than the quantity measure

public static <
the type of quantity
Q extends Quantity<Q>
>
Predicate<Quantity<Q>>

Returns:

the Predicate greater than this number, ignoring units
isLessThan
(Number
- the value to be used in Predicate
value
)

creates a Filter to lesser than number, ignoring units

public static <
the type of quantity
Q extends Quantity<Q>
>
Predicate<Quantity<Q>>

Returns:

the Predicate lesser than this measure
isLessThan
(Quantity<Q>
- the measure to be used in filter
quantity
)

creates a filter to lesser than the quantity measure

public static <
the type of quantity
Q extends Quantity<Q>
>
Predicate<Quantity<Q>>

Returns:

the Predicate lesser or equals than this number, ignoring units
isLessThanOrEqualTo
(Number
- the value to be used in Predicate
value
)

creates a Filter to lesser or equals than number, ignoring units

public static <
the type of quantity
Q extends Quantity<Q>
>
Predicate<Quantity<Q>>

Returns:

the Predicate lesser or equals than this measure
isLessThanOrEqualTo
(Quantity<Q>
- the measure to be used in filter
quantity
)

creates a filter to lesser or equals than the quantity measure

public static <
the type of quantity
Q extends Quantity<Q>
>
BinaryOperator<Quantity<Q>>

Returns:

the max BinaryOperator, not null.
max
()

Creates a BinaryOperator to calculate the maximum Quantity

public static <
the type of quantity
Q extends Quantity<Q>
>
BinaryOperator<Quantity<Q>>

Returns:

the min BinaryOperator, not null.
min
()

Creates a BinaryOperator to calculate the minimum Quantity

public static <
the type of quantity
Q extends Quantity<Q>
>
Comparator<Quantity<Q>>

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

sortNatural
()

Creates a comparator to sort by natural order, looking to both the unit and the value.

public static <
the type of quantity
Q extends Quantity<Q>
>
Comparator<Quantity<Q>>

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

sortNaturalDesc
()

Creates a comparator to sort by natural order descending, looking to both the unit and the value.

public static <
the type of quantity
Q extends Quantity<Q>
>
Comparator<Quantity<Q>>

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

sortNumber
()

Creates a comparator to sort by number, ignoring the unit.

public static <
the type of quantity
Q extends Quantity<Q>
>
Comparator<Quantity<Q>>

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

sortNumberDesc
()

Creates a comparator to sort by number descending, ignoring the unit.

public static <
the type of quantity
Q extends Quantity<Q>
>
Comparator<Quantity<Q>>

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

sortSymbol
()

Creates a comparator to sort by name, ignoring the value.

public static <
the type of quantity
Q extends Quantity<Q>
>
Comparator<Quantity<Q>>

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

sortSymbolDesc
()

Creates a comparator to sort by name descending, ignoring the value.

public static <
the type of quantity
Q extends Quantity<Q>
>
BinaryOperator<Quantity<Q>>

Returns:

the sum BinaryOperator
sum
()

Creates a BinaryOperator to sum.

public static <
the type of quantity
Q extends Quantity<Q>
>
BinaryOperator<Quantity<Q>>

Returns:

the sum BinaryOperator converting to unit
sum
(Unit<Q>
unit to be converting
unit
)

Creates a BinaryOperator to sum converting to unit

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

QuantityFunctionsback to summary
private QuantityFunctions()

Method Detail

fiterByExcludingUnitback to summary
public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> fiterByExcludingUnit(Unit<Q>... units)

Predicate to filter excluding these units

Parameters
<Q>
the type of quantity
units:Unit<Q>[]

- units to be filtered (optional)

Returns:Predicate<Quantity<Q>>

A predicate to filter to not be these units

Annotations
@SafeVarargs
fiterByUnitback to summary
public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> fiterByUnit(Unit<Q>... units)

Predicate to filter to one or more units

Parameters
<Q>
the type of quantity
units:Unit<Q>[]

- units to be filtered (optional)

Returns:Predicate<Quantity<Q>>

A predicate to filter one or more units

Annotations
@SafeVarargs
groupByUnitback to summary
public static <Q extends Quantity<Q>> Function<Quantity<Q>, Unit<Q>> groupByUnit()

creates a function to group quantities by their unit.

Parameters
<Q>
the type of quantity
Returns:Function<Quantity<Q>, Unit<Q>>

the Function of Quantity grouped by Unit

isBetweenback to summary
public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> isBetween(Number min, Number max)

creates a Filter to between, lesser or equals and greater or equals, than number, ignoring units

Parameters
<Q>
the type of quantity
min:Number

- the min value to be used in Predicate

max:Number

- the max value to be used in Predicate

Returns:Predicate<Quantity<Q>>

the Predicate lesser or equals than this number, ignoring units

isBetweenback to summary
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

Parameters
<Q>
the type of quantity
min:Quantity<Q>

- the min value to be used in Predicate

max:Quantity<Q>

- the max value to be used in Predicate

Returns:Predicate<Quantity<Q>>

the Predicate lesser or equals than this measure

isGreaterThanback to summary
public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> isGreaterThan(Number value)

creates a Filter to greater than number, ignoring units

Parameters
<Q>
the type of quantity
value:Number

- the value to be used in Predicate

Returns:Predicate<Quantity<Q>>

the Predicate greater than this number, ignoring units

isGreaterThanback to summary
public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> isGreaterThan(Quantity<Q> quantity)

creates a filter to greater than the quantity measure

Parameters
<Q>
the type of quantity
quantity:Quantity<Q>

- the measure to be used in filter

Returns:Predicate<Quantity<Q>>

the Predicate greater than this measure

isGreaterThanOrEqualToback to summary
public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> isGreaterThanOrEqualTo(Number value)

creates a Filter to greater or equals than number, ignoring units

Parameters
<Q>
the type of quantity
value:Number

- the value to be used in Predicate

Returns:Predicate<Quantity<Q>>

the Predicate greater or equals than this number, ignoring units

isGreaterThanOrEqualToback to summary
public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> isGreaterThanOrEqualTo(Quantity<Q> quantity)

creates a filter to greater or equals than the quantity measure

Parameters
<Q>
the type of quantity
quantity:Quantity<Q>

- the measure to be used in filter

Returns:Predicate<Quantity<Q>>

the Predicate greater or equals than this measure

isLessThanback to summary
public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> isLessThan(Number value)

creates a Filter to lesser than number, ignoring units

Parameters
<Q>
the type of quantity
value:Number

- the value to be used in Predicate

Returns:Predicate<Quantity<Q>>

the Predicate greater than this number, ignoring units

isLessThanback to summary
public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> isLessThan(Quantity<Q> quantity)

creates a filter to lesser than the quantity measure

Parameters
<Q>
the type of quantity
quantity:Quantity<Q>

- the measure to be used in filter

Returns:Predicate<Quantity<Q>>

the Predicate lesser than this measure

isLessThanOrEqualToback to summary
public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> isLessThanOrEqualTo(Number value)

creates a Filter to lesser or equals than number, ignoring units

Parameters
<Q>
the type of quantity
value:Number

- the value to be used in Predicate

Returns:Predicate<Quantity<Q>>

the Predicate lesser or equals than this number, ignoring units

isLessThanOrEqualToback to summary
public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> isLessThanOrEqualTo(Quantity<Q> quantity)

creates a filter to lesser or equals than the quantity measure

Parameters
<Q>
the type of quantity
quantity:Quantity<Q>

- the measure to be used in filter

Returns:Predicate<Quantity<Q>>

the Predicate lesser or equals than this measure

maxback to summary
public static <Q extends Quantity<Q>> BinaryOperator<Quantity<Q>> max()

Creates a BinaryOperator to calculate the maximum Quantity

Parameters
<Q>
the type of quantity
Returns:BinaryOperator<Quantity<Q>>

the max BinaryOperator, not null.

minback to summary
public static <Q extends Quantity<Q>> BinaryOperator<Quantity<Q>> min()

Creates a BinaryOperator to calculate the minimum Quantity

Parameters
<Q>
the type of quantity
Returns:BinaryOperator<Quantity<Q>>

the min BinaryOperator, not null.

sortNaturalback to summary
public static <Q extends Quantity<Q>> Comparator<Quantity<Q>> sortNatural()

Creates a comparator to sort by natural order, looking to both the unit and the value.

Parameters
<Q>
the type of quantity
Returns:Comparator<Quantity<Q>>

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

Annotations
@SuppressWarnings:unchecked
Exceptions
NullPointerException:
if any of the values to compare is null
sortNaturalDescback to summary
public static <Q extends Quantity<Q>> Comparator<Quantity<Q>> sortNaturalDesc()

Creates a comparator to sort by natural order descending, looking to both the unit and the value.

Parameters
<Q>
the type of quantity
Returns:Comparator<Quantity<Q>>

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

Exceptions
NullPointerException:
if any of the values to compare is null
sortNumberback to summary
public static <Q extends Quantity<Q>> Comparator<Quantity<Q>> sortNumber()

Creates a comparator to sort by number, ignoring the unit.

Parameters
<Q>
the type of quantity
Returns:Comparator<Quantity<Q>>

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

Exceptions
NullPointerException:
if any of the values to compare is null
sortNumberDescback to summary
public static <Q extends Quantity<Q>> Comparator<Quantity<Q>> sortNumberDesc()

Creates a comparator to sort by number descending, ignoring the unit.

Parameters
<Q>
the type of quantity
Returns:Comparator<Quantity<Q>>

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

Exceptions
NullPointerException:
if any of the values to compare is null
sortSymbolback to summary
public static <Q extends Quantity<Q>> Comparator<Quantity<Q>> sortSymbol()

Creates a comparator to sort by name, ignoring the value.

Parameters
<Q>
the type of quantity
Returns:Comparator<Quantity<Q>>

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

Exceptions
NullPointerException:
if any of the values to compare is null
sortSymbolDescback to summary
public static <Q extends Quantity<Q>> Comparator<Quantity<Q>> sortSymbolDesc()

Creates a comparator to sort by name descending, ignoring the value.

Parameters
<Q>
the type of quantity
Returns:Comparator<Quantity<Q>>

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

Exceptions
NullPointerException:
if any of the values to compare is null
sumback to summary
public static <Q extends Quantity<Q>> BinaryOperator<Quantity<Q>> sum()

Creates a BinaryOperator to sum.

Parameters
<Q>
the type of quantity
Returns:BinaryOperator<Quantity<Q>>

the sum BinaryOperator

sumback to summary
public static <Q extends Quantity<Q>> BinaryOperator<Quantity<Q>> sum(Unit<Q> unit)

Creates a BinaryOperator to sum converting to unit

Parameters
<Q>
the type of quantity
unit:Unit<Q>

unit to be converting

Returns:BinaryOperator<Quantity<Q>>

the sum BinaryOperator converting to unit