MoneyContext

case class MoneyContext(defaultCurrency: Currency, currencies: Set[Currency], rates: Seq[CurrencyExchangeRate], allowIndirectConversions: Boolean)

MoneyContext

MoneyContext

Provides a context for Money specific operations.

When provided as an implicit parameter, the defaultCurrency will be used by the Money factory when no other currency is provided.

Provides for cross-currency conversions.

Will act as an implicit parameter to cross currency operations to allow for easy conversions

Value Params
defaultCurrency

Currency used when none is supplied to the Money factory

rates

Collection of Exchange Rates used for currency conversions

Authors

garyKeorkunian

Since

0.1

trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any

Value members

Concrete methods

def add(moneyA: Money, moneyB: Money): Money

Adds two money values that may or may not be in the same currency.

Adds two money values that may or may not be in the same currency.

The result will be in the same currency as the first parameter.

Value Params
moneyA

Money A

moneyB

Money B

Throws
NoSuchExchangeRateException

when no exchange rate is available

def compare(moneyA: Money, moneyB: Money): Int

Performs a standard compare on two money values that may or may not be in the same currency

Performs a standard compare on two money values that may or may not be in the same currency

Value Params
moneyA

Money A

moneyB

Money B

Throws
NoSuchExchangeRateException

when no exchange rate is available

def convert(money: Money, currency: Currency): Money

Converts a Money value to the specified currency.

Converts a Money value to the specified currency.

The conversion first attempts to use an existing exchange rate for the two currencies in question. If no direct exchange works, a cross rate (limited to 1 hop) will be calculated and used. If no cross rate can be calculated a NoSuchElementException is thrown

Value Params
currency

Currency to be converted to

money

Money to be converted

Throws
NoSuchExchangeRateException

when no exchange rate is available

Returns an Option on an exchange rate if a direct rate exists, otherwise None

Returns an Option on an exchange rate if a direct rate exists, otherwise None

Value Params
curA

Currency A

curB

Currency B

def divide(moneyA: Money, moneyB: Money): BigDecimal

Divides two money value that may or may not be in the same currency after converting the second to the first

Divides two money value that may or may not be in the same currency after converting the second to the first

Value Params
moneyA

Money A

moneyB

Money B

Return an Option on an exchange rate. If a direct rate exists an Option on that will be returned. Otherwise, if a cross rate can be determined (1 hop limit), it will be created and returned in an Option. Otherwise, None will be returned

Return an Option on an exchange rate. If a direct rate exists an Option on that will be returned. Otherwise, if a cross rate can be determined (1 hop limit), it will be created and returned in an Option. Otherwise, None will be returned

Value Params
curA

Currency A

curB

Currency B

def subtract(moneyA: Money, moneyB: Money): Money

Subtracts two money values that may or may not be in the same currency

Subtracts two money values that may or may not be in the same currency

The result will be in the same currency as the first parameter.

Value Params
moneyA

Money A

moneyB

Money B

Throws
NoSuchExchangeRateException

when no exchange rate is available

override def toString: String

Custom implementation using SortedSets to ensure consistent output

Custom implementation using SortedSets to ensure consistent output

Returns

String representation of this instance

Definition Classes
Any
def withAdditionalCurrencies(additionalCurrencies: Set[Currency]): MoneyContext

Create a copy of this context with additional currencies added to the existing set

Create a copy of this context with additional currencies added to the existing set

Value Params
additionalCurrencies

Set[Currency]

Create a copy of this context with a new list of rates

Create a copy of this context with a new list of rates

Value Params
rates

List[CurrencyExchangeRate]

Inherited methods

def productElementNames: Iterator[String]
Inherited from
Product
def productIterator: Iterator[Any]
Inherited from
Product

Concrete fields

lazy val currencyMap: Map[String, Currency]