Class QuantityFunctions

java.lang.Object
tech.uom.lib.common.function.QuantityFunctions

public final class QuantityFunctions extends Object
Utility methods for operating on units and quantities with Java functional interfaces like Function.
Since:
2.0
Version:
1.0.3
Author:
Otavio, Werner
  • Method Details

    • sortNumber

      public static <Q extends Quantity<Q>> Comparator<Quantity<Q>> 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 is null
    • sortNumberDesc

      public static <Q extends Quantity<Q>> Comparator<Quantity<Q>> 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 is null
    • sortSymbol

      public static <Q extends Quantity<Q>> Comparator<Quantity<Q>> 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 is null
    • sortSymbolDesc

      public static <Q extends Quantity<Q>> Comparator<Quantity<Q>> 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 is null
    • sortNatural

      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.
      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 is null
    • sortNaturalDesc

      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.
      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 is null
    • min

      public static <Q extends Quantity<Q>> BinaryOperator<Quantity<Q>> min()
      Creates a BinaryOperator to calculate the minimum Quantity
      Type Parameters:
      Q - the type of quantity
      Returns:
      the min BinaryOperator, not null.
    • max

      public static <Q extends Quantity<Q>> BinaryOperator<Quantity<Q>> max()
      Creates a BinaryOperator to calculate the maximum Quantity
      Type Parameters:
      Q - the type of quantity
      Returns:
      the max BinaryOperator, not null.
    • sum

      public static <Q extends Quantity<Q>> BinaryOperator<Quantity<Q>> sum()
      Creates a BinaryOperator to sum.
      Type Parameters:
      Q - the type of quantity
      Returns:
      the sum BinaryOperator
    • sum

      public static <Q extends Quantity<Q>> BinaryOperator<Quantity<Q>> sum(Unit<Q> unit)
      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

      public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> isGreaterThan(Number value)
      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

      public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> isGreaterThan(Quantity<Q> quantity)
      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

      public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> isGreaterThanOrEqualTo(Number value)
      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

      public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> isLessThan(Number value)
      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

      public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> isLessThan(Quantity<Q> quantity)
      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

      public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> isLessThanOrEqualTo(Number value)
      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

      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
      Type Parameters:
      Q - the type of quantity
      Parameters:
      min - - the min value to be used in Predicate
      max - - 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 Predicate
      max - - the max value to be used in Predicate
      Returns:
      the Predicate lesser or equals than this measure
    • groupByUnit

      public static <Q extends Quantity<Q>> Function<Quantity<Q>,Unit<Q>> groupByUnit()
      creates a function to group quantities by their unit.
      Type Parameters:
      Q - the type of quantity
      Returns:
      the Function of Quantity grouped by Unit