U
- The unit corresponding with the type e.g., Length specifies LengthUnit.T
- This type. Note this type is recursive to enforce type-safety, normally the complicated generics are not
exposed to users of the library e.g., see the Length
measure.public abstract class AbstractMeasure<U extends Unit<T,U>,T extends AbstractMeasure<U,T>> extends java.lang.Object implements Dimension<T>, Sequential<T,Rational,U>
Length
,
Velocity
, Mass
, etc. for examples.
Instances of this class store the value (or magnitude) of the measure in terms of base units. Thus all arithmetic on
measures is performed using Base units, which permits measures of differing input units to work in calculations. A
measure instance also maintains a "display unit", which is used for display purposes and for working with other
systems requiring specific units.
ComparableUsing.EqualityMode, ComparableUsing.Operator
Constructor and Description |
---|
AbstractMeasure(Rational value,
U unit,
U displayUnit) |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(T that) |
T |
copy(Rational value)
Given a value produce a copy of this dimension with the given value
|
T |
copy(U dsiplayUnit)
Copies this instance with a new display unit.
|
Rational |
div(T operand) |
ComparableUsing.EqualityMode |
equalityMode()
Use
#compareTo(T) to implement the == operator as it does not take into account the
_displayUnit which is inconsequential wrt the measure. |
boolean |
equals(java.lang.Object o) |
T |
fromBaseNumber(Rational p0) |
T |
fromNumber(Rational p0) |
abstract U |
getBaseUnit()
The unit on which all instances of this type are based.
|
U |
getDisplayUnit() |
Rational |
getValue() |
int |
hashCode() |
abstract T |
make(Rational value,
U unit)
Creates a new instance using the specified parameters.
|
abstract T |
make(Rational value,
U unit,
U displayUnit)
Creates a new instance using the specified parameters.
|
T |
minus(T operand) |
T |
nextInSequence(Rational step,
U unit) |
T |
nextNthInSequence(Rational step,
U unit,
int index) |
T |
plus(T operand) |
T |
previousInSequence(Rational step,
U unit) |
T |
previousNthInSequence(Rational step,
U unit,
int index) |
Rational |
rem(T operand) |
T |
to(U displayUnit)
Copy this measure using the specified
displayUnit . |
Rational |
toBaseNumber() |
java.lang.String |
toMixedString() |
Rational |
toNumber() |
Rational |
toNumber(U unit)
Get the magnitude of this measure in terms of the specified
unit . |
java.lang.String |
toString() |
clone, finalize, getClass, jailbreak, notify, notifyAll, wait, wait, wait
div, rem, times, unaryMinus
compareToUsing
public abstract U getBaseUnit()
Length
dimension might use Meters
as the base unit because it is the SI standard.public abstract T make(Rational value, U unit, U displayUnit)
public abstract T make(Rational value, U unit)
public T copy(Rational value)
Dimension
public Rational getValue()
public U getDisplayUnit()
public T fromNumber(Rational p0)
fromNumber
in interface Dimension<T extends AbstractMeasure<U,T>>
value
.public Rational toNumber()
public Rational toBaseNumber()
toBaseNumber
in interface Dimension<T extends AbstractMeasure<U,T>>
public Rational toNumber(U unit)
unit
.public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toMixedString()
"2 1/8 kg"
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public ComparableUsing.EqualityMode equalityMode()
#compareTo(T)
to implement the ==
operator as it does not take into account the
_displayUnit
which is inconsequential wrt the measure.equalityMode
in interface ComparableUsing<T extends AbstractMeasure<U,T>>
public int compareTo(T that)
compareTo
in interface java.lang.Comparable<T extends AbstractMeasure<U,T>>
public T nextInSequence(Rational step, U unit)
nextInSequence
in interface Sequential<T extends AbstractMeasure<U,T>,Rational,U extends Unit<T,U>>
public T nextNthInSequence(Rational step, U unit, int index)
nextNthInSequence
in interface Sequential<T extends AbstractMeasure<U,T>,Rational,U extends Unit<T,U>>
public T previousInSequence(Rational step, U unit)
previousInSequence
in interface Sequential<T extends AbstractMeasure<U,T>,Rational,U extends Unit<T,U>>
public T previousNthInSequence(Rational step, U unit, int index)
previousNthInSequence
in interface Sequential<T extends AbstractMeasure<U,T>,Rational,U extends Unit<T,U>>
Copyright © 2021. All rights reserved.