org.jscience.economics.money
Class MoneyAmount

Object
  extended by Measure<Q>
      extended by Amount<Decimal,Money>
          extended by MoneyAmount
All Implemented Interfaces:
Serializable, Comparable<Measurable<Money>>, Measurable<Money>, Immutable, Realtime, ValueType, XMLSerializable, Field<Amount<Decimal,?>>, GroupAdditive<Amount<Decimal,?>>, GroupMultiplicative<Amount<Decimal,?>>, Ring<Amount<Decimal,?>>, Structure<Amount<Decimal,?>>

public class MoneyAmount
extends Amount<Decimal,Money>

This class represents an amount of money specified in a given Currency (convenience method).

Version:
5.0, January 2, 2010
Author:
Jean-Marie Dautelle
See Also:
Serialized Form

Field Summary
 
Fields inherited from class Amount
TEXT_FORMAT, XML_FORMAT
 
Constructor Summary
MoneyAmount(Decimal value, Currency unit)
          Creates a money amount always on the heap independently from the current allocator context.
 
Method Summary
 MoneyAmount copy()
          Returns a copy of this amount (allocated in the current context).
 Amount<Decimal,?> divide(Amount<Decimal,?> that)
          Returns this amount divided by the one specified.
 MoneyAmount divide(long n)
          Returns this amount divided by the specified divisor.
 Currency getUnit()
          Returns this amount unit.
 Decimal getValue()
          Returns this amount numeric value.
 Amount<Decimal,?> inverse()
          Returns the reciprocal of this amount.
 MoneyAmount minus(Amount<Decimal,?> that)
          Returns the difference between this amount and the one specified.
 MoneyAmount opposite()
          Returns the opposite of this amount.
 MoneyAmount plus(Amount<Decimal,?> that)
          Returns the sum of this amount with the one specified.
 Amount<Decimal,?> pow(int exp)
          Returns this amount raised at the specified exponent.
 Amount<Decimal,?> times(Amount<Decimal,?> that)
          Returns the product of this amount with the one specified.
 MoneyAmount times(long n)
          Returns this amount multiplied by the specified factor.
 String toStringLocale()
          Overrides the default Measure.toStringLocale() to show only the currency fraction digits of the associated currency (e.g.
static MoneyAmount valueOf(Amount<?,Money> amount)
          Returns the money amount corresponding to the specified generic amount.
static MoneyAmount valueOf(Decimal value, Currency currency)
          Returns the money amount corresponding to the specified decimal value and currency.
static MoneyAmount valueOf(long value, int cents, Currency currency)
          Returns the money amount corresponding to the specified value and cents.
 
Methods inherited from class Amount
asFloat64, asType, decimalValue, doubleValue, to, to, toSI, toString, toText, valueOf, valueOf, valueOf
 
Methods inherited from class Measure
compareTo, equals, equals, floatValue, hashCode, intValue, longValue, round
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MoneyAmount

public MoneyAmount(Decimal value,
                   Currency unit)
Creates a money amount always on the heap independently from the current allocator context. To allow for custom object allocation policies, static factory methods valueOf(...) are recommended.

Parameters:
value - the value stated in the specified currency.
currency - the currency in which the value is stated.
Method Detail

valueOf

public static MoneyAmount valueOf(Decimal value,
                                  Currency currency)
Returns the money amount corresponding to the specified decimal value and currency.

Parameters:
value - the value stated in the specified currency.
currency - the currency in which the value is stated.
Returns:
the corresponding amount.

valueOf

public static MoneyAmount valueOf(long value,
                                  int cents,
                                  Currency currency)
Returns the money amount corresponding to the specified value and cents.

Parameters:
value - the integer value in the specified currency.
cents - the cents value in the specified currency.
currency - the currency in which the value and cents are stated.
Returns:
the corresponding amount.

valueOf

public static MoneyAmount valueOf(Amount<?,Money> amount)
Returns the money amount corresponding to the specified generic amount.

Parameters:
amount - the raw amount.
Returns:
the corresponding money amount stated in an existing Currency.
Throws:
ClassCastException - if the SI unit of the specified amount is not a Currency.

toStringLocale

public String toStringLocale()
Overrides the default Measure.toStringLocale() to show only the currency fraction digits of the associated currency (e.g. rounding to closest cents).

Overrides:
toStringLocale in class Measure<Money>
Returns:
the string representation of this money amount.

getValue

public Decimal getValue()
Description copied from class: Amount
Returns this amount numeric value.

Specified by:
getValue in class Amount<Decimal,Money>
Returns:
this amount value.

getUnit

public Currency getUnit()
Description copied from class: Amount
Returns this amount unit.

Specified by:
getUnit in class Amount<Decimal,Money>
Returns:
this amount unit.

opposite

public MoneyAmount opposite()
Description copied from class: Amount
Returns the opposite of this amount.

Specified by:
opposite in interface GroupAdditive<Amount<Decimal,?>>
Specified by:
opposite in class Amount<Decimal,Money>
Returns:
-this.

plus

public MoneyAmount plus(Amount<Decimal,?> that)
Description copied from class: Amount
Returns the sum of this amount with the one specified.

Specified by:
plus in interface GroupAdditive<Amount<Decimal,?>>
Specified by:
plus in class Amount<Decimal,Money>
Parameters:
that - the amount to be added.
Returns:
this + that.

minus

public MoneyAmount minus(Amount<Decimal,?> that)
Description copied from class: Amount
Returns the difference between this amount and the one specified.

Overrides:
minus in class Amount<Decimal,Money>
Parameters:
that - the number to be subtracted.
Returns:
this - that.

times

public MoneyAmount times(long n)
Description copied from class: Amount
Returns this amount multiplied by the specified factor.

Specified by:
times in class Amount<Decimal,Money>
Parameters:
n - the factor multiplier.
Returns:
this * n.

times

public Amount<Decimal,?> times(Amount<Decimal,?> that)
Description copied from class: Amount
Returns the product of this amount with the one specified.

Specified by:
times in interface GroupMultiplicative<Amount<Decimal,?>>
Specified by:
times in interface Ring<Amount<Decimal,?>>
Specified by:
times in class Amount<Decimal,Money>
Parameters:
that - the number multiplier.
Returns:
this ยท that.

pow

public Amount<Decimal,?> pow(int exp)
Description copied from class: Amount
Returns this amount raised at the specified exponent.

Specified by:
pow in class Amount<Decimal,Money>
Parameters:
exp - the exponent.
Returns:
thisexp

inverse

public Amount<Decimal,?> inverse()
Description copied from class: Amount
Returns the reciprocal of this amount.

Specified by:
inverse in interface GroupMultiplicative<Amount<Decimal,?>>
Specified by:
inverse in class Amount<Decimal,Money>
Returns:
1 / this.

divide

public MoneyAmount divide(long n)
Description copied from class: Amount
Returns this amount divided by the specified divisor.

Specified by:
divide in class Amount<Decimal,Money>
Parameters:
n - the divisor.
Returns:
this / n.

divide

public Amount<Decimal,?> divide(Amount<Decimal,?> that)
Description copied from class: Amount
Returns this amount divided by the one specified.

Specified by:
divide in class Amount<Decimal,Money>
Parameters:
that - the amount divisor.
Returns:
this / that.

copy

public MoneyAmount copy()
Description copied from class: Amount
Returns a copy of this amount (allocated in the current context).

Specified by:
copy in interface ValueType
Specified by:
copy in class Amount<Decimal,Money>
Returns:
a deep copy of this.


Copyright © 2005-2010 JScience. All Rights Reserved.