|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.unit.Unit
public class Unit
A Unit
converts from one set of units to another.
Field Summary | |
---|---|
protected double |
b
|
protected int[] |
exp
|
java.lang.String |
latex
|
protected double |
m
|
protected java.lang.String |
name
|
static Unit |
pure
The unitless unit, such as radians, percents, or inches per inch. |
Constructor Summary | |
---|---|
protected |
Unit(java.lang.String s)
Do not use this, use newUnit(String) instead. |
Method Summary | |
---|---|
java.lang.Object |
clone()
|
java.lang.String |
definition()
Return the definition of this unit in terms of SI units. |
static java.util.Enumeration |
enumerate()
Return an enumeration of all defined units. |
boolean |
equals(Unit other)
Return true if this is the same unit as other . |
Unit |
exponent(double n)
Create a new unit that is this one raised to the power n. |
Unit |
exponent(int n)
Create a new unit that is this one raised to the power n. |
double |
from(double x)
Convert from this unit to standard SI units. |
double |
getB()
Return the conversion offset (used for debugging). |
double |
getM()
Return the conversion scale factor (used for debugging). |
int[] |
getType()
Return the expontents relative to primitive units (used for debugging). |
static Unit |
newUnit(java.lang.String s)
Create, if necessary, a new unit from the given definiton. |
static Unit |
newUnit(java.lang.String name,
double m,
java.lang.String s)
Make a unit which is m times the unit s . |
static Unit |
newUnit(java.lang.String name,
double m,
java.lang.String s,
double b)
Make a unit which is m times the unit s ,
with an offset of b . |
static Unit |
newUnit(java.lang.String name,
double m,
Unit u,
double b)
Make a unit which is m times the unit u ,
with an offset of b . |
Unit |
product(Unit b)
Create a new unit that is the product of this one and the other one. |
Unit |
quotient(Unit b)
Create a new unit that is the quotient of this one divided by the other one. |
boolean |
sameType(Unit other)
Return true if other measures the same
thing (length, time, energy, ...). |
double |
to(double x)
Convert from standard SI units to this unit. |
java.lang.String |
toString()
Returns the name, or if unnamed, the definition of this unit. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.lang.String name
public java.lang.String latex
protected int[] exp
protected double m
protected double b
public static final Unit pure
Constructor Detail |
---|
protected Unit(java.lang.String s)
newUnit(String)
instead.
Method Detail |
---|
public double from(double x)
public double to(double x)
public java.lang.String toString()
toString
in class java.lang.Object
public double getM()
public double getB()
public int[] getType()
public java.lang.Object clone()
clone
in class java.lang.Object
public java.lang.String definition()
public boolean sameType(Unit other)
other
measures the same
thing (length, time, energy, ...).
public boolean equals(Unit other)
other
.
public static Unit newUnit(java.lang.String s) throws ParseException
newUnit("kW hr")
.
If a unit with this name has alread been created it is returned,
otherwise a new unit is created.
ParseException
public static Unit newUnit(java.lang.String name, double m, java.lang.String s) throws ParseException
m
times the unit s
.
For example, to define feet in terms of inches, use:
newUnit("ft", 12.0,"in");(It helps to read this as 1 foot equals 12 inches.)
ParseException
public static Unit newUnit(java.lang.String name, double m, java.lang.String s, double b) throws ParseException
m
times the unit s
,
with an offset of b
.
For example, to define the temperature scale C from K use:
newUnit("C", 1, "K", -273.15);
Note: In order to "do what I mean" for units such as "J/C" or "BTU/F", the offset is only used for units that are pure temperatures, such as "C" or "F". This means that "J/C" is the same as "J/K" or "C^2" is the same as "K^2". That's probably what you want anyway.
ParseException
public static Unit newUnit(java.lang.String name, double m, Unit u, double b)
m
times the unit u
,
with an offset of b
.
public Unit exponent(int n)
public Unit exponent(double n) throws UnitMismatchException
UnitMismatchException
public Unit product(Unit b)
public Unit quotient(Unit b)
public static java.util.Enumeration enumerate() throws ParseException
ParseException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |