org.cts.units
Class Unit

java.lang.Object
  extended by org.cts.IdentifiableComponent
      extended by org.cts.units.Unit
All Implemented Interfaces:
Serializable, Identifiable

public class Unit
extends IdentifiableComponent
implements Serializable

According to wikipedia, a unit of measurement is a standardised quantity of a physical property, used as a factor to express occurring quantities of that property. This interface is not a complete definition of what units are and what one can do with them, but rather a simple definition for conversion purposes as used ni geodesy. See JSR-275 for a complete package.

Author:
Michaƫl Michaud, Jules Party
See Also:
Serialized Form

Field Summary
static Unit ARC_MINUTE
           
static Unit ARC_SECOND
           
static Unit CENTIMETER
           
static Unit DECIMETER
           
static Unit DEGREE
           
static Unit FOOT
           
static Unit GRAD
           
static Unit KILOMETER
           
static Unit METER
           
static Unit MILLIMETER
           
static Unit RADIAN
           
static Unit SECOND
           
static Unit UNIT
           
static Unit USFOOT
           
static Unit YARD
           
 
Fields inherited from interface org.cts.Identifiable
DEFAULT, LOCAL, UNKNOWN
 
Constructor Summary
Unit(Quantity quantity, double scale, double offset, Identifier id)
          Creates a new Unit for the Quantity Q.
Unit(Quantity quantity, double scale, Identifier id)
          Creates a new unit for this quantity.
Unit(Quantity quantity, Identifier id)
          Creates a base unit for this quantity.
 
Method Summary
 boolean equals(Object o)
          Returns true if this Unit can be considered as equals to another one.
 double fromBaseUnit(double measure)
          Convert a measure from base unit(s) into this unit.
 Unit getBaseUnit()
          Return the base unit for measures of the same quantity.
static Unit getBaseUnit(Quantity quantity)
          Static method returning the base Unit for this quantity Class.
 ArrayList<String> getNames()
          Return a list of the names of the unit (ex : metre, meter).
 double getOffset()
          Returns the offset from base unit to this (ex. temperature).
 Quantity getQuantity()
          Returns the Quantity measured by this Unit.
 double getScale()
          Returns the scale of this unit compared to the base unit.
 String getSymbol()
          Return the preferred symbol to use with this unit.
static Unit getUnit(Quantity quantity, String symbol)
          Static method returning a Unit from its symbol and quantity Class.
 int hashCode()
          Returns the hash code for this Unit.
 boolean isComparable(Unit anotherUnit)
          Returns true if quantity measured by this unit and quantity measured by anotherUnit are equals.
 void setScale(double scale)
          Set factor or scale.
 double toBaseUnit(double measure)
          Convert a measure from this unit into base unit(s).
 String toString()
          String representation of this Unit.
 String toWKT()
          Returns a WKT representation of the unit.
 
Methods inherited from class org.cts.IdentifiableComponent
addAlias, addRemark, getAliases, getAuthorityKey, getAuthorityName, getCode, getComponent, getIdentifier, getName, getRemarks, getShortName, setIdentifier, setRemarks, setShortName
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

RADIAN

public static final Unit RADIAN

DEGREE

public static final Unit DEGREE

ARC_MINUTE

public static final Unit ARC_MINUTE

ARC_SECOND

public static final Unit ARC_SECOND

GRAD

public static final Unit GRAD

METER

public static final Unit METER

MILLIMETER

public static final Unit MILLIMETER

CENTIMETER

public static final Unit CENTIMETER

DECIMETER

public static final Unit DECIMETER

KILOMETER

public static final Unit KILOMETER

FOOT

public static final Unit FOOT

USFOOT

public static final Unit USFOOT

YARD

public static final Unit YARD

UNIT

public static final Unit UNIT

SECOND

public static final Unit SECOND
Constructor Detail

Unit

public Unit(Quantity quantity,
            Identifier id)
Creates a base unit for this quantity. The name of the identifier should be the name of the unit and the short name of the identifier, the symbol of this unit.

Parameters:
quantity - the quantity measured by this unit
id - the identifier of this unit

Unit

public Unit(Quantity quantity,
            double scale,
            Identifier id)
Creates a new unit for this quantity. The name of the identifier should be the name of the unit and the short name of the identifier, the symbol of this unit.

Parameters:
quantity - the quantity measured by this unit
scale - the scale factor of this unit compared to the base unit
id - the identifier of this unit

Unit

public Unit(Quantity quantity,
            double scale,
            double offset,
            Identifier id)
Creates a new Unit for the Quantity Q. The name of the identifier should be the name of the unit and the short name of the identifier, the symbol of this unit.

Parameters:
quantity - the quantity measured by this unit
scale - the scale factor of this unit compared to the base unit
offset - the shift factor of this unit compared to the base unit
id - the identifier of this unit
Method Detail

getUnit

public static Unit getUnit(Quantity quantity,
                           String symbol)
Static method returning a Unit from its symbol and quantity Class.

Parameters:
quantity - the Quantity measured by the Unit to be found
symbol - the symbol of the Unit to be found
Returns:
the Unit measuring this quantity and having this symbol or null if no Unit has been instanciated with this symbol for this quantity until now.

getBaseUnit

public static Unit getBaseUnit(Quantity quantity)
Static method returning the base Unit for this quantity Class.

Parameters:
quantity - the quantity Class of the Unit to be found
Returns:
the base Unit for this quantity

getNames

public ArrayList<String> getNames()
Return a list of the names of the unit (ex : metre, meter).


getQuantity

public Quantity getQuantity()
Returns the Quantity measured by this Unit.


getScale

public double getScale()
Returns the scale of this unit compared to the base unit.


getOffset

public double getOffset()
Returns the offset from base unit to this (ex. temperature).


toBaseUnit

public double toBaseUnit(double measure)
Convert a measure from this unit into base unit(s).

Parameters:
measure - the measure to convert into base unit

fromBaseUnit

public double fromBaseUnit(double measure)
Convert a measure from base unit(s) into this unit.

Parameters:
measure - the measure to convert into this unit

getSymbol

public String getSymbol()
Return the preferred symbol to use with this unit.


setScale

public void setScale(double scale)
Set factor or scale.

Parameters:
scale - the scale to set to the unit.

getBaseUnit

public Unit getBaseUnit()
Return the base unit for measures of the same quantity. If the base unit has not been defined, one default base unit with an unknown name and an empty symbol is created.


isComparable

public boolean isComparable(Unit anotherUnit)
Returns true if quantity measured by this unit and quantity measured by anotherUnit are equals.

Parameters:
anotherUnit - another unit

toWKT

public String toWKT()
Returns a WKT representation of the unit.


toString

public String toString()
String representation of this Unit.

Overrides:
toString in class IdentifiableComponent

equals

public boolean equals(Object o)
Returns true if this Unit can be considered as equals to another one.

Overrides:
equals in class IdentifiableComponent
Parameters:
o - the object to compare this Unit against

hashCode

public int hashCode()
Returns the hash code for this Unit.

Overrides:
hashCode in class IdentifiableComponent


Copyright © 2014 IRSTV CNRS-FR-2488. All Rights Reserved.