com.twitter.common.quantity
Class Amount<T extends Number & Comparable<T>,U extends Unit<U>>

java.lang.Object
  extended by com.twitter.common.quantity.Amount<T,U>
Type Parameters:
T - the type of number the amount value is expressed in
U - the type of unit that this amount quantifies
All Implemented Interfaces:
Comparable<Amount<T,U>>

public abstract class Amount<T extends Number & Comparable<T>,U extends Unit<U>>
extends Object
implements Comparable<Amount<T,U>>

Represents a value in a unit system and facilitates unambiguous communication of amounts. Instances are created via static factory of(...) methods.


Method Summary
 T as(U unit)
           
 int compareTo(Amount<T,U> other)
           
 boolean equals(Object obj)
           
 U getUnit()
           
 T getValue()
           
 int hashCode()
           
static
<U extends Unit<U>>
Amount<Double,U>
of(double number, U unit)
          Creates an amount that uses a double value.
static
<U extends Unit<U>>
Amount<Float,U>
of(float number, U unit)
          Creates an amount that uses a float value.
static
<U extends Unit<U>>
Amount<Integer,U>
of(int number, U unit)
          Creates an amount that uses an int value.
static
<U extends Unit<U>>
Amount<Long,U>
of(long number, U unit)
          Creates an amount that uses a long value.
protected abstract  T scale(double multiplier)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getValue

public T getValue()

getUnit

public U getUnit()

as

public T as(U unit)

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

compareTo

public int compareTo(Amount<T,U> other)
Specified by:
compareTo in interface Comparable<Amount<T extends Number & Comparable<T>,U extends Unit<U>>>

scale

protected abstract T scale(double multiplier)

of

public static <U extends Unit<U>> Amount<Double,U> of(double number,
                                                      U unit)
Creates an amount that uses a double value.

Type Parameters:
U - the type of unit that the returned amount quantifies
Parameters:
number - the number of units the returned amount should quantify
unit - the unit the returned amount is expressed in terms of
Returns:
an amount quantifying the given number of units

of

public static <U extends Unit<U>> Amount<Float,U> of(float number,
                                                     U unit)
Creates an amount that uses a float value.

Type Parameters:
U - the type of unit that the returned amount quantifies
Parameters:
number - the number of units the returned amount should quantify
unit - the unit the returned amount is expressed in terms of
Returns:
an amount quantifying the given number of units

of

public static <U extends Unit<U>> Amount<Long,U> of(long number,
                                                    U unit)
Creates an amount that uses a long value.

Type Parameters:
U - the type of unit that the returned amount quantifies
Parameters:
number - the number of units the returned amount should quantify
unit - the unit the returned amount is expressed in terms of
Returns:
an amount quantifying the given number of units

of

public static <U extends Unit<U>> Amount<Integer,U> of(int number,
                                                       U unit)
Creates an amount that uses an int value.

Type Parameters:
U - the type of unit that the returned amount quantifies
Parameters:
number - the number of units the returned amount should quantify
unit - the unit the returned amount is expressed in terms of
Returns:
an amount quantifying the given number of units