visad
Class OffsetUnit
- java.lang.Object
-
- visad.Unit
-
- visad.OffsetUnit
-
- All Implemented Interfaces:
- java.io.Serializable
public final class OffsetUnit extends Unit implements java.io.Serializable
A class that represents a scaled unit with an offset. Instances are immutable.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description OffsetUnit(double offset)Construct an offset, dimensionless unit.OffsetUnit(double offset, java.lang.String identifier)Construct an offset, dimensionless unit with an identifier.OffsetUnit(double offset, Unit unit)Construct an offset unit from another unit.OffsetUnit(double offset, Unit unit, java.lang.String identifier)Construct an offset unit from another unit and an identifier.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description Unitdivide(Unit that)Divide an offset unit by another unit.booleanequals(Unit unit)Indicates if this instance equals a unit.UnitgetAbsoluteUnit()Gets the absolute unit of this unit.java.lang.StringgetDefinition()Return the definition of this unit.DerivedUnitgetDerivedUnit()Returns the derived unit that underlies this unit.inthashCode()Returns the hash code of this instance.booleanisConvertible(Unit unit)Indicate whether this unit is convertible with another unit.booleanisDimensionless()Indicates if this instance is dimensionless.Unitlog(double base)Returns the logarithmic unit that has this unit as its reference level.static voidmain(java.lang.String[] args)Test this class.Unitmultiply(Unit that)Multiply an offset unit by another unit.Unitpow(double power)Raises an offset unit to a power.Unitpow(int power)Raises an offset unit to a power.Unitroot(int root)Returns the N-th root of this unit.Unitscale(double amount)Scale this unit by an amount.Unitshift(double offset)Shift this unit by an amount.double[]toThat(double[] values, Unit that)Convert values from this unit to another unit.double[]toThat(double[] values, Unit that, boolean copy)Convert values from this unit to another unit.float[]toThat(float[] values, Unit that)Convert values from this unit to another unit.float[]toThat(float[] values, Unit that, boolean copy)Convert values from this unit to another unit.double[]toThis(double[] values, Unit that)Convert values to this unit from another unit.double[]toThis(double[] values, Unit that, boolean copy)Convert values to this unit from another unit.float[]toThis(float[] values, Unit that)Convert values to this unit from another unit.float[]toThis(float[] values, Unit that, boolean copy)Convert values to this unit from another unit.-
Methods inherited from class visad.Unit
canConvert, canConvertArray, clone, convertTuple, convertTuple, convertTuple, convertTuple, copyUnitsArray, equals, getIdentifier, sqrt, toString, toThat, toThis, transformUnits, transformUnits, transformUnits, transformUnits
-
-
-
-
Constructor Detail
-
OffsetUnit
public OffsetUnit(double offset)
Construct an offset, dimensionless unit. The identifier will be empty.- Parameters:
offset- The amount of offset.
-
OffsetUnit
public OffsetUnit(double offset, java.lang.String identifier)Construct an offset, dimensionless unit with an identifier.- Parameters:
offset- The amount of offset.identifier- The name or abbreviation for the cloned unit. May benullor empty.
-
OffsetUnit
public OffsetUnit(double offset, Unit unit)Construct an offset unit from another unit. The identifier will be that of the base unit if the offset is zero; otherwise, the identifier will benull.- Parameters:
offset- The amount of offset.unit- The other unit.
-
OffsetUnit
public OffsetUnit(double offset, Unit unit, java.lang.String identifier)Construct an offset unit from another unit and an identifier.- Parameters:
offset- The amount of offset.unit- The other unit.identifier- The name or abbreviation for the cloned unit. May benullor empty.
-
-
Method Detail
-
isDimensionless
public boolean isDimensionless()
Indicates if this instance is dimensionless. A unit is dimensionless if it is a measure of a dimensionless quantity like angle or concentration. Examples of dimensionless units include radian, degree, steradian, and "g/kg".
- Specified by:
isDimensionlessin classUnit- Returns:
- True if an only if this unit is dimensionless.
-
scale
public Unit scale(double amount) throws UnitException
Description copied from class:UnitScale this unit by an amount.- Specified by:
scalein classUnit- Parameters:
amount- The amount by which to scale this unit. E.g. Unit yard = meter.scale(0.9144);- Returns:
- A unit equal to this instance scaled by the given amount.
- Throws:
UnitException- This unit cannot be scaled.
-
shift
public Unit shift(double offset) throws UnitException
Description copied from class:UnitShift this unit by an amount.- Specified by:
shiftin classUnit- Parameters:
offset- The amount by which to shift this unit. E.g. Unit celsius = kelvin.shift(273.15);- Returns:
- A unit equal to this instance with the origin shifted by the given amount.
- Throws:
UnitException- The unit subclass is unknown.
-
log
public Unit log(double base) throws UnitException
Description copied from class:UnitReturns the logarithmic unit that has this unit as its reference level. Not all units can be used as a reference level.- Specified by:
login classUnit- Parameters:
base- The logarithmic base: one of2,Math.E, or10.- Returns:
- The logarithmic unit that has this instance as its reference level.
- Throws:
UnitException- if this unit can't be used as a reference level for a logarithmic unit.
-
pow
public Unit pow(int power) throws UnitException
Raises an offset unit to a power. Raising an offset unit to a power is equivalent to first stripping-off the offset amount and then raising the resulting non-offset unit to the power.- Specified by:
powin classUnit- Parameters:
power- The power to raise this unit by.- Returns:
- A corresponding unit.
- Throws:
UnitException- if the underlying unit can't be raised to the given power.
-
pow
public Unit pow(double power) throws UnitException
Raises an offset unit to a power. Raising an offset unit to a power is equivalent to first stripping-off the offset amount and then raising the resulting non-offset unit to the power.- Specified by:
powin classUnit- Parameters:
power- The power to raise this unit by.- Returns:
- A corresponding unit.
- Throws:
UnitException- if the underlying unit can't be raised to the given power.
-
root
public Unit root(int root) throws java.lang.IllegalArgumentException, UnitException
Returns the N-th root of this unit. Taking the root of an offset unit is equivalent to first stripping-off the offset amount and then taking the root of the resulting non-offset unit.- Specified by:
rootin classUnit- Parameters:
root- The root to take (e.g. 2 means square root). May not be zero.- Returns:
- The unit corresponding to the
root-th root of this unit. - Throws:
java.lang.IllegalArgumentException- The root value is zero or the resulting unit would have a non-integral unit dimension.UnitException- if the underlying unit can't have the given root taken.
-
getDefinition
public java.lang.String getDefinition()
Return the definition of this unit.- Specified by:
getDefinitionin classUnit- Returns:
- The definition of this unit (e.g. "K @ 273.15" for degree celsius).
-
multiply
public Unit multiply(Unit that) throws UnitException
Multiply an offset unit by another unit.- Specified by:
multiplyin classUnit- Parameters:
that- The unit with which to multiply this unit.- Returns:
- A unit equal to this instance multiplied by the given unit.
- Throws:
UnitException- Can't multiply units.
-
divide
public Unit divide(Unit that) throws UnitException
Divide an offset unit by another unit.- Specified by:
dividein classUnit- Parameters:
that- The unit to divide into this unit.- Returns:
- A unit equal to this instance divided by the given unit.
- Throws:
UnitException- Can't divide units.
-
toThis
public double[] toThis(double[] values, Unit that) throws UnitExceptionConvert values to this unit from another unit.- Specified by:
toThisin classUnit- Parameters:
values- The values to be converted.that- The unit ofvalues.- Returns:
- The converted values in units of this unit. require: The units are convertible. promise: Neither unit has been modified.
- Throws:
UnitException- The units are not convertible.
-
toThis
public float[] toThis(float[] values, Unit that) throws UnitExceptionConvert values to this unit from another unit.- Specified by:
toThisin classUnit- Parameters:
values- The values to be converted.that- The unit ofvalues.- Returns:
- The converted values in units of this unit. require: The units are convertible. promise: Neither unit has been modified.
- Throws:
UnitException- The units are not convertible.
-
toThis
public double[] toThis(double[] values, Unit that, boolean copy) throws UnitExceptionConvert values to this unit from another unit.- Overrides:
toThisin classUnit- Parameters:
values- The values to be converted.that- The unit ofvalues.copy- if false andthatequals this, returnvalues, else return a new array- Returns:
- The converted values in units of this unit. require: The units are convertible. promise: Neither unit has been modified.
- Throws:
UnitException- The units are not convertible.
-
toThis
public float[] toThis(float[] values, Unit that, boolean copy) throws UnitExceptionConvert values to this unit from another unit.- Overrides:
toThisin classUnit- Parameters:
values- The values to be converted.that- The unit ofvalues.copy- if false, convert values in place.- Returns:
- The converted values in units of this unit. require: The units are convertible. promise: Neither unit has been modified.
- Throws:
UnitException- The units are not convertible.
-
toThat
public double[] toThat(double[] values, Unit that) throws UnitExceptionConvert values from this unit to another unit.- Specified by:
toThatin classUnit- Parameters:
values- The values to be converted in units of this unit.that- The unit to which to convert the values.- Returns:
- The converted values. require: The units are convertible. promise: Neither unit has been modified.
- Throws:
UnitException- The units are not convertible.
-
toThat
public float[] toThat(float[] values, Unit that) throws UnitExceptionConvert values from this unit to another unit.- Specified by:
toThatin classUnit- Parameters:
values- The values to be converted in units of this unit.that- The unit to which to convert the values.- Returns:
- The converted values. require: The units are convertible. promise: Neither unit has been modified.
- Throws:
UnitException- The units are not convertible.
-
toThat
public double[] toThat(double[] values, Unit that, boolean copy) throws UnitExceptionConvert values from this unit to another unit.- Overrides:
toThatin classUnit- Parameters:
values- The values to be converted in units of this unit.that- The unit to which to convert the values.copy- if false andthatequals this, return avalues, else return a new array- Returns:
- The converted values. require: The units are convertible. promise: Neither unit has been modified.
- Throws:
UnitException- The units are not convertible.
-
toThat
public float[] toThat(float[] values, Unit that, boolean copy) throws UnitExceptionConvert values from this unit to another unit.- Overrides:
toThatin classUnit- Parameters:
values- The values to be converted in units of this unit.that- The unit to which to convert the values.copy- if false andthatequals this, return avalues, else return a new array- Returns:
- The converted values. require: The units are convertible. promise: Neither unit has been modified.
- Throws:
UnitException- The units are not convertible.
-
getAbsoluteUnit
public Unit getAbsoluteUnit()
Gets the absolute unit of this unit. An interval in the underlying physical quantity has the same numeric value in an absolute unit of a unit as in the unit itself -- but an absolute unit is always referenced to the physical origin of the underlying physical quantity. For example, the absolute unit corresponding to degrees celsius is degrees kelvin -- and calling this method on a degrees celsius unit obtains a degrees kelvin unit.- Overrides:
getAbsoluteUnitin classUnit- Returns:
- The absolute unit corresponding to this unit.
-
isConvertible
public boolean isConvertible(Unit unit)
Indicate whether this unit is convertible with another unit. If one unit is convertible with another, then thetoThis(...)/ andtoThat(...)methods will not throw a UnitException. Unit A is convertible with unit B if and only if unit B is convertible with unit A; hence, calling-order is irrelevant.- Specified by:
isConvertiblein classUnit- Parameters:
unit- The other unit.- Returns:
- True if and only if this unit is convertible with the other unit.
-
main
public static void main(java.lang.String[] args) throws UnitExceptionTest this class.- Parameters:
args- Arguments (ignored).- Throws:
UnitException- A problem occurred.
-
equals
public boolean equals(Unit unit)
Indicates if this instance equals a unit.
-
hashCode
public int hashCode()
Returns the hash code of this instance.Object.hashCode()should be overridden wheneverObject.equals(Object)is.
-
getDerivedUnit
public DerivedUnit getDerivedUnit()
Description copied from class:UnitReturns the derived unit that underlies this unit.- Specified by:
getDerivedUnitin classUnit- Returns:
- The derived unit that underlies this unit.
-
-
DMelt 3.0 © DataMelt by jWork.ORG