|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.Object
|
+--java.util.Observable
|
+--UnitConverter
This class implements unit conversions between Metric and IP. The root unit system for all calculations is always metric. Input and output values can be metric or I-P (inch-pound). The class contains a state variable, set using the static setUnitSystem() method, which sets the unit system that will be used for all conversions.
Methods that do input or output should create an instance of this class for each type of unit with which they deal. They should then run input data through getMetricValue() to get the value that will be used for all calculations. Output data should be run through the getConvertedValue() method to get the value that will be displayed. If this is done, unit coversion is otherwise transparent to other elements of the program.
Note that if the unit system is set for metric, the conversion methods return input data unchanged.
The class provides methods for retrieving a string for the type of unit (e.g. "Power") and a label for the unit (e.g. "Watts"). The label is appropriate for the unit system currently selected.
The class extends the Observable class, giving a convenient means for updating objects that utilize it for conversions, when the unit system changes.
| Field Summary | |
static int |
AREA
Indicates that the type of unit is area. |
static int |
ENERGY
Indicates that the type of unit is energy. |
static int |
IP
Of choices METRIC or IP, indicates that English units are used. |
static int |
LENGTH
Indicates that the type of unit is length. |
static int |
METRIC
Of choices METRIC or IP, indicates that metric units are used. |
static int |
NOTHING
Indicates that no conversion will be made. |
static int |
POWER
Indicates that the type of unit is power. |
static int |
POWER_PER_AREA
Indicates that the type of unit is power per unit area. |
static int |
RVALUE
Indicates that the type of unit is R value. |
static int |
TEMPERATURE
Indicates that the type of unit is Temperature. |
static int |
UVALUE
Indicates that the type of unit is U value. |
static int |
VELOCITY_FT_SEC
Indicates that the type of unit is velocity. |
static int |
VELOCITY_MPH
Indicates that the type of unit is velocity. |
| Constructor Summary | |
UnitConverter(int unitType)
Creates a UnitConverter object for conversion of unitType units. |
|
| Method Summary | |
double |
getConversionFactor()
Returns conversion factor (Metric to English). |
double |
getConvertedValue(double metric_value)
Converts the passed value, assumed to be in metric, into the current unit system. |
static double |
getConvertedValue(double metric_value,
int unit_type)
|
java.lang.String |
getLabel()
Returns the current label associated with these units (e.g. |
double |
getMetricValue(double value)
Converts the passed value, assumed to be in the current unit system, to metric and returns the value. |
java.lang.String |
getName()
Returns the name of the units for which this object converts (e.g. |
static int |
getUnitSystem()
|
int |
getUnitType()
Returns the type of unit for this converter. |
static void |
setUnitSystem(int unitSystem)
Sets the system of units to METRIC or IP. |
| Methods inherited from class java.util.Observable |
addObserver,
clearChanged,
countObservers,
deleteObserver,
deleteObservers,
hasChanged,
notifyObservers,
notifyObservers,
setChanged |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Field Detail |
public static final int METRIC
public static final int IP
public static final int NOTHING
public static final int TEMPERATURE
public static final int POWER_PER_AREA
public static final int POWER
public static final int ENERGY
public static final int RVALUE
public static final int UVALUE
public static final int AREA
public static final int VELOCITY_MPH
public static final int VELOCITY_FT_SEC
public static final int LENGTH
| Constructor Detail |
public UnitConverter(int unitType)
| Method Detail |
public static void setUnitSystem(int unitSystem)
public static int getUnitSystem()
public int getUnitType()
public java.lang.String getName()
public java.lang.String getLabel()
public static double getConvertedValue(double metric_value,
int unit_type)
public double getConvertedValue(double metric_value)
public double getConversionFactor()
public double getMetricValue(double value)
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||