etomica.units
Class PrefixedUnit

java.lang.Object
  extended by etomica.units.PrefixedUnit
All Implemented Interfaces:
Unit, Serializable

public class PrefixedUnit
extends Object
implements Unit, Serializable

Implementation of the Unit interface formed from a base Unit (e. g., grams) and a Prefix (e. g., kilo). The base unit cannot be changed after construction. However, the prefix can be changed using the setPrefix method.

See Also:
SimpleUnit, Prefix, Serialized Form

Constructor Summary
PrefixedUnit(Prefix prefix, Unit base)
          Constructs a PrefixedUnit using the given prefix and base
PrefixedUnit(Unit base)
          Constructs a PrefixedUnit using the given base and a Null prefix
 
Method Summary
 Dimension dimension()
          Returns the dimension of this baseUnit.
 double fromSim(double x)
          Takes the given value in simulation units and converts it to class units (considering prefix).
 Prefix getPrefix()
           
 Prefix prefix()
          Returns the prefix of the baseUnit.
 boolean prefixAllowed()
          Returns false to indicate that a prefix cannot be applied to an already prefixed baseUnit.
 void setPrefix(Prefix pre)
          Changes prefix to given instance if prefixAllowed flag is true
 String symbol()
          Accessor for symbol of baseUnit
 double toSim(double x)
          Takes the given value in class units (considering prefix) and converts it to simulation units.
 String toString()
          Accessor for common name of baseUnit
 Unit unit()
          Returns the base baseUnit of the baseUnit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PrefixedUnit

public PrefixedUnit(Unit base)
Constructs a PrefixedUnit using the given base and a Null prefix


PrefixedUnit

public PrefixedUnit(Prefix prefix,
                    Unit base)
Constructs a PrefixedUnit using the given prefix and base

Method Detail

dimension

public Dimension dimension()
Returns the dimension of this baseUnit. For example, the dimension of grams is mass.

Specified by:
dimension in interface Unit

setPrefix

public final void setPrefix(Prefix pre)
Changes prefix to given instance if prefixAllowed flag is true


getPrefix

public Prefix getPrefix()

prefix

public Prefix prefix()
Returns the prefix of the baseUnit. Equivalent to getPrefix().


unit

public Unit unit()
Returns the base baseUnit of the baseUnit.


toSim

public final double toSim(double x)
Takes the given value in class units (considering prefix) and converts it to simulation units.

Specified by:
toSim in interface Unit
Parameters:
x - a value in units of this class
Returns:
the value converted to simulation units

fromSim

public final double fromSim(double x)
Takes the given value in simulation units and converts it to class units (considering prefix).

Specified by:
fromSim in interface Unit
Parameters:
x - a value in simulation units
Returns:
the value converted to units of this class

toString

public String toString()
Accessor for common name of baseUnit

Overrides:
toString in class Object

symbol

public String symbol()
Accessor for symbol of baseUnit

Specified by:
symbol in interface Unit

prefixAllowed

public boolean prefixAllowed()
Returns false to indicate that a prefix cannot be applied to an already prefixed baseUnit.

Specified by:
prefixAllowed in interface Unit
See Also:
Unit.prefixAllowed()