public abstract class Quantity extends AbstractScienceObject
This class mixes a static master list of quantity types and their affiliated
units. Subclasses (such as Time
) can easily be created that
provide a set of units for a different type of quantity.
The Quantity class also works with the QuantityPanel GUI component to provide a text entry for a unit that automatically tracks, displays and converts values into a user-settable application wide default unit.
This code was developed by NASA, Goddard Space Flight Center, Code 588
for the Scientist's Expert Assistant (SEA) project for Next Generation
Space Telescope (NGST).
See Time
or Wavelength
for an examples of quantity
subclasses.
AbstractScienceObject.EventMonitor
Modifier and Type | Field and Description |
---|---|
protected double |
fValue
internal holder for quantity amount
|
NAME_PROPERTY, PENDING_PROPERTY, VALID_PROPERTY
Constructor and Description |
---|
Quantity() |
Modifier and Type | Method and Description |
---|---|
Quantity |
add(Quantity q)
adds the parameter to the value of the quantity and returns a NEW quantity
Throws a ClassCastException if the two classes are not compatible
|
static void |
addDefaultUnitsChangeListener(Class cl,
PropertyChangeListener listener)
Add a listener to the list of objects listening to changes in the default unit type
|
boolean |
equals(Object that)
compares to Quantities for equality.
|
protected static void |
fireDefaultUnitsChange(Class cl,
PropertyChangeEvent evt)
Fire a property change event to all listeners of the default unit type for
the specified Quantity subclass
|
protected void |
fireDefaultUnitsChange(PropertyChangeEvent evt)
Fire a property change event to all listeners of the default unit type
of this instance's class
|
List |
getAllUnits()
Returns the list of string labels for this instance's class
|
static List |
getAllUnits(Class cl)
Returns the list of all units for specfied Quantity subclass
|
List |
getAllUnitsAbbrev()
Returns the list of abbreviations for this instance's class
|
static List |
getAllUnitsAbbrev(Class cl)
Returns the list of abbreviations for specified Quantity subclass
|
String |
getDefaultUnits()
Returns the name of the current default units
|
static String |
getDefaultUnits(Class cl)
Returns the current default units for the specified Quantity subclass
|
static String |
getDefaultUnitsAbbrev(Class cl)
Returns the current default units for the specified Class
|
static String |
getDefaultUnitsProperty(Class cl)
Returns the current default propertyName for the specified Quantity subclass
|
static String |
getUnitsAbbrev(Class cl,
String def)
Returns the abbreviation for the specified Units type.
|
static String |
getUnitsIgnoreCase(Class cl,
String inUnits)
Does a case-insensitve search through the list of valid units for
a class and returns the proper casing for the specified units
|
double |
getValue()
Returns the value of the an instance as a
double in the
current default units |
abstract double |
getValue(String units)
Returns the quantity value in specified units.
|
int |
hashCode()
sets the hashcode value to the
int of the value |
static void |
initializeSubClass(Class cl,
List unitNames,
List abbrevStrings,
String defaultUnits,
String defaultUnitsChangeProperty)
Called by static initializer of subclasses to initialize a new quantity.
|
static boolean |
isInitialized(Class thisClass)
returns true if the a specified Class has been initialized as a Quantity
subclass
|
abstract Quantity |
newInstance(double inValue)
Returns a new instance an object with same value as creating instance.
|
static void |
removeDefaultUnitsChangeListener(Class cl,
PropertyChangeListener listener)
Remove a listener from the list of objects listening to changes in the default unit type
|
static void |
setDefaultUnits(Class cl,
String inUnits)
Sets the default units, for the specified Quantity subclass
|
protected abstract void |
setValue(double inValue,
String inUnits)
Sets the value of the Quantity in specified units
|
String |
toString()
returns a string displaying the current value in the default units
to 2 decimal places of accuracy.
|
String |
toString(int decs)
formats the current quantity value in the default units to the specfied decimal accuracy.
|
addEventMonitor, addPropertyChangeListener, areNamesEqual, clearAllListeners, clone, compareTo, createDefaultName, firePropertyChange, firePropertyChange, fireReplaceObject, fireReplaceObject, fireReplaceObject, fireVetoableChange, fireVetoableChange, getException, getLabel, getName, getObjectIdString, getObjectIdString, getParent, isHolding, isPending, isTracing, isValid, notifyEventMonitors, propertyChange, removeEventMonitor, removePropertyChangeListener, replaceObject, replaceObjectNYI, setException, setHolding, setName, setParent, setTraceAll, setTracing, writeDebug, writeError
public abstract double getValue(String units)
public abstract Quantity newInstance(double inValue)
Note this method is only expected to be called by QuantityPanel.actionPerformed()
protected abstract void setValue(double inValue, String inUnits)
public static void initializeSubClass(Class cl, List unitNames, List abbrevStrings, String defaultUnits, String defaultUnitsChangeProperty)
cl
- The class of the Quantity subclassunitNames
- a List of long names of the supported unitsabbrevStrings
- a List of abbreviations of the supported units (must
be same length and order as the unitNamesdefaultUnits
- the unit that is the starting default unitdefaultUnitsChangeProperty
- the bound propertyName to be specified
in PropertyChangeEvents when the default units are changedpublic static boolean isInitialized(Class thisClass)
public static String getDefaultUnitsAbbrev(Class cl)
public static String getUnitsAbbrev(Class cl, String def)
cl
- Class reference to the desired Quantity subclassdef
- the long name of the units for which the abbreviation is desired.public static String getDefaultUnits(Class cl)
public static String getDefaultUnitsProperty(Class cl)
public static void setDefaultUnits(Class cl, String inUnits)
public double getValue()
double
in the
current default unitspublic String getDefaultUnits()
public String toString()
toString
in class AbstractScienceObject
public String toString(int decs)
public boolean equals(Object that)
equals
in class AbstractScienceObject
public int hashCode()
int
of the valuepublic static List getAllUnits(Class cl)
cl
- Quantity subclasspublic List getAllUnits()
public static List getAllUnitsAbbrev(Class cl)
public List getAllUnitsAbbrev()
public static String getUnitsIgnoreCase(Class cl, String inUnits)
cl
- the subclass of Quantity to be searchedinUnits
- the units string to be searched forpublic static void addDefaultUnitsChangeListener(Class cl, PropertyChangeListener listener)
listener
- to addpublic Quantity add(Quantity q) throws ClassCastException
ClassCastException
public static void removeDefaultUnitsChangeListener(Class cl, PropertyChangeListener listener)
listener
- to removeprotected static void fireDefaultUnitsChange(Class cl, PropertyChangeEvent evt)
protected void fireDefaultUnitsChange(PropertyChangeEvent evt)
Copyright © 2023 Central Laboratory of the Research Councils. All Rights Reserved.