net.lessy.util.type
Class Amount<T extends Amount<T>>

java.lang.Object
  extended by net.lessy.util.type.Amount<T>
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
Money, Percentage, Quantity

public abstract class Amount<T extends Amount<T>>
extends Object
implements Serializable

General class to represent a number. Internally a BigDecimal is used.

Author:
Hans Lesmeister
See Also:
Serialized Form

Constructor Summary
protected Amount(BigDecimal value)
           
protected Amount(BigDecimal value, int decimalPlaces)
           
 
Method Summary
 T add(Amount<T> amount)
          Add an amount to this Amount
 T createInstance(BigDecimal amount)
           
 T divideBy(Amount<T> amount)
           
 T divideBy(int amount)
           
 boolean equals(Object o)
           
 BigDecimal getValue()
           
 int hashCode()
           
 T multiplyWith(Amount<T> amount)
           
 T subtract(Amount<T> amount)
          Subtract an amount from this Amount
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Amount

protected Amount(BigDecimal value,
                 int decimalPlaces)

Amount

protected Amount(BigDecimal value)
Method Detail

getValue

public BigDecimal getValue()

subtract

public T subtract(Amount<T> amount)
Subtract an amount from this Amount

Parameters:
amount - Amount to subtract. If null, zero is subtracted
Returns:
The new amount
See Also:
BigDecimal.subtract(java.math.BigDecimal)

add

public T add(Amount<T> amount)
Add an amount to this Amount

Parameters:
amount - Amount to add. If null, zero is added
Returns:
The new amount
See Also:
BigDecimal.add(java.math.BigDecimal)

divideBy

public T divideBy(Amount<T> amount)

divideBy

public T divideBy(int amount)

multiplyWith

public T multiplyWith(Amount<T> amount)

createInstance

public final T createInstance(BigDecimal amount)

equals

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2012. All Rights Reserved.