deegree 2.3 (2010/04/09 10:10 build-4-official)

org.deegree.crs.components
Class Unit

java.lang.Object
  extended by org.deegree.crs.Identifiable
      extended by org.deegree.crs.components.Unit
All Implemented Interfaces:
Serializable

public final class Unit
extends Identifiable
implements Serializable

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

Version:
$Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
Author:
Rutger Bezema, last edited by: $Author: mschneider $
See Also:
Serialized Form

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 DAY
          Unit of time.
static Unit DEGREE
          Unit of angle.
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, double scale, Unit baseType)
          Unit constructor, which uses the name as the id.
Unit(String symbol, String name, String id)
          Unit constructor.
Unit(String symbol, String name, String id, double scale, Unit baseType)
          Unit constructor.
 
Method Summary
 boolean canConvert(Unit other)
          Check if amount of the specified unit can be converted into amount of this unit.
 double convert(double value, Unit 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.
 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.crs.Identifiable
checkForNullObject, checkForNullObject, checkForNullObject, getAreaOfUse, getAreaOfUseBBox, getAreasOfUse, getDescription, getDescriptions, getIdAndName, getIdentifier, getIdentifiers, getName, getNames, getVersion, getVersions, hasID
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

RADIAN

public static final Unit RADIAN
Unit of angle.


DEGREE

public static final Unit DEGREE
Unit of angle.


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.


USFOOT

public static final Unit USFOOT
US foot; unit of length, with base unit of 0.304 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,
            String id)
Unit constructor.

Parameters:
symbol -
name - of the unit, e.g. metre
id - 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,
            Unit 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,
            String id,
            double scale,
            Unit baseType)
Unit constructor.

Parameters:
symbol - of the units, e.g. 'm'
name - human readable name, e.g. metre
id - 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(Unit other)
Check if amount of the specified unit can be converted into amount of this unit.

Parameters:
other -
Returns:
true if this unit can be converted into the other unit

convert

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

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

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 Identifiable
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 Identifiable

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 Object
Returns:
(int) ( result >>> 32 ) ^ (int) result;
See Also:
Object.hashCode()

getScale

public final double getScale()
Returns:
the scale to convert to the base unit.

isBaseType

public final boolean isBaseType()
Returns:
true if this is a base type

deegree 2.3 (2010/04/09 10:10 build-4-official)

an open source project founded by lat/lon, Bonn, Germany.
For more information visit: http://www.deegree.org