JScience v3.3

javax.measure.quantities
Class Scalar<Q extends Quantity>

java.lang.Object
  extended by java.lang.Number
      extended by javax.measure.quantities.Scalar<Q>
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Quantity<Q>>, Quantity<Q>

public class Scalar<Q extends Quantity>
extends java.lang.Number
implements Quantity<Q>, java.lang.Comparable<Quantity<Q>>, java.io.Serializable

This class represents a simple quantity implementation, that is completely specified by its magnitude and has no direction.

Instances of this class are immutable

Version:
3.1, April 22, 2006
Author:
Jean-Marie Dautelle
See Also:
Serialized Form

Constructor Summary
Scalar(double amount, Unit<Q> unit)
          Creates a scalar quantity of specified amount stated in the specified unit.
 
Method Summary
 int compareTo(Quantity<Q> that)
          Compares the value of this quantity to the specified quantity value both stated using the same unit.
 double doubleValue()
          Returns the amount as a double.
 double doubleValue(Unit<Q> unit)
          Returns the estimated value of this quantity stated in the specified unit as a double.
 boolean equals(java.lang.Object that)
          Compares this scalar against the specified object.
 float floatValue()
          Returns the amount as a float.
 double getAmount()
          Returns the amount stated in this scalar quantity unit.
 Unit<Q> getUnit()
          Returns the unit used for this scalar quantity.
 int hashCode()
          Returns the hash code for this scalar.
 int intValue()
          Returns the amount as an int.
 long longValue()
          Returns the amount as a long.
 long longValue(Unit<Q> unit)
          Returns the estimated value of this quantity stated in the specified unit as a long.
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Scalar

public Scalar(double amount,
              Unit<Q> unit)
Creates a scalar quantity of specified amount stated in the specified unit.

Parameters:
amount - the quantity amount stated in the specified unit.
unit - the unit used to specified the amount
Method Detail

getAmount

public final double getAmount()
Returns the amount stated in this scalar quantity unit.

Returns:
the amount value.

getUnit

public final Unit<Q> getUnit()
Returns the unit used for this scalar quantity.

Returns:
the amount unit.

doubleValue

public final double doubleValue(Unit<Q> unit)
Description copied from interface: Quantity
Returns the estimated value of this quantity stated in the specified unit as a double.

Specified by:
doubleValue in interface Quantity<Q extends Quantity>
Parameters:
unit - the unit in which the measurement value is stated.
Returns:
the numeric value after conversion to type double.

longValue

public final long longValue(Unit<Q> unit)
                     throws java.lang.ArithmeticException
Description copied from interface: Quantity
Returns the estimated value of this quantity stated in the specified unit as a long.

Specified by:
longValue in interface Quantity<Q extends Quantity>
Parameters:
unit - the unit in which the measurement value is stated.
Returns:
the numeric value after conversion to type long.
Throws:
java.lang.ArithmeticException - if this quantity cannot be represented as a long number in the specified unit.

compareTo

public int compareTo(Quantity<Q> that)
Compares the value of this quantity to the specified quantity value both stated using the same unit.

Specified by:
compareTo in interface java.lang.Comparable<Quantity<Q extends Quantity>>
Parameters:
that - the quantity to compare with.
Returns:
negative integer, zero, or a positive integer as this quantity amount is less than, equal to, or greater than the specified quantity.

intValue

public final int intValue()
Returns the amount as an int. This may involve rounding or truncation.

Specified by:
intValue in class java.lang.Number
Returns:
the numeric value represented by this object after conversion to type int.

longValue

public final long longValue()
Returns the amount as a long. This may involve rounding or truncation.

Specified by:
longValue in class java.lang.Number
Returns:
the numeric value represented by this object after conversion to type long.

floatValue

public final float floatValue()
Returns the amount as a float. This may involve rounding.

Specified by:
floatValue in class java.lang.Number
Returns:
the numeric value represented by this object after conversion to type float.

doubleValue

public final double doubleValue()
Returns the amount as a double.

Specified by:
doubleValue in class java.lang.Number
Returns:
the numeric value represented by this object after conversion to type double.

equals

public boolean equals(java.lang.Object that)
Compares this scalar against the specified object.

Overrides:
equals in class java.lang.Object
Parameters:
that - the object to compare with.
Returns:
true if the objects are the same; false otherwise.

hashCode

public int hashCode()
Returns the hash code for this scalar.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code value.

JScience v3.3

Copyright © 2006 JScience.