|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.sf.magnitude.core.Magnitude
public class Magnitude
A magnitude is a value and its units. Mathematical operations take into account the units.
Translation from the python project magnitude of Juan Reyero
| Constructor Summary | |
|---|---|
Magnitude(double val)
Creates a new dimension less Magnitude with the specified
value. |
|
Magnitude(double val,
Magnitude units)
Creates a new Magnitude from the specified value and the
units of another Magnitude object. |
|
Magnitude(double val,
java.lang.String units)
Creates a new Magnitude from the specified value and units
expressed as a string. |
|
| Method Summary | |
|---|---|
Magnitude |
add(Magnitude m)
Adds two magnitudes together. |
static void |
addMag(java.lang.String symbol,
Magnitude mag)
Adds a magnitude to the list of known magnitudes. |
boolean |
areSameUnits(Magnitude m)
Checks if the units of the two Magnitudes are the same. |
boolean |
areUnits(java.lang.String units)
Checks whether this Magnitude can be expressed using the
specified units. |
void |
clearPreferredUnits()
Clears the preferred units. |
Magnitude |
clone()
Creates a copy of the Magnitude object. |
int |
compareTo(Magnitude m)
Compares two Magnitudes. |
Magnitude |
div(double k)
Divides this Magnitude by a constant. |
Magnitude |
div(Magnitude m)
Divides two magnitudes. |
boolean |
equals(Magnitude obj,
Magnitude precision)
Checks whether two Magnitudes are almost equal. |
boolean |
equals(java.lang.Object obj)
Checks whether two Magnitudes are equal. |
protected double[] |
getBaseUnitExponents()
Returns a base unit exponents for this magnitude. |
java.lang.String |
getBaseUnitsLabel()
Returns a string representation of the units of this Magnitude. |
double |
getBaseUnitsValue()
Returns the value of this Magnitude in the base units. |
java.lang.String |
getPreferredUnitsLabel()
Returns the currently defined preferred units. |
double |
getPreferredUnitsValue()
Returns the value of this Magnitude in the preferred units. |
double |
getValue(java.lang.String units)
Returns the value of this Magnitude in the specified units. |
int |
hashCode()
Returns the hash code of this Magnitude. |
boolean |
isDimensionless()
Returns whether this Magnitude has units. |
boolean |
isExponent(BaseUnits baseUnit,
int value)
Checks if the exponent of the specified base unit is as specified. |
boolean |
isInfinite()
Returns true if the value of this Magnitude is
infinitely large, false otherwise. |
static boolean |
isInfinite(Magnitude m)
Returns true if the value of the specified
Magnitude is infinitely large, false otherwise. |
boolean |
isNaN()
Returns true if the value of this Magnitude is
a Not-a-Number (NaN), false otherwise. |
static boolean |
isNaN(Magnitude m)
Returns true if the value of the specified
Magnitude is a Not-a-Number (NaN), false
otherwise. |
boolean |
isUnidimensional()
Returns whether this Magnitude has only one type of unit. |
static boolean |
isValidUnits(java.lang.String units)
Checks whether the specified units are valid (can be parsed by a Magnitude object). |
Magnitude |
minus(Magnitude m)
Subtracts two magnitudes together. |
Magnitude |
modulo(Magnitude m)
Returns the modulo of two Magnitude's. |
Magnitude |
multiply(double k)
Multiplies this Magnitude by a constant. |
Magnitude |
multiply(Magnitude m)
Multiplies two magnitudes. |
Magnitude |
power(double exponent)
Power of this magnitude. |
void |
setPreferredUnits(java.lang.String units)
Sets the preferred units for the output ( getPreferredUnitsValue()). |
java.lang.String |
toString()
Returns a String representation. |
void |
validateEqualUnits(Magnitude m)
Checks if the units of this Magnitude are equal to the units
of another Magnitude. |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Magnitude(double val)
Magnitude with the specified
value.
val - value
public Magnitude(double val,
Magnitude units)
Magnitude from the specified value and the
units of another Magnitude object. The preferred units from
the specified Magnitude are also transfered to the new
Magnitude.
val - valueunits - a Magnitude defining the units
java.lang.NullPointerException - if the units Magnitude is null
public Magnitude(double val,
java.lang.String units)
Magnitude from the specified value and units
expressed as a string.
The preferred units are automatically set to be the specified units. This
preference is lost if a multiplication or a division is performed. For
the addition or the subtraction the preferred units of the first
Magnitude are kept.
val - valueunits - string representation of the units
java.lang.NullPointerException - if the units are null
java.lang.IllegalArgumentException - if the string does not represent valid units| Method Detail |
|---|
public static void addMag(java.lang.String symbol,
Magnitude mag)
symbol - string representation of the magnitudemag - definition of the magnitude
java.lang.NullPointerException - if the symbol or the magnitude is null
java.lang.IllegalArgumentException - if the symbol has already been defined to a different
magnitudepublic static boolean isInfinite(Magnitude m)
true if the value of the specified
Magnitude is infinitely large, false otherwise.
m - a magnitude
true if the value represented by this object is
positive infinity or negative infinity; false
otherwise.public static boolean isNaN(Magnitude m)
true if the value of the specified
Magnitude is a Not-a-Number (NaN), false
otherwise.
m - a magnitude
true if the value represented by this object is NaN;
false otherwise.public static boolean isValidUnits(java.lang.String units)
Magnitude object).
units - units
true if the units are valid, false
otherwise@CheckReturnValue public Magnitude add(Magnitude m)
m - other magnitude
java.lang.IllegalArgumentException - if the units are different
java.lang.NullPointerException - if the other magnitude is nullpublic boolean areSameUnits(Magnitude m)
Magnitudes are the same. For
the units to be the same, they must be specified in both
Magnitudes with the same exponent.
m - other magnitude
true if the two Magnitudes are the same
or false otherwise
java.lang.NullPointerException - if the other magnitude is nullpublic boolean areUnits(java.lang.String units)
Magnitude can be expressed using the
specified units.
units - units to test the current Magnitude against
true if this Magnitude can be expressed
using the specified units or false if otherwisepublic void clearPreferredUnits()
getBaseUnitsLabel().
public Magnitude clone()
Magnitude object.
clone in class java.lang.Objectpublic int compareTo(Magnitude m)
Magnitudes. The two magnitudes must have the
same units.
compareTo in interface java.lang.Comparable<Magnitude>m - other magnitude
java.lang.IllegalArgumentException - if the two magnitudes have different units
java.lang.NullPointerException - if the other magnitude is null@CheckReturnValue public Magnitude div(double k)
Magnitude by a constant.
k - constant
Magnitude@CheckReturnValue public Magnitude div(Magnitude m)
m - other magnitudes
java.lang.NullPointerException - if the other magnitude is null
public boolean equals(Magnitude obj,
Magnitude precision)
Magnitudes are almost equal. To be equal
they must have the same units and the difference between their value must
be less than the precision.
obj - other magnitudeprecision - level of precision
Magnitude are almost equal
java.lang.IllegalArgumentException - if the precision is less than 0.0
java.lang.IllegalArgumentException - if the precision is not a number (NaN)public boolean equals(java.lang.Object obj)
Magnitudes are equal. To be equal they
must have the same units and the same value.
equals in class java.lang.Objectobj - other magnitude
true if they are equal, false otherwiseprotected double[] getBaseUnitExponents()
public java.lang.String getBaseUnitsLabel()
Magnitude.
public double getBaseUnitsValue()
Magnitude in the base units.
public java.lang.String getPreferredUnitsLabel()
public double getPreferredUnitsValue()
Magnitude in the preferred units.
setPreferredUnits(java.lang.String)public double getValue(java.lang.String units)
Magnitude in the specified units.
units - units of the value
java.lang.NullPointerException - if the units are nullpublic int hashCode()
Magnitude.
hashCode in class java.lang.Objectpublic boolean isDimensionless()
Magnitude has units.
true if this Magnitude has no units,
false otherwise
public boolean isExponent(BaseUnits baseUnit,
int value)
baseUnit - base unit to test the exponent of.value - exponent value
true if the value matches the exponent or
false otherwisepublic boolean isInfinite()
true if the value of this Magnitude is
infinitely large, false otherwise.
true if the value represented by this object is
positive infinity or negative infinity; false
otherwise.public boolean isNaN()
true if the value of this Magnitude is
a Not-a-Number (NaN), false otherwise.
true if the value represented by this object is NaN;
false otherwise.public boolean isUnidimensional()
Magnitude has only one type of unit.
true if this Magnitude has one type of
unit, false otherwise@CheckReturnValue public Magnitude minus(Magnitude m)
m - other magnitude
java.lang.IllegalArgumentException - if the units are different
java.lang.NullPointerException - if the other magnitude is null@CheckReturnValue public Magnitude modulo(Magnitude m)
Magnitude's. The dividend and the
divisor must have the same units.
m - other Magnitude
Magnitude@CheckReturnValue public Magnitude multiply(double k)
Magnitude by a constant.
k - constant
Magnitude@CheckReturnValue public Magnitude multiply(Magnitude m)
m - other magnitudes
java.lang.NullPointerException - if the other magnitude is null@CheckReturnValue public Magnitude power(double exponent)
exponent - exponent
Magnitudepublic void setPreferredUnits(java.lang.String units)
getPreferredUnitsValue()). The new preferred units must be
equivalent to the present unit of this magnitude object.
units - new preferred units
java.lang.IllegalArgumentException - if the new preferred units are not equivalent to the present
unitspublic java.lang.String toString()
String representation. The preferred units are
used if they are set. If not the base units are used.
toString in class java.lang.ObjectString representationpublic void validateEqualUnits(Magnitude m)
Magnitude are equal to the units
of another Magnitude.
m - other magnitude
java.lang.IllegalArgumentException - if the two magnitudes don't have the same units
java.lang.NullPointerException - if the other magnitude is null
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||