org.deegree.cs.components
Class Unit

java.lang.Object
  extended by org.deegree.cs.CRSIdentifiable
      extended by org.deegree.cs.components.Unit
All Implemented Interfaces:
Object, TypedObjectNode, IUnit, CRSResource

public final class Unit
extends CRSIdentifiable
implements IUnit

The Unit class defines a mechanism to convert between different measurements units, such as british_yard and meter.

Version:
$Revision: 29642 $, $Date: 2011-02-11 13:59:33 +0100 (Fri, 11 Feb 2011) $
Author:
Rutger Bezema, last edited by: $Author: lbuesching $

Field Summary
static Unit ARC_SEC
          Unit of angle, which is defined to be 1/3600 of a degree, or PI/(180*3600) Radian.
static Unit BRITISHYARD
          British yard; unit of length.
static Unit CLARK_FOOT
          Clarkse foot; unit of length, with base unit of 0.304797 meter.
static Unit DAY
          Unit of time.
static Unit DEGREE
          Unit of angle.
static IUnit DMSH
          1 degree minute second hemisphere = 1 degree
static Unit FOOT
          foot; unit of length, with base unit of 0.304 meter.
static Unit INDIAN_FOOT
          Indian foot; unit of length, with base unit of 0.304799 meter.
static Unit METRE
          Base unit of length.
static Unit MILLISECOND
          Unit of time.
static Unit RADIAN
          Unit of angle.
static Unit SECOND
          Base unit of time.
static Unit USFOOT
          US foot; unit of length, with base unit of 0.304 meter.
 
Constructor Summary
Unit(String symbol, String name)
          Unit constructor.
Unit(String symbol, String name, CRSCodeType code)
          Unit constructor.
Unit(String symbol, String name, CRSCodeType code, double scale, IUnit baseType)
          Unit constructor.
Unit(String symbol, String name, double scale, IUnit baseType)
          Unit constructor, which uses the name as the id.
 
Method Summary
 boolean canConvert(IUnit other)
          Check if amount of the specified unit can be converted into amount of this unit.
 double convert(double value, IUnit targetUnit)
          Convert a value in this unit to the given unit if possible.
static Unit createUnitFromString(String unit)
          Will create a unit from the given String.
 boolean equals(Object object)
          Compare this unit symbol with the specified object for equality.
 IUnit getBaseType()
           
 double getScale()
           
 int hashCode()
          Implementation as proposed by Joshua Block in Effective Java (Addison-Wesley 2001), which supplies an even distribution and is relatively fast.
 boolean isBaseType()
           
 double toBaseUnits(double value)
          Convert a value in this unit to the base unit, e.g. degree->radians
 String toString()
           
 
Methods inherited from class org.deegree.cs.CRSIdentifiable
addAreaOfUse, addName, checkForNullObject, checkForNullObject, checkForNullObject, getAreaOfUse, getAreaOfUseBBox, getAreasOfUse, getCode, getCodeAndName, getCodes, getDescription, getDescriptions, getId, getName, getNames, getOrignalCodeStrings, getVersion, getVersions, hasCode, hasId, hasIdOrName, setDefaultAreaOfUse, setDefaultDescription, setDefaultId, setDefaultName, setDefaultVersion
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.deegree.cs.CRSResource
addAreaOfUse, addName, getAreaOfUse, getAreaOfUseBBox, getAreasOfUse, getCode, getCodeAndName, getCodes, getDescription, getDescriptions, getName, getNames, getOrignalCodeStrings, getVersion, getVersions, hasCode, hasId, hasIdOrName, setDefaultAreaOfUse, setDefaultDescription, setDefaultId, setDefaultName, setDefaultVersion
 
Methods inherited from interface org.deegree.commons.tom.Object
getId
 

Field Detail

RADIAN

public static final Unit RADIAN
Unit of angle.


DEGREE

public static final Unit DEGREE
Unit of angle.


DMSH

public static final IUnit DMSH
1 degree minute second hemisphere = 1 degree


ARC_SEC

public static final Unit ARC_SEC
Unit of angle, which is defined to be 1/3600 of a degree, or PI/(180*3600) Radian.


METRE

public static final Unit METRE
Base unit of length.


BRITISHYARD

public static final Unit BRITISHYARD
British yard; unit of length.


FOOT

public static final Unit FOOT
foot; unit of length, with base unit of 0.304 meter.


USFOOT

public static final Unit USFOOT
US foot; unit of length, with base unit of 0.304 meter.


CLARK_FOOT

public static final Unit CLARK_FOOT
Clarkse foot; unit of length, with base unit of 0.304797 meter.


INDIAN_FOOT

public static final Unit INDIAN_FOOT
Indian foot; unit of length, with base unit of 0.304799 meter.


SECOND

public static final Unit SECOND
Base unit of time.


MILLISECOND

public static final Unit MILLISECOND
Unit of time.


DAY

public static final Unit DAY
Unit of time.

Constructor Detail

Unit

public Unit(String symbol,
            String name,
            CRSCodeType code)
Unit constructor.

Parameters:
symbol -
name - of the unit, e.g. metre
code - of the unit

Unit

public Unit(String symbol,
            String name)
Unit constructor.

Parameters:
symbol -
name - of the unit, e.g. metre

Unit

public Unit(String symbol,
            String name,
            double scale,
            IUnit baseType)
Unit constructor, which uses the name as the id.

Parameters:
symbol - of the units, e.g. 'm'
name - human readable name, e.g. metre
scale - to convert to the base type.
baseType - the baseType

Unit

public Unit(String symbol,
            String name,
            CRSCodeType code,
            double scale,
            IUnit baseType)
Unit constructor.

Parameters:
symbol - of the units, e.g. 'm'
name - human readable name, e.g. metre
code - of the unit.
scale - to convert to the base type.
baseType - the baseType
Method Detail

createUnitFromString

public static Unit createUnitFromString(String unit)
Will create a unit from the given String. If no appropriate unit was found null will be returned.

Parameters:
unit - to convert to an actual unit.
Returns:
a unit or null

canConvert

public boolean canConvert(IUnit other)
Check if amount of the specified unit can be converted into amount of this unit.

Specified by:
canConvert in interface IUnit
Parameters:
other -
Returns:
true if this unit can be converted into the other unit

convert

public final double convert(double value,
                            IUnit targetUnit)
Convert a value in this unit to the given unit if possible.

Specified by:
convert in interface IUnit
Parameters:
value - to be converted
targetUnit - to convert to
Returns:
the converted value or the same value if this unit equals given unit.
Throws:
IllegalArgumentException - if no conversion can be applied.

toBaseUnits

public final double toBaseUnits(double value)
Convert a value in this unit to the base unit, e.g. degree->radians

Specified by:
toBaseUnits in interface IUnit
Parameters:
value - to be converted
Returns:
the converted value or the same value if this unit is a base unit.

toString

public String toString()
Overrides:
toString in class CRSIdentifiable
Returns:
the symbol of this unit.

equals

public boolean equals(Object object)
Compare this unit symbol with the specified object for equality. Only symbols are compared; other parameters are ignored.

Overrides:
equals in class CRSIdentifiable

hashCode

public int hashCode()
Implementation as proposed by Joshua Block in Effective Java (Addison-Wesley 2001), which supplies an even distribution and is relatively fast. It is created from field f as follows:
  • boolean -- code = (f ? 0 : 1)
  • byte, char, short, int -- code = (int)f
  • long -- code = (int)(f ^ (f >>>32))
  • float -- code = Float.floatToIntBits(f);
  • double -- long l = Double.doubleToLongBits(f); code = (int)(l ^ (l >>> 32))
  • all Objects, (where equals( ) calls equals( ) for this field) -- code = f.hashCode( )
  • Array -- Apply above rules to each element

Combining the hash code(s) computed above: result = 37 * result + code;

Overrides:
hashCode in class CRSIdentifiable
Returns:
(int) ( result >>> 32 ) ^ (int) result;
See Also:
Object.hashCode()

getScale

public final double getScale()
Specified by:
getScale in interface IUnit
Returns:
the scale to convert to the base unit.

isBaseType

public final boolean isBaseType()
Specified by:
isBaseType in interface IUnit
Returns:
true if this is a base type

getBaseType

public IUnit getBaseType()
Specified by:
getBaseType in interface IUnit
Returns:
the base unit.


Copyright © 2011. All Rights Reserved.