com.rubecula.jquantity
Class UnitsTable
java.lang.Object
java.util.AbstractMap
java.util.HashMap
com.rubecula.jquantity.UnitsTable
- All Implemented Interfaces:
- Cloneable, com.rubecula.util.Identifiable, Map, Serializable
- Direct Known Subclasses:
- UnitsCGS, UnitsImperial, UnitsSI
- public class UnitsTable
- extends HashMap
- implements com.rubecula.util.Identifiable
This class extends HashMap to provide a table of units values.
- Version:
- $Revision: 1.11 $ @todo Ensure Compliance.
- Author:
- Robin Hillyard
- See Also:
- Serialized Form
Nested classes inherited from class java.util.HashMap |
|
Nested classes inherited from class java.util.AbstractMap |
|
Fields inherited from class java.util.HashMap |
|
Methods inherited from class java.util.HashMap |
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values |
_Name
private final String _Name
_System
private final SystemFlag _System
UnitsTable
public UnitsTable(String name,
SystemFlag system)
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:
JQuantityException
- if name is not unique.
lookup
public Measurable lookup(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(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)
- 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 Measurable which was found in this table that is also parallel to units.
findParallel
public Measurable findParallel(Measurable units)
- 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.
- Returns:
- the first Measurable which was found in this table that is also parallel to units.
toString
public String toString()
audit
public void audit(PrintStream stream)
getIdentifier
public String getIdentifier()
- Specified by:
getIdentifier
in interface com.rubecula.util.Identifiable
getName
public String getName()
- Returns:
- Returns the name.
getSystem
public SystemFlag getSystem()
- Returns:
- Returns the system.