@Immutable public abstract class UnitImpl extends java.lang.Object implements Unit, java.io.Serializable
| Modifier and Type | Class and Description |
|---|---|
protected static class |
UnitImpl.MyConverter
Provides support for converting numeric values from this unit to another
unit.
|
| Modifier | Constructor and Description |
|---|---|
protected |
UnitImpl()
Constructs with no ID.
|
protected |
UnitImpl(UnitName id)
Constructs with the given ID.
|
| Modifier and Type | Method and Description |
|---|---|
double[] |
convertTo(double[] amounts,
Unit outputUnit)
Converts numeric values from this unit to another unit.
|
double[] |
convertTo(double[] input,
Unit outputUnit,
double[] output)
Converts numeric values from this unit to another unit.
|
double |
convertTo(double amount,
Unit outputUnit)
Converts a numeric value from this unit to another unit.
|
float[] |
convertTo(float[] amounts,
Unit outputUnit)
Converts numeric values from this unit to another unit.
|
float[] |
convertTo(float[] input,
Unit outputUnit,
float[] output)
Converts numeric values from this unit to another unit.
|
float |
convertTo(float amount,
Unit outputUnit)
Converts a numeric value from this unit to another unit.
|
Unit |
divideBy(Unit that)
Divides this unit by another.
|
Unit |
divideInto(Unit that)
Divides this unit into another.
|
Converter |
getConverterTo(Unit outputUnit)
Gets a Converter for converting numeric values from this unit to another,
compatible unit.
|
java.lang.String |
getName()
Gets the name of the unit.
|
java.lang.String |
getPlural()
Gets the plural form of the name of the unit.
|
java.lang.String |
getSymbol()
Gets the symbol for the unit.
|
UnitName |
getUnitName()
Gets the identifier of this unit.
|
abstract int |
hashCode()
Returns the hash code of this instance.
|
boolean |
isCompatible(Unit that)
Indicates if numeric values in this unit are convertible with another
unit.
|
Unit |
log(double base)
Returns a logarithmic unit whose reference level is equal to this unit.
|
java.lang.String |
makeLabel(java.lang.String quantityID)
Returns a label for a quantity in this unit.
|
Unit |
multiplyBy(double scale)
Multiplies this unit by a scale factor.
|
Unit |
multiplyBy(Unit that)
Multiplies this unit by another.
|
protected abstract Unit |
myDivideBy(Unit unit)
Divides this unit by another.
|
protected abstract Unit |
myDivideInto(Unit unit)
Divides this unit into another.
|
protected abstract Unit |
myMultiplyBy(Unit that)
Multiplies this unit by another.
|
protected abstract Unit |
myRaiseTo(int power)
Raises this unit to a power.
|
Unit |
raiseTo(int power)
Raises this unit to a power.
|
Unit |
shiftTo(java.util.Date origin)
Returns a unit identical to this instance but whose origin (i.e., zero
value) has been shifted to the given time.
|
Unit |
shiftTo(double origin)
Returns a unit identical to this instance but whose origin (i.e., zero
value) has been shifted to the given value.
|
java.lang.String |
toString()
Returns the string representation of this unit.
|
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, waitclone, equals, getCanonicalString, getDerivedUnit, isDimensionlessprotected UnitImpl()
protected UnitImpl(UnitName id)
id - The id of the unit (e.g. "foot"). May be null.public final UnitName getUnitName()
getUnitName in interface Unitnull.public final java.lang.String getName()
public final java.lang.String getPlural()
public final java.lang.String getSymbol()
public Unit shiftTo(double origin) throws ShiftException
UnitdegK
is a Kelvin unit, then degK.shiftTo(273.15) is a Celsius unit.shiftTo in interface Unitorigin - The new origin in units of this instance.origin of this instance.ShiftException - if the corresponding new unit can't be created.public Unit shiftTo(java.util.Date origin) throws ShiftException
Unitsec is
a second unit, then sec.shiftTo(new Date(0L) is the unit
corresponding to seconds since the epoch (1970-01-01 00:00:00 UTC).shiftTo in interface Unitorigin - The new origin.origin.ShiftException - if the corresponding new unit can't be created. For example,
if this instance isn't a unit of time.public final Unit multiplyBy(Unit that) throws MultiplyException
multiplyBy in interface Unitthat - The other unit.MultiplyException - Can't multiply these units.public Unit multiplyBy(double scale) throws MultiplyException
Unitm is a
meter unit, then m.multiplyBy(1e-2) returns a centimeter unit.multiplyBy in interface Unitscale - The scale factor.MultiplyException - if scale is zero.protected abstract Unit myMultiplyBy(Unit that) throws MultiplyException
that - The other unit.MultiplyException - Can't multiply these units.public final Unit divideBy(Unit that) throws OperationException
divideBy in interface Unitthat - The other unit.OperationException - Can't divide these units.protected abstract Unit myDivideBy(Unit unit) throws OperationException
unit - The other unit.OperationException - Can't divide these units.public final Unit divideInto(Unit that) throws OperationException
divideInto in interface Unitthat - The other unit.OperationException - Can't divide these units.protected abstract Unit myDivideInto(Unit unit) throws OperationException
unit - The other unit.OperationException - Can't divide these units.public final Unit raiseTo(int power) throws RaiseException
raiseTo in interface Unitpower - The power.RaiseException - Can't raise this unit to a power.protected abstract Unit myRaiseTo(int power) throws RaiseException
power - The power.RaiseException - Can't raise this unit to a power.public Unit log(double base)
UnitmW is a milliwatt unit, then mW.log(10.)
returns a base-ten logarithmic unit with a milliwatt reference level.public Converter getConverterTo(Unit outputUnit) throws ConversionException
getConverterTo in interface UnitoutputUnit - The unit to which to convert the numeric values.ConversionException - The units aren't convertible.public float convertTo(float amount,
Unit outputUnit)
throws ConversionException
convertTo in interface Unitamount - The numeric value.outputUnit - The unit to which to convert the numeric value.ConversionException - The units aren't convertible.public double convertTo(double amount,
Unit outputUnit)
throws ConversionException
convertTo in interface Unitamount - The numeric value.outputUnit - The unit to which to convert the numeric value.ConversionException - The units aren't convertible.public float[] convertTo(float[] amounts,
Unit outputUnit)
throws ConversionException
convertTo in interface Unitamounts - The numeric values.outputUnit - The unit to which to convert the numeric values.ConversionException - The units aren't convertible.public double[] convertTo(double[] amounts,
Unit outputUnit)
throws ConversionException
convertTo in interface Unitamounts - The numeric values.outputUnit - The unit to which to convert the numeric values.ConversionException - The units aren't convertible.public float[] convertTo(float[] input,
Unit outputUnit,
float[] output)
throws ConversionException
convertTo in interface Unitinput - The input numeric values.outputUnit - The unit to which to convert the numeric values.output - The output numeric values. May be the same array as the input
values.ConversionException - The units aren't convertible.public double[] convertTo(double[] input,
Unit outputUnit,
double[] output)
throws ConversionException
convertTo in interface Unitinput - The input numeric values.outputUnit - The unit to which to convert the numeric values.output - The output numeric values. May be the same array as the input
values.ConversionException - The units aren't convertible.public boolean isCompatible(Unit that)
isCompatible in interface Unitthat - The other unit.true if and only if numeric values in this unit are
convertible the other unit.public abstract int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()