net.commerce.zocalo.currency
Class Quantity

java.lang.Object
  extended by net.commerce.zocalo.currency.Quantity
All Implemented Interfaces:
java.lang.Comparable
Direct Known Subclasses:
RangedQuantity

public class Quantity
extends java.lang.Object
implements java.lang.Comparable

Quantities represent numbers using BigDecimal. They carry a MathContext for computations. Subclasses represent Price and Probability by limiting the range of possible values and being able to scale.


Field Summary
static Quantity EPSILON
           
static java.math.MathContext NINE_DIGITS
           
static Quantity ONE
           
static Quantity Q100
           
protected  java.math.BigDecimal quant
           
static java.math.MathContext ROUNDING_CONTEXT
           
static Quantity ZERO
           
 
Constructor Summary
Quantity()
          Deprecated.  
Quantity(java.math.BigDecimal q)
           
Quantity(double q)
           
Quantity(java.lang.String q)
           
 
Method Summary
 Quantity abs()
           
 Quantity absLog()
           
 boolean approaches(Quantity quantity)
           
 Quantity asQuantity()
           
 java.math.BigDecimal asValue()
           
 int compareTo(java.lang.Object o)
           
 int compareTo(Quantity quantity)
           
 Quantity div(int q)
           
 Quantity div(Quantity q)
           
 boolean eq(Quantity q)
           
 boolean equals(java.lang.Object o)
           
 Quantity exp()
           
 Quantity floor()
           
 long getId()
          Deprecated.  
 java.math.BigDecimal getQuant()
          Deprecated.  
 int hashCode()
           
 boolean isNegative()
           
 boolean isNegligible()
           
 boolean isNonNegative()
           
 boolean isPositive()
           
 boolean isZero()
           
 Quantity max(Quantity other)
           
 Quantity min(Quantity other)
           
 Quantity minus(Quantity q)
           
 Quantity movePointLeft(int i)
           
 Quantity negate()
           
 Quantity newScale(int scale)
           
 Quantity plus(Quantity value)
           
 java.lang.String printAsDetailedQuantity()
           
 java.lang.String printAsDollars()
           
 java.lang.String printAsIntegerQuantity()
           
 java.lang.String printAsQuantity()
           
 java.lang.String printAsScore()
           
 Quantity remainder(Quantity dividend)
           
 Quantity round()
           
 Quantity round(java.math.MathContext c)
           
 Quantity roundFloor()
           
 Quantity scale(int scale)
           
 void setId(long id)
          Deprecated.  
 void setQuant(java.math.BigDecimal quant)
          Deprecated.  
 Quantity simplify()
           
 Quantity times(Quantity q)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NINE_DIGITS

public static final java.math.MathContext NINE_DIGITS

ROUNDING_CONTEXT

public static final java.math.MathContext ROUNDING_CONTEXT

ZERO

public static final Quantity ZERO

EPSILON

public static final Quantity EPSILON

ONE

public static final Quantity ONE

Q100

public static final Quantity Q100

quant

protected java.math.BigDecimal quant
Constructor Detail

Quantity

public Quantity(java.lang.String q)

Quantity

public Quantity(java.math.BigDecimal q)

Quantity

public Quantity(double q)

Quantity

public Quantity()
Deprecated. 

Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

printAsQuantity

public java.lang.String printAsQuantity()

printAsDetailedQuantity

public java.lang.String printAsDetailedQuantity()

printAsIntegerQuantity

public java.lang.String printAsIntegerQuantity()

printAsScore

public java.lang.String printAsScore()

printAsDollars

public java.lang.String printAsDollars()

asValue

public java.math.BigDecimal asValue()

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

div

public Quantity div(Quantity q)

div

public Quantity div(int q)

minus

public Quantity minus(Quantity q)

times

public Quantity times(Quantity q)

eq

public boolean eq(Quantity q)

absLog

public Quantity absLog()

approaches

public boolean approaches(Quantity quantity)

compareTo

public int compareTo(java.lang.Object o)
Specified by:
compareTo in interface java.lang.Comparable

compareTo

public int compareTo(Quantity quantity)

abs

public Quantity abs()

exp

public Quantity exp()

round

public Quantity round(java.math.MathContext c)

round

public Quantity round()

remainder

public Quantity remainder(Quantity dividend)

plus

public Quantity plus(Quantity value)

min

public Quantity min(Quantity other)

max

public Quantity max(Quantity other)

isPositive

public boolean isPositive()

isZero

public boolean isZero()

isNegative

public boolean isNegative()

isNonNegative

public boolean isNonNegative()

negate

public Quantity negate()

isNegligible

public boolean isNegligible()

scale

public Quantity scale(int scale)

movePointLeft

public Quantity movePointLeft(int i)

newScale

public Quantity newScale(int scale)

getQuant

public java.math.BigDecimal getQuant()
Deprecated. 


setQuant

public void setQuant(java.math.BigDecimal quant)
Deprecated. 


getId

public long getId()
Deprecated. 


setId

public void setId(long id)
Deprecated. 


asQuantity

public Quantity asQuantity()

simplify

public Quantity simplify()

roundFloor

public Quantity roundFloor()

floor

public Quantity floor()