com.elasticpath.domain.misc.impl
Class MoneyImpl

java.lang.Object
  extended by com.elasticpath.domain.impl.AbstractEpDomainImpl
      extended by com.elasticpath.domain.impl.AbstractTransientImpl
          extended by com.elasticpath.domain.misc.impl.MoneyImpl
All Implemented Interfaces:
EpDomain, Money, Transient, java.io.Serializable, java.lang.Comparable

public class MoneyImpl
extends AbstractTransientImpl
implements Money

Represents an amount of money in a particular currency. This class was migrated from EP4.1 and methods should be uncommented as required.

See Also:
Serialized Form

Field Summary
static long serialVersionUID
          Serial version id.
 
Constructor Summary
MoneyImpl()
          No-arg Constructor.
MoneyImpl(java.math.BigDecimal amount, java.util.Currency currency)
          Constructor.
 
Method Summary
 Money add(Money otherMoney)
          Returns a new Money object representing the sum of this object and otherMoney's values.
 int compareTo(java.lang.Object object)
          Compares this money with the specified object for order.
 java.lang.String displaySalePercentage(Money salePrice, java.util.Locale locale)
          Creates a string to display the percentage savings at the specified sale price.
 java.lang.String displaySaleSavings(Money salePrice)
          Creates a string to display the amount saved at the specified sale price.
 boolean equals(java.lang.Object otherMoney)
          Returns true if this money object is equal to otherMoney.
 java.math.BigDecimal getAmount()
          Get the amount of money as a BigDecimal.
 java.util.Currency getCurrency()
          Get the Currency of the money.
 java.lang.String getMoneyValueAndSymbol()
          Prints the symbol of the selected currency along with the value.
 boolean greaterThan(Money otherMoney)
          Returns true if this money object is greater than the specified other money object.
 int hashCode()
          The hash code for this Money object.
 boolean lessThan(Money otherMoney)
          Returns true if this money object is less than the specified other money object.
 Money multiply(java.math.BigDecimal multiplier)
          Return a new Money object whose value is this money object's value times the specified multiplier.
 Money multiply(int multiplier)
          Return a new Money object whose value is this money object's value times the specified multiplier.
 void setCurrency(java.util.Currency currency)
          Set the Currency of the money.
 void setValue(java.math.BigDecimal amount, java.util.Currency currency)
          Set the value that this object represents.
 void setValue(float amount, java.util.Currency currency)
          Set the value that this object represents.
 Money subtract(Money otherMoney)
          Returns a new Money object representing the the amount of this object less the amount of the otherMoney object.
 java.lang.String toString()
          Returns string representation of Money objects to facilitate debugging.
 
Methods inherited from class com.elasticpath.domain.impl.AbstractEpDomainImpl
getElasticPath, setElasticPath
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.elasticpath.domain.EpDomain
getElasticPath, setElasticPath
 

Field Detail

serialVersionUID

public static final long serialVersionUID
Serial version id.

See Also:
Constant Field Values
Constructor Detail

MoneyImpl

public MoneyImpl()
No-arg Constructor.


MoneyImpl

public MoneyImpl(java.math.BigDecimal amount,
                 java.util.Currency currency)
Constructor.

Parameters:
amount - the amount of money
currency - the currency
Method Detail

add

public Money add(Money otherMoney)
Returns a new Money object representing the sum of this object and otherMoney's values.

Specified by:
add in interface Money
Parameters:
otherMoney - the Money object whose value is to be added to this object
Returns:
the new Money object representing the sum.

compareTo

public int compareTo(java.lang.Object object)
              throws EpDomainException
Compares this money with the specified object for order.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
object - the given object
Returns:
a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object.
Throws:
EpDomainException - if the given object is not a Money

displaySalePercentage

public java.lang.String displaySalePercentage(Money salePrice,
                                              java.util.Locale locale)
Creates a string to display the percentage savings at the specified sale price.

Specified by:
displaySalePercentage in interface Money
Parameters:
salePrice - the sale price
locale - the user's locale
Returns:
a string for displaying the percentage savings

displaySaleSavings

public java.lang.String displaySaleSavings(Money salePrice)
Creates a string to display the amount saved at the specified sale price.

Specified by:
displaySaleSavings in interface Money
Parameters:
salePrice - the sale price
Returns:
a string for displaying the amount saved at the given sale price

equals

public boolean equals(java.lang.Object otherMoney)
Returns true if this money object is equal to otherMoney.

Overrides:
equals in class java.lang.Object
Parameters:
otherMoney - the other money object to be compared
Returns:
true of the objects are equal

getAmount

public java.math.BigDecimal getAmount()
Get the amount of money as a BigDecimal.

Specified by:
getAmount in interface Money
Returns:
the BigDecimal amount

getCurrency

public java.util.Currency getCurrency()
Get the Currency of the money.

Specified by:
getCurrency in interface Money
Returns:
the Currency

getMoneyValueAndSymbol

public java.lang.String getMoneyValueAndSymbol()
Prints the symbol of the selected currency along with the value.

Specified by:
getMoneyValueAndSymbol in interface Money
Returns:
a string/html representation of the money value in the specified locale

greaterThan

public boolean greaterThan(Money otherMoney)
Returns true if this money object is greater than the specified other money object.

Specified by:
greaterThan in interface Money
Parameters:
otherMoney - the other money object
Returns:
true if this object is greater

hashCode

public int hashCode()
The hash code for this Money object.

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

lessThan

public boolean lessThan(Money otherMoney)
Returns true if this money object is less than the specified other money object.

Specified by:
lessThan in interface Money
Parameters:
otherMoney - the other money object
Returns:
true if this object is less

multiply

public Money multiply(java.math.BigDecimal multiplier)
Return a new Money object whose value is this money object's value times the specified multiplier.

Specified by:
multiply in interface Money
Parameters:
multiplier - the amount to multiply by
Returns:
a Money object representing the result

multiply

public Money multiply(int multiplier)
Return a new Money object whose value is this money object's value times the specified multiplier.

Specified by:
multiply in interface Money
Parameters:
multiplier - the amount to multiply by
Returns:
a Money object representing the result

setCurrency

public void setCurrency(java.util.Currency currency)
Set the Currency of the money.

Specified by:
setCurrency in interface Money
Parameters:
currency - the Currency

setValue

public void setValue(java.math.BigDecimal amount,
                     java.util.Currency currency)
Set the value that this object represents.

Specified by:
setValue in interface Money
Parameters:
amount - the amount of money as a BigDecimal
currency - the money's currency

setValue

public void setValue(float amount,
                     java.util.Currency currency)
Set the value that this object represents.

Specified by:
setValue in interface Money
Parameters:
amount - the amount of money as a float
currency - the money's currency

subtract

public Money subtract(Money otherMoney)
Returns a new Money object representing the the amount of this object less the amount of the otherMoney object.

Specified by:
subtract in interface Money
Parameters:
otherMoney - the Money object whose value is to be subtracted from this object
Returns:
the new Money object representing this value less the other object's value.

toString

public java.lang.String toString()
Returns string representation of Money objects to facilitate debugging.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the Money ojbect