edu.nrao.sss.measure
Class FluxDensity

java.lang.Object
  extended by edu.nrao.sss.measure.FluxDensity
All Implemented Interfaces:
Cloneable, Comparable<FluxDensity>

public class FluxDensity
extends Object
implements Cloneable, Comparable<FluxDensity>

A measure of flux density.

Version Info:

$Revision: 1816 $
$Date: 2008-12-23 10:21:00 -0700 (Tue, 23 Dec 2008) $
$Author: dharland $

Since:
2006-05-16
Author:
David M. Harland

Constructor Summary
FluxDensity()
          Creates a new flux density of zero janskies.
FluxDensity(BigDecimal janskies)
          Creates a new flux density of janskies janskies.
FluxDensity(BigDecimal value, FluxDensityUnits units)
          Creates a new flux density with the given magnitude and units.
FluxDensity(String janskies)
          Creates a new flux density of janskies janskies.
FluxDensity(String value, FluxDensityUnits units)
          Creates a new flux density with the given magnitude and units.
 
Method Summary
 FluxDensity add(FluxDensity other)
          Adds other flux density to this one.
 FluxDensity clone()
          Returns a flux density that is equal to this one.
 int compareTo(FluxDensity otherFlux)
          Compares this flux density with the otherFlux for order.
 FluxDensity convertTo(FluxDensityUnits newUnits)
          Converts this measure of flux density to the new units.
 boolean equals(Object o)
          Returns true if o is equal to this flux density.
 FluxDensityUnits getUnits()
          Returns the units of this flux density.
 BigDecimal getValue()
          Returns the magnitude of this flux density.
 int hashCode()
          Returns a hash code value for this flux density.
 boolean isInDefaultState()
          Returns true if this flux density is in its default state, no matter how it got there.
 boolean isInfinite()
          Returns true if this flux density is infinite.
 FluxDensity normalize()
          Converts the value and units of this flux density so that the value is between one and one thousand.
static FluxDensity parse(String fluxString)
          Returns a new flux density based on fluxString.
 void reset()
          Resets this flux density so that it is equal to a flux density created via the no-argument constructor.
 void set(BigDecimal value, FluxDensityUnits units)
          Sets the magnitude and units of this flux density.
 void set(String fluxString)
          Sets the value and units of this flux density based on fluxString.
 void set(String value, FluxDensityUnits units)
          Sets the magnitude and units of this flux density.
 void setUnits(FluxDensityUnits newUnits)
          Sets the units of this flux density to newUnits.
 void setValue(BigDecimal newValue)
          Sets the magnitude of this flux density to newValue.
 void setValue(String newValue)
          Sets the magnitude of this flux density to newValue.
 FluxDensity subtract(FluxDensity other)
          Subtracts other flux density from this one.
 String toString()
          Returns a text representation of this flux density.
 String toString(int minFracDigits, int maxFracDigits)
          Returns a text representation of this flux density.
 BigDecimal toUnits(FluxDensityUnits otherUnits)
          Returns the magnitude of this flux density in otherUnits.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FluxDensity

public FluxDensity()
Creates a new flux density of zero janskies.


FluxDensity

public FluxDensity(BigDecimal janskies)
Creates a new flux density of janskies janskies. See setValue(BigDecimal) for information about valid parameter values and exceptions that might be thrown.

Parameters:
janskies - the magnitude of this flux density in janskies.

FluxDensity

public FluxDensity(String janskies)
Creates a new flux density of janskies janskies. See setValue(BigDecimal) for information about valid parameter values and exceptions that might be thrown.

Parameters:
janskies - the magnitude of this flux density in janskies.

FluxDensity

public FluxDensity(BigDecimal value,
                   FluxDensityUnits units)
Creates a new flux density with the given magnitude and units. See set(BigDecimal, FluxDensityUnits) for information about valid parameter values and exceptions that might be thrown.

Parameters:
value - the magnitude of this flux density.
units - the units in which value is expressed.

FluxDensity

public FluxDensity(String value,
                   FluxDensityUnits units)
Creates a new flux density with the given magnitude and units. See set(BigDecimal, FluxDensityUnits) for information about valid parameter values and exceptions that might be thrown.

Parameters:
value - the magnitude of this flux density.
units - the units in which value is expressed.
Method Detail

reset

public void reset()
Resets this flux density so that it is equal to a flux density created via the no-argument constructor.


getValue

public BigDecimal getValue()
Returns the magnitude of this flux density.

Returns:
the magnitude of this flux density.

getUnits

public FluxDensityUnits getUnits()
Returns the units of this flux density.

Returns:
the units of this flux density.

set

public final void set(BigDecimal value,
                      FluxDensityUnits units)
Sets the magnitude and units of this flux density.

See setValue(BigDecimal) for more information on legal values for value.

Parameters:
value - the new magnitude of this flux density.
units - the units in which value is expressed.

set

public final void set(String value,
                      FluxDensityUnits units)
Sets the magnitude and units of this flux density.

See setValue(String) for more information on legal values for value.

Parameters:
value - the new magnitude of this flux density.
units - the units in which value is expressed.

setValue

public final void setValue(BigDecimal newValue)
Sets the magnitude of this flux density to newValue.

Note that the units of this flux density are unaffected by this method.

Parameters:
newValue - the new magnitude for this flux density. This value may not be negative or null but may be infinite.
Throws:
NumberFormatException - if newValue is null or negative.

setValue

public final void setValue(String newValue)
Sets the magnitude of this flux density to newValue.

Note that the units of this flux density are unaffected by this method.

Parameters:
newValue - the new magnitude for this flux density. This value may not be negative or null but may be infinite. The allowable representations of infinity are "infinity", "+infinity", and "-infinity"; these values are not case sensitive.
Throws:
NumberFormatException - if newValue is null or negative.

setUnits

public final void setUnits(FluxDensityUnits newUnits)
Sets the units of this flux density to newUnits.

Note that the value of this distance is unaffected by this method. Contrast this with convertTo(FluxDensityUnits).

Parameters:
newUnits - the new units for this flux density. If newUnits is null an IllegalArgumentException will be thrown.

set

public void set(String fluxString)
Sets the value and units of this flux density based on fluxString. See parse(String) for the expected format of fluxString.

If the parsing fails, this flux density will be kept in its current state.

Parameters:
fluxString - a string that will be converted into a flux density.
Throws:
IllegalArgumentException - if fluxString is not in the expected form.
Since:
2008-10-01

isInDefaultState

public boolean isInDefaultState()
Returns true if this flux density is in its default state, no matter how it got there.

A flux density is in its default state if both its value and its units are the same as those of a flux density newly created via the no-argument constructor. A flux density whose most recent update came via the reset method is also in its default state.

Returns:
true if this flux density is in its default state.

isInfinite

public boolean isInfinite()
Returns true if this flux density is infinite.

Returns:
true if this flux density is infinite.

convertTo

public FluxDensity convertTo(FluxDensityUnits newUnits)
Converts this measure of flux density to the new units.

After this method is complete this flux density will have units of units and its value will have been converted accordingly.

Parameters:
newUnits - the new units for this flux density. If newUnits is null an IllegalArgumentException will be thrown.
Returns:
this flux density. The reason for this return type is to allow code of this nature: double janskies = myFluxDensity.convertTo(FluxDensityUnits.JANSKY).getValue();

toUnits

public BigDecimal toUnits(FluxDensityUnits otherUnits)
Returns the magnitude of this flux density in otherUnits.

Note that this method does not alter the state of this flux density. Contrast this with convertTo(FluxDensityUnits).

Parameters:
otherUnits - the units in which to express this flux density's magnitude.
Returns:
this flux density's value converted to otherUnits.

normalize

public FluxDensity normalize()
Converts the value and units of this flux density so that the value is between one and one thousand. The units will be 10x Hertz, where x is evenly divisible by three. The value might not fall in the range [1.0-1000.0) if the units are the smallest or largest available.

Returns:
this frequency, after normalization.

add

public FluxDensity add(FluxDensity other)
Adds other flux density to this one.

Parameters:
other - the flux density to be added to this flux density.
Returns:
this flux density, after the addition.

subtract

public FluxDensity subtract(FluxDensity other)
Subtracts other flux density from this one.

Parameters:
other - the flux density to be subtracted from this flux density.
Returns:
this flux density, after the subtraction.

parse

public static FluxDensity parse(String fluxString)
Returns a new flux density based on fluxString.

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 janskies.

Format Two: wRwSw.

Special Cases
A fluxString of null or "" (the empty string) will not result in an IllegalArgumentException, but will instead return a flux density of zero janskies.

Parameters:
fluxString - text that will be converted into a flux density.
Returns:
a new flux density.
Throws:
IllegalArgumentException - if fluxString is not in the expected form.

toString

public String toString()
Returns a text representation of this flux density.

Overrides:
toString in class Object

toString

public String toString(int minFracDigits,
                       int maxFracDigits)
Returns a text representation of this flux density.

Parameters:
minFracDigits - the minimum number of places after the decimal point.
maxFracDigits - the maximum number of places after the decimal point.
Returns:
a text representation of this flux density.

clone

public FluxDensity clone()
Returns a flux density that is equal to this one.

Overrides:
clone in class Object

equals

public boolean equals(Object o)
Returns true if o is equal to this flux density.

Overrides:
equals in class Object

hashCode

public int hashCode()
Returns a hash code value for this flux density.

Overrides:
hashCode in class Object

compareTo

public int compareTo(FluxDensity otherFlux)
Compares this flux density with the otherFlux for order.

Specified by:
compareTo in interface Comparable<FluxDensity>


Copyright © 2009. All Rights Reserved.