|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjsky.science.AbstractScienceObject
jsky.science.Quantity
public abstract class Quantity
Quantity, abstract super class to match values and units and easily allow developers to manage the units a quantity-style value. This class also provides infrastructure for creating new types of quantity values and/or new sets of units.
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.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class jsky.science.AbstractScienceObject |
---|
AbstractScienceObject.EventMonitor |
Field Summary | |
---|---|
protected double |
fValue
internal holder for quantity amount |
Fields inherited from interface jsky.science.ScienceObjectModel |
---|
NAME_PROPERTY, PENDING_PROPERTY, VALID_PROPERTY |
Constructor Summary | |
---|---|
Quantity()
|
Method Summary | |
---|---|
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(java.lang.Class cl,
java.beans.PropertyChangeListener listener)
Add a listener to the list of objects listening to changes in the default unit type |
boolean |
equals(java.lang.Object that)
compares to Quantities for equality. |
protected static void |
fireDefaultUnitsChange(java.lang.Class cl,
java.beans.PropertyChangeEvent evt)
Fire a property change event to all listeners of the default unit type for the specified Quantity subclass |
protected void |
fireDefaultUnitsChange(java.beans.PropertyChangeEvent evt)
Fire a property change event to all listeners of the default unit type of this instance's class |
java.util.List |
getAllUnits()
Returns the list of string labels for this instance's class |
static java.util.List |
getAllUnits(java.lang.Class cl)
Returns the list of all units for specfied Quantity subclass |
java.util.List |
getAllUnitsAbbrev()
Returns the list of abbreviations for this instance's class |
static java.util.List |
getAllUnitsAbbrev(java.lang.Class cl)
Returns the list of abbreviations for specified Quantity subclass |
java.lang.String |
getDefaultUnits()
Returns the name of the current default units |
static java.lang.String |
getDefaultUnits(java.lang.Class cl)
Returns the current default units for the specified Quantity subclass |
static java.lang.String |
getDefaultUnitsAbbrev(java.lang.Class cl)
Returns the current default units for the specified Class |
static java.lang.String |
getDefaultUnitsProperty(java.lang.Class cl)
Returns the current default propertyName for the specified Quantity subclass |
static java.lang.String |
getUnitsAbbrev(java.lang.Class cl,
java.lang.String def)
Returns the abbreviation for the specified Units type. |
static java.lang.String |
getUnitsIgnoreCase(java.lang.Class cl,
java.lang.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(java.lang.String units)
Returns the quantity value in specified units. |
int |
hashCode()
sets the hashcode value to the int of the value |
static void |
initializeSubClass(java.lang.Class cl,
java.util.List unitNames,
java.util.List abbrevStrings,
java.lang.String defaultUnits,
java.lang.String defaultUnitsChangeProperty)
Called by static initializer of subclasses to initialize a new quantity. |
static boolean |
isInitialized(java.lang.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(java.lang.Class cl,
java.beans.PropertyChangeListener listener)
Remove a listener from the list of objects listening to changes in the default unit type |
static void |
setDefaultUnits(java.lang.Class cl,
java.lang.String inUnits)
Sets the default units, for the specified Quantity subclass |
protected abstract void |
setValue(double inValue,
java.lang.String inUnits)
Sets the value of the Quantity in specified units |
java.lang.String |
toString()
returns a string displaying the current value in the default units to 2 decimal places of accuracy. |
java.lang.String |
toString(int decs)
formats the current quantity value in the default units to the specfied decimal accuracy. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected double fValue
Constructor Detail |
---|
public Quantity()
Method Detail |
---|
public abstract double getValue(java.lang.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, java.lang.String inUnits)
public static void initializeSubClass(java.lang.Class cl, java.util.List unitNames, java.util.List abbrevStrings, java.lang.String defaultUnits, java.lang.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(java.lang.Class thisClass)
public static java.lang.String getDefaultUnitsAbbrev(java.lang.Class cl)
public static java.lang.String getUnitsAbbrev(java.lang.Class cl, java.lang.String def)
cl
- Class reference to the desired Quantity subclassdef
- the long name of the units for which the abbreviation is desired.public static java.lang.String getDefaultUnits(java.lang.Class cl)
public static java.lang.String getDefaultUnitsProperty(java.lang.Class cl)
public static void setDefaultUnits(java.lang.Class cl, java.lang.String inUnits)
public double getValue()
double
in the
current default units
public java.lang.String getDefaultUnits()
public java.lang.String toString()
toString
in class AbstractScienceObject
public java.lang.String toString(int decs)
public boolean equals(java.lang.Object that)
equals
in class AbstractScienceObject
public int hashCode()
int
of the value
hashCode
in class java.lang.Object
public static java.util.List getAllUnits(java.lang.Class cl)
cl
- Quantity subclasspublic java.util.List getAllUnits()
public static java.util.List getAllUnitsAbbrev(java.lang.Class cl)
public java.util.List getAllUnitsAbbrev()
public static java.lang.String getUnitsIgnoreCase(java.lang.Class cl, java.lang.String inUnits)
cl
- the subclass of Quantity to be searchedinUnits
- the units string to be searched forpublic static void addDefaultUnitsChangeListener(java.lang.Class cl, java.beans.PropertyChangeListener listener)
listener
- to addpublic Quantity add(Quantity q) throws java.lang.ClassCastException
java.lang.ClassCastException
public static void removeDefaultUnitsChangeListener(java.lang.Class cl, java.beans.PropertyChangeListener listener)
listener
- to removeprotected static void fireDefaultUnitsChange(java.lang.Class cl, java.beans.PropertyChangeEvent evt)
protected void fireDefaultUnitsChange(java.beans.PropertyChangeEvent evt)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |