edu.nrao.sss.measure
Class LinearVelocity

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

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

A measure of linear velocity.

Version Info:

$Revision: 1707 $
$Date $
$Author: dharland $

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

Constructor Summary
LinearVelocity()
          Creates a new linear velocity of zero kilometers per second.
LinearVelocity(BigDecimal kms)
          Creates a new velocity of kms kilometers per second.
LinearVelocity(BigDecimal value, LinearVelocityUnits units)
          Creates a new linear velocity with the given magnitude and units.
LinearVelocity(String kms)
          Creates a new velocity of kms kilometers per second.
LinearVelocity(String value, LinearVelocityUnits units)
          Creates a new linear velocity with the given magnitude and units.
 
Method Summary
 LinearVelocity add(LinearVelocity other)
          Adds other linear velocity to this one.
 LinearVelocity clone()
          Returns a linear velocity that is equal to this one.
 int compareTo(LinearVelocity otherVel)
          Compares this linear velocity with the otherVel for order.
 LinearVelocity convertTo(LinearVelocityUnits newUnits)
          Converts this measure of linear velocity to the new units.
 LinearVelocity divideBy(BigDecimal divisor)
          Divides this velocity by divisor.
 boolean equals(Object o)
          Returns true if o is equal to this linear velocity.
 LinearVelocityUnits getUnits()
          Returns the units of this linear velocity.
 BigDecimal getValue()
          Returns the magnitude of this linear velocity.
 int hashCode()
          Returns a hash code value for this linear velocity.
 boolean isInDefaultState()
          Returns true if this velocity is in its default state, no matter how it got there.
 boolean isInfinite()
          Returns true if this velocity is infinite.
 LinearVelocity multiplyBy(BigDecimal multiplier)
          Multiplies this velocity by multiplier.
static LinearVelocity parse(String velocityString)
          Returns a new velocity based on velocityString.
 void reset()
          Resets this linear velocity so that it is equal to one created via the no-argument constructor.
 void set(BigDecimal value, LinearVelocityUnits units)
          Sets the magnitude and units of this linear velocity.
 void set(String velocityText)
          Sets the value and units of this velocity based on velocityText.
 void set(String value, LinearVelocityUnits units)
          Sets the magnitude and units of this linear velocity.
 void setUnits(LinearVelocityUnits newUnits)
          Sets the units of this linear velocity to newUnits.
 void setValue(BigDecimal newValue)
          Sets the magnitude of this linear velocity to newValue.
 void setValue(String newValue)
          Sets the magnitude of this linear velocity to newValue.
 LinearVelocity subtract(LinearVelocity other)
          Subtracts other linear velocity from this one.
 String toString()
          Returns a text representation of this linear velocity.
 String toString(int minFracDigits, int maxFracDigits)
          Returns a text representation of this velocity.
 BigDecimal toUnits(LinearVelocityUnits otherUnits)
          Returns the magnitude of this linear velocity in otherUnits.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LinearVelocity

public LinearVelocity()
Creates a new linear velocity of zero kilometers per second.


LinearVelocity

public LinearVelocity(BigDecimal kms)
Creates a new velocity of kms kilometers per second. See setValue(BigDecimal) for information about valid parameter values and exceptions that might be thrown.

Parameters:
kms - the magnitude of this velocity in kilometers per second.

LinearVelocity

public LinearVelocity(String kms)
Creates a new velocity of kms kilometers per second. See setValue(BigDecimal) for information about valid parameter values and exceptions that might be thrown.

Parameters:
kms - the magnitude of this velocity in kilometers per second.

LinearVelocity

public LinearVelocity(BigDecimal value,
                      LinearVelocityUnits units)
Creates a new linear velocity with the given magnitude and units. See set(BigDecimal, LinearVelocityUnits) for information about valid parameter values and exceptions that might be thrown.

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

LinearVelocity

public LinearVelocity(String value,
                      LinearVelocityUnits units)
Creates a new linear velocity with the given magnitude and units. See set(BigDecimal, LinearVelocityUnits) for information about valid parameter values and exceptions that might be thrown.

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

reset

public void reset()
Resets this linear velocity so that it is equal to one created via the no-argument constructor.


getValue

public BigDecimal getValue()
Returns the magnitude of this linear velocity.

Returns:
the magnitude of this linear velocity.

getUnits

public LinearVelocityUnits getUnits()
Returns the units of this linear velocity.

Returns:
the units of this linear velocity.

set

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

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

Parameters:
velocityText - a string that will be converted into a velocity.
Throws:
IllegalArgumentException - if velocityText is not in the expected form.
Since:
2008-09-22

set

public final void set(BigDecimal value,
                      LinearVelocityUnits units)
Sets the magnitude and units of this linear velocity.

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

Parameters:
value - the new magnitude of this linear velocity.
units - the units in which value is expressed.

set

public final void set(String value,
                      LinearVelocityUnits units)
Sets the magnitude and units of this linear velocity.

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

Parameters:
value - the new magnitude of this linear velocity.
units - the units in which value is expressed.

setValue

public final void setValue(BigDecimal newValue)
Sets the magnitude of this linear velocity to newValue.

Note that the units of this velocity are unaffected by this method.

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

setValue

public final void setValue(String newValue)
Sets the magnitude of this linear velocity to newValue.

Note that the units of this velocity are unaffected by this method.

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

setUnits

public final void setUnits(LinearVelocityUnits newUnits)
Sets the units of this linear velocity to newUnits.

Note that the value of this linear velocity is unaffected by this method. Contrast this with convertTo(LinearVelocityUnits).

Parameters:
newUnits - the new units for this linear velocity. If newUnits is null it will be treated as a default type.

isInDefaultState

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

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

Returns:
true if this velocity is in its default state.

isInfinite

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

Returns:
true if this velocity is infinite.

convertTo

public LinearVelocity convertTo(LinearVelocityUnits newUnits)
Converts this measure of linear velocity to the new units.

After this method is complete this linear velocity will have units of newUnits and its value will have been converted accordingly.

Parameters:
newUnits - the new units for this linear velocity. If newUnits is null an IllegalArgumentException will be thrown.
Returns:
this linear velocity. The reason for this return type is to allow code of this nature: double kms = myLinearVelocity.convertTo( LinearVelocityUnits.KILOMETERS_PER_SECOND).getValue();

toUnits

public BigDecimal toUnits(LinearVelocityUnits otherUnits)
Returns the magnitude of this linear velocity in otherUnits.

Note that this method does not alter the state of this linear velocity. Contrast this with convertTo(LinearVelocityUnits).

Parameters:
otherUnits - the units in which to express this linear velocity's magnitude.
Returns:
this linear velocity's value converted to otherUnits.
Throws:
IllegalArgumentException - if otherUnits is null.

add

public LinearVelocity add(LinearVelocity other)
Adds other linear velocity to this one.

Parameters:
other - the linear velocity to be added to this linear velocity.
Returns:
this linear velocity, after the addition.

subtract

public LinearVelocity subtract(LinearVelocity other)
Subtracts other linear velocity from this one.

Parameters:
other - the linear velocity to be subtracted from this angular velocity.
Returns:
this linear velocity, after the subtraction.

multiplyBy

public LinearVelocity multiplyBy(BigDecimal multiplier)
Multiplies this velocity by multiplier.

Parameters:
multiplier - the number by which this velocity should be multiplied.
Returns:
this velocity, after the multiplication.

divideBy

public LinearVelocity divideBy(BigDecimal divisor)
Divides this velocity by divisor.

Parameters:
divisor - the number by which this velocity should be divided.
Returns:
this velocity, after the division.

parse

public static LinearVelocity parse(String velocityString)
Returns a new velocity based on velocityString.

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 km/s.

Format Two: wRwSw.

Parameters:
velocityString - a string that will be converted into a velocity.
Returns:
a new velocity.
Throws:
IllegalArgumentException - if velocityString is not in the expected form.

toString

public String toString()
Returns a text representation of this linear velocity.

Overrides:
toString in class Object

toString

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

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

clone

public LinearVelocity clone()
Returns a linear velocity 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 linear velocity.

Overrides:
equals in class Object

hashCode

public int hashCode()
Returns a hash code value for this linear velocity.

Overrides:
hashCode in class Object

compareTo

public int compareTo(LinearVelocity otherVel)
Compares this linear velocity with the otherVel for order.

Specified by:
compareTo in interface Comparable<LinearVelocity>


Copyright © 2009. All Rights Reserved.