etomica.units
Class SimpleUnit

java.lang.Object
  extended by etomica.units.SimpleUnit
All Implemented Interfaces:
Unit, Serializable
Direct Known Subclasses:
Ampere, Angstrom, Bar, Barye, Calorie, Candela, Coulomb, Count, CubicCentimeter, CubicMeter, Dalton, Debye, Decimal, Degree, Dyne, Electron, ElectronVolt, Erg, Gram, Joule, Kelvin, Liter, Meter, Mole, Newton, Pascal, Percent, Picosecond, Pixel, Poise, Radian, Second, Statcoulomb, Volt

public class SimpleUnit
extends Object
implements Unit, Serializable

Superclass for all base unit classes. These classes provide a means for indicating the physical units of a given quantity, and present methods for converting between units. A BaseUnit can be used as is, or combined with a Prefix to form a PrefixedUnit. Units are employed by I/O classes (usually a Device or Display) to handle unit conversions and labeling of graphic elements.
By convention, each subclass of any base unit will contain a static field named UNIT, which is a handle to an instance of that unit. One can access an instance of any unit class through this static member.
Each general base unit type (i.e., dimension) is defined as an abstract class. Each of these abstract classes contains an inner static subclass (named Sim) that defines the unit as derived from the basic simulation units (Dalton-A-ps) Thus an instance of the base simulation units for any dimensioned quantity can be accessed by the handle BaseUnit.Energy.Sim.UNIT (e.g. for the energy unit).

See Also:
Serialized Form

Constructor Summary
SimpleUnit(Dimension dimension, double toSim, String name, String symbol, boolean prefixAllowed)
          Constructor.
 
Method Summary
 Dimension dimension()
          Returns the dimension of this base unit.
 double fromSim(double x)
          Takes the given value in simulation units and converts it to class units.
 boolean prefixAllowed()
          Returns flag indicating whether a prefix is allowed with this unit.
 String symbol()
          Accessor for symbol of unit
 double toSim(double x)
          Takes the given value in class units and converts it to simulation units.
 String toString()
          Accessor for common name of unit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleUnit

public SimpleUnit(Dimension dimension,
                  double toSim,
                  String name,
                  String symbol,
                  boolean prefixAllowed)
Constructor.

Parameters:
to - conversion factor from this unit to simulation units
name - string describing this unit
symbol - symbol for this unit
prefixAllowed - flag indicating if this unit is suitable for use with a prefix (e.g., kilo, nano)
Method Detail

dimension

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

Specified by:
dimension in interface Unit

toSim

public final double toSim(double x)
Takes the given value in class units 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.

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 unit

Overrides:
toString in class Object

symbol

public String symbol()
Accessor for symbol of unit

Specified by:
symbol in interface Unit

prefixAllowed

public boolean prefixAllowed()
Returns flag indicating whether a prefix is allowed with this unit. Some units (such as Angstroms) are not normally defined with a prefix attached, and for such units this flag can be set to false to prohibit the application of a prefix. This indication is usually made in the constructor of the base unit class.

Specified by:
prefixAllowed in interface Unit