com.rubecula.units
Class UnitsTable

java.lang.Object
  extended byjava.util.AbstractMap
      extended byjava.util.HashMap
          extended bycom.rubecula.util.StringMap
              extended bycom.rubecula.units.UnitsTable
All Implemented Interfaces:
java.lang.Cloneable, Identifiable, java.util.Map, java.io.Serializable
Direct Known Subclasses:
UnitsCGS, UnitsImperial, UnitsSI

public class UnitsTable
extends StringMap
implements Identifiable

This class extends HashMap to provide a table of units values.

Version:
$Revision: 1.6 $ // TODO Ensure Compliance.
Author:
Robin Hillyard
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.util.HashMap
 
Nested classes inherited from class java.util.AbstractMap
 
Field Summary
private  java.lang.String _Name
           
private  SystemFlag _System
           
 
Fields inherited from class java.util.HashMap
 
Fields inherited from class java.util.AbstractMap
 
Constructor Summary
UnitsTable(java.lang.String name, SystemFlag system)
           
 
Method Summary
 void audit(java.io.PrintStream stream)
           
 Measurable findParallel(Measurable units)
          Method to lookup a Measurable from this which is parallel to units.
 Measurable findParallel(Measurable units, SystemFlag system)
          Method to lookup a Measurable from this which is parallel to units and which is in system (if specified).
 Measurable findParallel(Measurable units, SystemFlag system, boolean named)
          Method to lookup a Measurable from this which is parallel to units and which is in system (if specified)
 java.lang.String getIdentifier()
          Method to get the specific identifier for an object.
 java.lang.String getName()
           
 SystemFlag getSystem()
           
 Measurable lookup(java.lang.String name)
          Method to lookup a Measurable by key.
 Measurable lookup(java.lang.String name, boolean matchOK)
          Method to lookup a Measurable by key (or by matching the name if matchOK is true) in this UnitsTable.
 Measurable match(Measurable units)
          Method to lookup a Measurable by key (or by matching the name if matchOK is true) in this UnitsTable.
(package private)  Measurable put(Measurable unit)
          Method to insert a unit in this table.
 java.lang.String toString()
           
 
Methods inherited from class com.rubecula.util.StringMap
get, get, put, put
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, isEmpty, keySet, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

_Name

private final java.lang.String _Name

_System

private final SystemFlag _System
Constructor Detail

UnitsTable

public UnitsTable(java.lang.String name,
                  SystemFlag system)
Method Detail

put

Measurable put(Measurable unit)
Method to insert a unit in this table. Successful insertion depends on the value of the unit's identifier. If it's not null, then an insertion will be made provided that there is no existing entry of the same name (else an exception will be thrown). If it's null, then no insertion will be ever be made. However, if the unit itself matches an existing unit in the table, then that (matching unit) will be returned. Otherwise, the given unit will be returned.

Parameters:
unit - the Measurable instance to be inserted.
Throws:
UnitsException - if name is not unique.

lookup

public Measurable lookup(java.lang.String name,
                         boolean matchOK)
Method to lookup a Measurable by key (or by matching the name if matchOK is true) in this UnitsTable.

Parameters:
name - the key of the desired Measurable, or (if matchOK true) a string which will match one of the elements in the table (the first to be found).
matchOK - true if it is OK to accept a Measurable whose name matches when the name does not match a key.
Returns:
the (unique) Measurable whose key is name else any Measurable in the table which "matches" the name.

lookup

public Measurable lookup(java.lang.String name)
Method to lookup a Measurable by key.

Parameters:
name - the key of the desired Measurable
Returns:
the (unique) Measurable whose key is name.

match

public Measurable match(Measurable units)
Method to lookup a Measurable by key (or by matching the name if matchOK is true) in this UnitsTable.

Parameters:
units - the units to match with one in this table.
Returns:
the (unique) Measurable whose key is name else any Measurable in the table which "matches" the name.

findParallel

public Measurable findParallel(Measurable units,
                               SystemFlag system,
                               boolean named)
Method to lookup a Measurable from this which is parallel to units and which is in system (if specified)

Parameters:
units - the units to match with one in this table.
system - the system to which result must belong (or null if don't care).
named - whether or not we insist that the parallel unit found must be named.
Returns:
the first Measurable which was found in this table that is also parallel to units and (if named is true) is named.

findParallel

public Measurable findParallel(Measurable units,
                               SystemFlag system)
Method to lookup a Measurable from this which is parallel to units and which is in system (if specified).

Parameters:
units - the units to match with one in this table.
system - the system to which result must belong (or null if don't care).
Returns:
the first named Measurable which was found in this table that is also parallel to units. If no named Measurable was found, then the first unnamed Measurable will be returned.

findParallel

public Measurable findParallel(Measurable units)
Method to lookup a Measurable from this which is parallel to units.

Parameters:
units - the units to match with one in this table.
Returns:
the first named Measurable which was found in this table that is also parallel to units. If no named Measurable was found, then the first unnamed Measurable will be returned.

toString

public java.lang.String toString()

audit

public void audit(java.io.PrintStream stream)

getIdentifier

public java.lang.String getIdentifier()
Description copied from interface: Identifiable
Method to get the specific identifier for an object.

Specified by:
getIdentifier in interface Identifiable
Returns:
the identifier.

getName

public java.lang.String getName()
Returns:
Returns the name.

getSystem

public SystemFlag getSystem()
Returns:
Returns the system.