/** * Get the minimal quantity found within this summary converted to unit * * @param unit * to convert * @return the minimal quantity converted to this unit */ public Quantity<Q> getMin(Unit<Q> unit) { return min.to(unit); }
/** * Get the maximal amount found within this summary converted to unit * * @param unit * to convert * @return the maximal quantity converted to this unit */ public Quantity<Q> getMax(Unit<Q> unit) { return max.to(unit); }
/** * Get the quantity average of all amounts added converted to unit * * @param unit * to convert * @return the average quantity converted to this unit */ public Quantity<Q> getAverage(Unit<Q> unit) { return average.to(unit); }
/** * Creates a {@link TemporalQuantity} based a {@link Quantity<Time>} converted to {@link Units#SECOND}. * * @param quantity * - quantity to be used * @return the {@link TemporalQuantity} converted be quantity in seconds. */ public static TemporalQuantity toTemporalSeconds(Quantity<Time> quantity) { Quantity<Time> seconds = Objects.requireNonNull(quantity).to(SECOND); return TemporalQuantity.of(seconds); } }
/** * Creates a {@link TimeUnitQuantity} based a {@link Quantity<Time>} converted to {@link Units#SECOND}. * * @param quantity * - quantity to be used * @return the {@link TimeUnitQuantity} converted be quantity in seconds. */ public static TimeUnitQuantity toTimeUnitSeconds(Quantity<Time> quantity) { Quantity<Time> seconds = Objects.requireNonNull(quantity).to(SECOND); return new TimeUnitQuantity(TimeUnit.SECONDS, seconds.getValue().intValue()); }
/** * creates a filter to lesser or equals than the quantity measure * * @param quantity * - the measure to be used in filter * @return the Predicate lesser or equals than this measure */ public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> isLesserThanOrEqualTo(Quantity<Q> quantity) { return q -> q.to(quantity.getUnit()).getValue().doubleValue() <= quantity.getValue().doubleValue(); }
/** * creates a filter to lesser than the quantity measure * * @param quantity * - the measure to be used in filter * @return the Predicate lesser than this measure */ public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> isLesserThan(Quantity<Q> quantity) { return q -> q.to(quantity.getUnit()).getValue().doubleValue() < quantity.getValue().doubleValue(); }
/** * creates a filter to greater or equals than the quantity measure * * @param quantity * - the measure to be used in filter * @return the Predicate greater or equals than this measure */ public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> isGreaterThanOrEqualTo(Quantity<Q> quantity) { return q -> q.to(quantity.getUnit()).getValue().doubleValue() >= quantity.getValue().doubleValue(); }
/** * creates a filter to lesser than the quantity measure * * @param quantity * - the measure to be used in filter * @return the Predicate lesser than this measure */ public static <Q extends Quantity<Q>> Predicate<Quantity<Q>> isLesserThan(Quantity<Q> quantity) { return q -> q.to(quantity.getUnit()).getValue().doubleValue() < quantity.getValue().doubleValue(); }
@Override public int compare(Quantity<T> q1, Quantity<T> q2) { if (q1.getUnit().equals(q2.getUnit())) { return Double.compare(q1.getValue().doubleValue(), q2.getValue().doubleValue()); } return Double.compare(q1.getValue().doubleValue(), q2.to(q1.getUnit()).getValue().doubleValue()); } }
@Override public ComparableQuantity<Q> subtract(Quantity<Q> that) { final Quantity<Q> converted = that.to(getUnit()); return NumberQuantity.of(value - converted.getValue().byteValue(), getUnit()); }
@Override public ComparableQuantity<Q> add(Quantity<Q> that) { final Quantity<Q> converted = that.to(getUnit()); return NumberQuantity.of(value + converted.getValue().byteValue(), getUnit()); }
@Override public ComparableQuantity<Q> add(Quantity<Q> that) { final Quantity<Q> converted = that.to(getUnit()); return NumberQuantity.of(value + converted.getValue().byteValue(), getUnit()); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public Quantity<Q> subtract(Quantity<Q> that) { final Quantity<Q> thatToUnit = (Quantity<Q>) that.to(getUnit()); return new NumberQuantity(this.getValue().doubleValue() - thatToUnit.getValue().doubleValue(), getUnit()); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public Quantity<Q> add(Quantity<Q> that) { final Quantity<Q> thatToUnit = (Quantity<Q>) that.to(getUnit()); return new NumberQuantity(this.getValue().doubleValue() + thatToUnit.getValue().doubleValue(), getUnit()); }
@Override public ComparableQuantity<Q> subtract(Quantity<Q> that) { final Quantity<Q> converted = that.to(getUnit()); return NumberQuantity.of(value - converted.getValue().byteValue(), getUnit()); }
@Override public ComparableQuantity<Time> add(Quantity<Time> that) { if (getUnit().equals(that.getUnit())) { return TimeQuantities.getQuantity(value + that.getValue().intValue(), timeUnit); } Quantity<Time> converted = that.to(getUnit()); return TimeQuantities.getQuantity(value + converted.getValue().intValue(), timeUnit); }
/** * @since 1.0.1 */ @Override public ComparableQuantity<Time> add(Quantity<Time> that) { if (getUnit().equals(that.getUnit())) { return TimeQuantities.getQuantity(value + that.getValue().intValue(), timeUnit); } Quantity<Time> converted = that.to(getUnit()); return TimeQuantities.getQuantity(value + converted.getValue().intValue(), timeUnit); }
@Override public ComparableQuantity<Q> subtract(Quantity<Q> that) { if (getUnit().equals(that.getUnit())) { return Quantities.getQuantity(value - that.getValue().doubleValue(), getUnit()); } Quantity<Q> converted = that.to(getUnit()); return Quantities.getQuantity(value - converted.getValue().doubleValue(), getUnit()); }
@Override public ComparableQuantity<Q> add(Quantity<Q> that) { if (getUnit().equals(that.getUnit())) { return Quantities.getQuantity(value + that.getValue().doubleValue(), getUnit()); } Quantity<Q> converted = that.to(getUnit()); return Quantities.getQuantity(value + converted.getValue().doubleValue(), getUnit()); }