Package org.openwms.core.units.api
Class Weight
java.lang.Object
org.openwms.core.units.api.Weight
- All Implemented Interfaces:
Serializable
,Comparable<Weight>
,Measurable<BigDecimal,
Weight, WeightUnit>
public class Weight
extends Object
implements Measurable<BigDecimal,Weight,WeightUnit>, Serializable
A Weight represents a real world weight, that comes with an
Unit
and a value.- Author:
- Heiko Scherrer
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate BigDecimal
The magnitude of the Weight.private WeightUnit
The unit of the Weight.static final Weight
Constant for a zero value.Fields inherited from interface org.openwms.core.units.api.Measurable
SEPARATOR
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Weight()
Accessed by persistence provider.private
Weight
(BigDecimal magnitude, WeightUnit unitType) Create a new Weight. -
Method Summary
Modifier and TypeMethodDescriptionadd
(Measurable<BigDecimal, Weight, WeightUnit> other) Add another
Measurable to this one.int
convertTo
(WeightUnit unt) Convert thisMeasurable
into anotherMeasurable
.boolean
Uses magnitude and unitType for comparison.Get the magnitude of thisMeasurable
.Returns the type ofMeasurable
.int
hashCode()
Uses magnitude and unitType for calculation.boolean
Check whether the magnitude is of negative value.boolean
isZero()
Check whether the magnitude is 0.static Weight
of
(int magnitude) Create a new Weight.static Weight
of
(Integer magnitude, WeightUnit unitType) Create a new Weight.static Weight
of
(BigDecimal magnitude) Create a new Weight.static Weight
of
(BigDecimal magnitude, WeightUnit unitType) Create a new Weight.subtract
(Measurable<BigDecimal, Weight, WeightUnit> subtrahent) Subtract another
Measurable instance from this one.toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.openwms.core.units.api.Measurable
asString
-
Field Details
-
unitType
The unit of the Weight. -
magnitude
The magnitude of the Weight. -
ZERO
Constant for a zero value.
-
-
Constructor Details
-
Weight
protected Weight()Accessed by persistence provider. -
Weight
Create a new Weight.- Parameters:
magnitude
- The magnitudeunitType
- The unit of measure
-
-
Method Details
-
of
Create a new Weight.- Parameters:
magnitude
- The magnitudeunitType
- The unit of measure- Returns:
- The new instance
-
of
Create a new Weight.- Parameters:
magnitude
- The magnitude- Returns:
- The new instance
-
of
Create a new Weight.- Parameters:
magnitude
- The magnitudeunitType
- The unit of measure- Returns:
- The new instance
-
of
Create a new Weight.- Parameters:
magnitude
- The magnitude- Returns:
- The new instance
-
getMagnitude
Get the magnitude of thisMeasurable
.- Specified by:
getMagnitude
in interfaceMeasurable<BigDecimal,
Weight, WeightUnit> - Returns:
- the magnitude
-
getUnitType
Returns the type ofMeasurable
.- Specified by:
getUnitType
in interfaceMeasurable<BigDecimal,
Weight, WeightUnit> - Returns:
- The
Measurable
's type
-
isZero
public boolean isZero()Check whether the magnitude is 0.- Specified by:
isZero
in interfaceMeasurable<BigDecimal,
Weight, WeightUnit> - Returns:
- true is magnitude is 0, otherwise false
-
isNegative
public boolean isNegative()Check whether the magnitude is of negative value.- Specified by:
isNegative
in interfaceMeasurable<BigDecimal,
Weight, WeightUnit> - Returns:
- true if the magnitude is of negative value, otherwise false
-
convertTo
Convert thisMeasurable
into anotherMeasurable
.- Specified by:
convertTo
in interfaceMeasurable<BigDecimal,
Weight, WeightUnit> - Parameters:
unt
- TheBaseUnit
to convert to- Returns:
- The converted unit
-
add
Add another
Measurable to this one.- Specified by:
add
in interfaceMeasurable<BigDecimal,
Weight, WeightUnit> - Parameters:
other
- The one to add- Returns:
- A new instance
-
subtract
public Measurable<BigDecimal,Weight, subtractWeightUnit> (Measurable<BigDecimal, Weight, WeightUnit> subtrahent) Subtract another
Measurable instance from this one.- Specified by:
subtract
in interfaceMeasurable<BigDecimal,
Weight, WeightUnit> - Parameters:
subtrahent
- The one to subtract- Returns:
- A new instance
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Weight>
-
hashCode
public int hashCode()Uses magnitude and unitType for calculation. -
equals
Uses magnitude and unitType for comparison. -
toString
-