Package org.salespointframework.quantity
Class Quantity
java.lang.Object
org.salespointframework.quantity.Quantity
@Embeddable public class Quantity extends Object
A value object to represent a quantity.
- Author:
- Oliver Gierke, Martin Morgenstern
-
Field Summary
-
Method Summary
Modifier and Type Method Description Quantityadd(Quantity other)Adds the givenQuantityto the current one.protected booleancanEqual(Object other)booleanequals(Object o)@NonNull BigDecimalgetAmount()The amount of the Quantity.@NonNull MetricgetMetric()The metric of the Quantity.inthashCode()booleanisCompatibleWith(Metric metric)booleanisEqualTo(Quantity other)Returns whether the currentQuantityis equal to the given one negelecting potential differences in precision of the underlying amount.booleanisGreaterThan(Quantity other)Returns whether the givenQuantityis greater than the current one.booleanisGreaterThanOrEqualTo(Quantity other)Returns whether the givenQuantityis greater than or equal to the current one.booleanisLessThan(Quantity other)Returns whether the givenQuantityis less than the current one.booleanisNegative()Returns whether the currentQuantityis negative.booleanisZeroOrNegative()Returns whether the currentQuantityis zero or negative.static Quantityof(double amount)Creates a newQuantityof the given amount.static Quantityof(double amount, Metric metric)static Quantityof(long amount)Creates a newQuantityof the given amount.static Quantityof(long amount, Metric metric)Quantitysubtract(Quantity other)Subtracts the given Quantity from the current one.Quantitytimes(int multiplier)Creates a newQuantityof the current one multiplied with the given int.Quantitytimes(long multiplier)Creates a newQuantityof the current one multiplied with the given long.StringtoString()QuantitytoZero()
-
Field Details
-
Method Details
-
of
Creates a newQuantityof the given amount. Defaults the metric to .- Parameters:
amount- must not be null.- Returns:
-
of
Creates a newQuantityof the given amount. Defaults the metric to .- Parameters:
amount- must not be null.- Returns:
-
of
- Parameters:
amount- must not be null.metric- must not be null.- Returns:
-
of
- Parameters:
amount- must not be null.metric- must not be null.- Returns:
-
isCompatibleWith
- Parameters:
metric- must not be null.- Returns:
-
add
Adds the givenQuantityto the current one.- Parameters:
other- theQuantityto add. The givenQuantity'sMetricmust be compatible with the current one.- Returns:
- See Also:
isCompatibleWith(Metric)
-
subtract
Subtracts the given Quantity from the current one.- Parameters:
other- theQuantityto add. The givenQuantity'sMetricmust be compatible with the current one.- Returns:
- See Also:
isCompatibleWith(Metric)
-
isLessThan
Returns whether the givenQuantityis less than the current one.- Parameters:
other- must not be null. The givenQuantity'sMetricmust be compatible with the current one.- Returns:
- See Also:
isCompatibleWith(Metric)
-
times
Creates a newQuantityof the current one multiplied with the given int.- Parameters:
multiplier-- Returns:
- will never be null.
-
times
Creates a newQuantityof the current one multiplied with the given long.- Parameters:
multiplier-- Returns:
- will never be null.
-
isEqualTo
Returns whether the currentQuantityis equal to the given one negelecting potential differences in precision of the underlying amount. I.e. an amount of 1 is considered equal to an amount of 1.0.- Parameters:
other- must not be null.- Returns:
- Since:
- 7.2.2
-
isGreaterThan
Returns whether the givenQuantityis greater than the current one.- Parameters:
other- must not be null. The givenQuantity'sMetricmust be compatible with the current one.- Returns:
- See Also:
isCompatibleWith(Metric)
-
isGreaterThanOrEqualTo
Returns whether the givenQuantityis greater than or equal to the current one.- Parameters:
other- must not be null. The givenQuantity'sMetricmust be compatible with the current one.- Returns:
- See Also:
isCompatibleWith(Metric)
-
isNegative
public boolean isNegative()Returns whether the currentQuantityis negative.- Returns:
-
isZeroOrNegative
public boolean isZeroOrNegative()Returns whether the currentQuantityis zero or negative.- Returns:
-
toZero
- Returns:
- will never be null.
-
toString
-
equals
-
canEqual
-
hashCode
public int hashCode() -
getAmount
The amount of the Quantity. Explicitly set a prefixed column name to avoid name conflicts. -
getMetric
The metric of the Quantity. Explicitly set a prefixed column name to avoid name conflicts.
-