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 Quantity
add(Quantity other)
Adds the givenQuantity
to the current one.protected boolean
canEqual(Object other)
boolean
equals(Object o)
@NonNull BigDecimal
getAmount()
The amount of the Quantity.@NonNull Metric
getMetric()
The metric of the Quantity.int
hashCode()
boolean
isCompatibleWith(Metric metric)
boolean
isEqualTo(Quantity other)
Returns whether the currentQuantity
is equal to the given one negelecting potential differences in precision of the underlying amount.boolean
isGreaterThan(Quantity other)
Returns whether the givenQuantity
is greater than the current one.boolean
isGreaterThanOrEqualTo(Quantity other)
Returns whether the givenQuantity
is greater than or equal to the current one.boolean
isLessThan(Quantity other)
Returns whether the givenQuantity
is less than the current one.boolean
isNegative()
Returns whether the currentQuantity
is negative.boolean
isZeroOrNegative()
Returns whether the currentQuantity
is zero or negative.static Quantity
of(double amount)
Creates a newQuantity
of the given amount.static Quantity
of(double amount, Metric metric)
static Quantity
of(long amount)
Creates a newQuantity
of the given amount.static Quantity
of(long amount, Metric metric)
Quantity
subtract(Quantity other)
Subtracts the given Quantity from the current one.Quantity
times(int multiplier)
Creates a newQuantity
of the current one multiplied with the given int.Quantity
times(long multiplier)
Creates a newQuantity
of the current one multiplied with the given long.String
toString()
Quantity
toZero()
-
Field Details
-
Method Details
-
of
Creates a newQuantity
of the given amount. Defaults the metric to .- Parameters:
amount
- must not be null.- Returns:
-
of
Creates a newQuantity
of 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 givenQuantity
to the current one.- Parameters:
other
- theQuantity
to add. The givenQuantity
'sMetric
must be compatible with the current one.- Returns:
- See Also:
isCompatibleWith(Metric)
-
subtract
Subtracts the given Quantity from the current one.- Parameters:
other
- theQuantity
to add. The givenQuantity
'sMetric
must be compatible with the current one.- Returns:
- See Also:
isCompatibleWith(Metric)
-
isLessThan
Returns whether the givenQuantity
is less than the current one.- Parameters:
other
- must not be null. The givenQuantity
'sMetric
must be compatible with the current one.- Returns:
- See Also:
isCompatibleWith(Metric)
-
times
Creates a newQuantity
of the current one multiplied with the given int.- Parameters:
multiplier
-- Returns:
- will never be null.
-
times
Creates a newQuantity
of the current one multiplied with the given long.- Parameters:
multiplier
-- Returns:
- will never be null.
-
isEqualTo
Returns whether the currentQuantity
is 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 givenQuantity
is greater than the current one.- Parameters:
other
- must not be null. The givenQuantity
'sMetric
must be compatible with the current one.- Returns:
- See Also:
isCompatibleWith(Metric)
-
isGreaterThanOrEqualTo
Returns whether the givenQuantity
is greater than or equal to the current one.- Parameters:
other
- must not be null. The givenQuantity
'sMetric
must be compatible with the current one.- Returns:
- See Also:
isCompatibleWith(Metric)
-
isNegative
public boolean isNegative()Returns whether the currentQuantity
is negative.- Returns:
-
isZeroOrNegative
public boolean isZeroOrNegative()Returns whether the currentQuantity
is 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.
-