|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.nrao.sss.measure.Frequency
public class Frequency
A measure of frequency.
Note About Accuracy
This class originally used java's primitive double type
for storage and calculation. Certain transformations, though,
led to results that where not accurate enough for many purposes.
Because of that, the internal references to double
have been replaced with references to BigDecimal
.
Version Info:
$Revision: 1816 $ |
$Date: 2008-12-23 10:21:00 -0700 (Tue, 23 Dec 2008) $ |
$Author: dharland $ |
Constructor Summary | |
---|---|
Frequency()
Creates a new frequency of zero gigahertz. |
|
Frequency(BigDecimal gigahertz)
Creates a new frequency of gigahertz gigahertz. |
|
Frequency(BigDecimal magnitude,
FrequencyUnits units)
Creates a new frequency with the given magnitude and units. |
|
Frequency(String gigahertz)
Creates a new frequency of gigahertz gigahertz. |
|
Frequency(String magnitude,
FrequencyUnits units)
Creates a new frequency with the given magnitude and units. |
Method Summary | |
---|---|
Frequency |
add(Frequency other)
Adds other frequency to this one. |
Frequency |
clone()
Returns a frequency that is equal to this one. |
int |
compareTo(Frequency otherFreq)
Compares this frequency with the otherFreq for order. |
Frequency |
convertTo(FrequencyUnits newUnits)
Converts this measure of frequency to the new units. |
Frequency |
divideBy(BigDecimal divisor)
Divides this frequency by divisor . |
Frequency |
divideBy(String divisor)
Divides this frequency by divisor . |
BigDecimal |
dividedBy(Frequency other)
Returns the result of dividing this frequency by other ,
without altering this frequency. |
boolean |
equals(Object o)
Returns true if o is equal to this frequency. |
Frequency |
getAbsoluteDistanceFrom(FrequencyRange range)
Returns the smallest positive difference between this frequency and range . |
FrequencyUnits |
getUnits()
Returns the units of this frequency. |
BigDecimal |
getValue()
Returns the magnitude of this frequency. |
int |
hashCode()
Returns a hash code value for this frequency. |
boolean |
isEndPointOf(FrequencyRange range)
Returns true if this frequency is equal to either the low or high frequency of range . |
boolean |
isInDefaultState()
Returns true if this frequency is in its default state, no matter how it got there. |
boolean |
isInfinite()
Returns true if the magnitude of this frequency approaches infinity. |
Wave |
makeWave()
Creates and returns a new wave with the speed of light and this frequency. |
Wave |
makeWave(LinearVelocity speedOfWave)
Creates and returns a new wave with the given speed and this frequency. |
Frequency |
multiplyBy(BigDecimal multiplier)
Multiplies this frequency by multiplier . |
Frequency |
multiplyBy(String multiplier)
Multiplies this frequency by multiplier . |
Frequency |
normalize()
Converts the value and units of this frequency so that the value is between one and one thousand. |
static Frequency |
parse(String frequencyString)
Returns a new frequency based on frequencyString . |
void |
reset()
Resets this frequency so that it is equal to a frequency created via the no-argument constructor. |
void |
set(BigDecimal value,
FrequencyUnits units)
Sets the magnitude and units of this frequency. |
void |
set(String frequencyText)
Sets the value and units of this frequency based on frequencyText . |
void |
set(String value,
FrequencyUnits units)
Sets the magnitude and units of this frequency. |
void |
setAllowNegativeValues(boolean allow)
Configure this frequency so that it allows, or disallows, negative values. |
void |
setUnits(FrequencyUnits newUnits)
Sets the units of this frequency to newUnits . |
void |
setValue(BigDecimal newValue)
Sets the magnitude of this frequency to newValue . |
void |
setValue(String newValue)
Sets the magnitude of this frequency to newValue . |
Frequency |
subtract(Frequency other)
Subtracts other frequency from this one. |
String |
toString()
Returns a text representation of this frequency. |
String |
toString(int minFracDigits,
int maxFracDigits)
Returns a text representation of this frequency. |
String |
toStringNormalized(int minFracDigits,
int maxFracDigits)
Returns a text representation of a normalized representation of this frequency. |
BigDecimal |
toUnits(FrequencyUnits otherUnits)
Returns the magnitude of this frequency in otherUnits . |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Frequency()
public Frequency(BigDecimal gigahertz)
gigahertz
gigahertz.
See setValue(BigDecimal)
for information
about valid parameter values and exceptions that might
be thrown.
public Frequency(String gigahertz)
gigahertz
gigahertz.
See setValue(String)
for information
about valid parameter values and exceptions that might
be thrown.
public Frequency(BigDecimal magnitude, FrequencyUnits units)
set(BigDecimal, FrequencyUnits)
for information
about valid parameter values and exceptions that might
be thrown.
public Frequency(String magnitude, FrequencyUnits units)
set(String, FrequencyUnits)
for information
about valid parameter values and exceptions that might
be thrown.
Method Detail |
---|
public void reset()
public BigDecimal getValue()
public FrequencyUnits getUnits()
public void set(String frequencyText)
frequencyText
.
See parse(String)
for the expected format of
frequencyText
.
If the parsing fails, this frequency will be kept in its current state.
frequencyText
- a string that will be converted into a frequency.
IllegalArgumentException
- if frequencyText
is not in the expected form.public final void set(BigDecimal value, FrequencyUnits units)
See setValue(BigDecimal)
for more information on legal
values for value.
value
- the new magnitude for this frequency.units
- the new units for this frequency.public final void set(String value, FrequencyUnits units)
See setValue(String)
for more information on legal
values for value.
value
- the new magnitude for this frequency.units
- the new units for this frequency.public final void setValue(BigDecimal newValue)
newValue
.
Note that the units of this frequency are unaffected by this method.
newValue
- the new magnitude for this frequency. This value is normally be zero or
positive, but negative values will be accepted if the user has
specifically allowed negative values by calling
setAllowNegativeValues(boolean)
. It is permissible for this
value to be infinite, but it may not be null.
NumberFormatException
- if newValue
is null, or if it is negative and negative
values have not been expressly allowed.public final void setValue(String newValue)
newValue
.
Note that the units of this frequency are unaffected by this method.
newValue
- the new magnitude for this frequency. This value is normally zero or
positive, but negative values will be accepted if the user has
specifically allowed negative values by calling
allowNegativeValues
. It is permissible for this value to be
infinite, but it may not be NaN. The allowable representations
of infinity are "infinity", "+infinity", and
"-infinity"; these values are not case sensitive.
NumberFormatException
- if newValue
is null, NaN,
or if it is negative and negative values have not been expressly allowed.public final void setUnits(FrequencyUnits newUnits)
newUnits
.
Note that the value of this frequency is unaffected by
this method. Contrast this with convertTo(FrequencyUnits)
.
newUnits
- the new units for this frequency. If newUnits
is null
it will be treated as FrequencyUnits.GIGAHERTZ
.public void setAllowNegativeValues(boolean allow)
allow
- true if this frequency should be allowed to hold negative values.
IllegalStateException
- if allow is false and this frequency is currently
negative.public boolean isInDefaultState()
A frequency is in its default state if both its value and
its units are the same as those of a frequency newly created via
the no-argument constructor
.
A frequency whose most recent update came via the
reset
method is also in its default state.
public boolean isInfinite()
public boolean isEndPointOf(FrequencyRange range)
range
.
range
- a frequency range that may or may not have a low or high frequency equal
to this one.
range
.public Frequency convertTo(FrequencyUnits newUnits)
After this method is complete this frequency will have units of
units
and its value will have been converted
accordingly.
newUnits
- the new units for this frequency.
If newUnits
is null an
IllegalArgumentException
will be thrown.
BigDecimal gigahertz =
myFrequency.convertTo(FrequencyUnits.GIGAHERTZ).getValue();
public BigDecimal toUnits(FrequencyUnits otherUnits)
otherUnits
.
Note that this method does not alter the state of this frequency.
Contrast this with convertTo(FrequencyUnits)
.
otherUnits
- the units in which to express this frequency's magnitude.
If newUnits
is null, it will be treated as
FrequencyUnits.GIGAHERTZ
.
otherUnits
.public Frequency normalize()
If this frequency is exactly zero, the default units, as opposed to the smallest units, will be used.
public Frequency add(Frequency other)
other
frequency to this one.
If all of the items below are true:
other
- the frequency to be added to this frequency.
public Frequency subtract(Frequency other)
other
frequency from this one.
If the result of the subtraction is negative, and if this frequency does not allow negative values, the result of this operation will be a frequency of zero.
other
- the frequency to be subtracted from this frequency.
public Frequency multiplyBy(String multiplier)
multiplier
.
multiplier
- the number by which this frequency should be multiplied.
This value must not result in a frequency magnitude that is
negative or NaN.
ArithmeticException
- if the multiplication results in a negative value and this frequency
is not allowed to be negative.
NumberFormatException
- if multiplier is NaN or is
otherwise rejected by the BigDecimal class.
NullPointerException
- if multiplier is null.public Frequency multiplyBy(BigDecimal multiplier)
multiplier
.
multiplier
- the number by which this frequency should be multiplied.
This value must not result in a frequency magnitude that is
negative.
ArithmeticException
- if the multiplication results in a negative value and this frequency
is not allowed to be negative.
NullPointerException
- if multiplier is null.public Frequency divideBy(String divisor)
divisor
.
divisor
- the number by which this frequency should be divided.
This value must not result in a frequency magnitude that is
negative or NaN.
ArithmeticException
- if the division results in a negative value and this frequency
is not allowed to be negative, or if the divisor is zero.
NumberFormatException
- if divisor is null, NaN, or is
otherwise rejected by the BigDecimal class.dividedBy(Frequency)
public Frequency divideBy(BigDecimal divisor)
divisor
.
divisor
- the number by which this frequency should be divided.
This value must not result in a frequency magnitude that is
negative or NaN.
ArithmeticException
- if the division results in a negative value and this frequency
is not allowed to be negative, or if the divisor is zero.
NumberFormatException
- if divisor is null.public BigDecimal dividedBy(Frequency other)
other
,
without altering this frequency.
other
- the frequency by which this one is divided. This parameter
is the denominator
in the equation quotient = dividend / divisor,
this frequency is the numerator, and the quotient is the
value returned.
other
.divideBy(BigDecimal)
,
divideBy(String)
public Frequency getAbsoluteDistanceFrom(FrequencyRange range)
range
.
range
- the range to which a distance is computed.
range
. If range
is null, null
is returned. If range
contains this frequency,
a frequency of zero hertz is returned.public Wave makeWave()
public Wave makeWave(LinearVelocity speedOfWave)
speedOfWave
- the speed of the returned wave.
public static Frequency parse(String frequencyString)
frequencyString
.
Valid Formats
Let R be the text representation of a real number.
Let w represent zero or more whitespace characters.
Let S be a valid units
symbol.
Format One: wRw. The given number will be defined to be
in units of hertz
.
Format Two: wRwSw.
frequencyString
- a string that will be converted into a frequency.
In addition to the valid formats listed above, this parameter may
use the special values "infinity", "+infinity",
and "-infinity", with or without units, and without
regard to case.
IllegalArgumentException
- if frequencyString
is not in
the expected form.public String toString()
toString
in class Object
public String toString(int minFracDigits, int maxFracDigits)
minFracDigits
- the minimum number of places after the decimal point.maxFracDigits
- the maximum number of places after the decimal point.
public String toStringNormalized(int minFracDigits, int maxFracDigits)
normalize()
for
the definition of "normalized".)
minFracDigits
- the minimum number of places after the decimal point.maxFracDigits
- the maximum number of places after the decimal point.
public Frequency clone()
clone
in class Object
public boolean equals(Object o)
o
is equal to this frequency.
equals
in class Object
public int hashCode()
hashCode
in class Object
public int compareTo(Frequency otherFreq)
otherFreq
for order.
compareTo
in interface Comparable<Frequency>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |