case class MoneyContext(defaultCurrency: Currency, currencies: Set[Currency], rates: Seq[CurrencyExchangeRate], allowIndirectConversions: Boolean = true) extends Product with Serializable
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
- defaultCurrency
Currency used when none is supplied to the Money factory
- rates
Collection of Exchange Rates used for currency conversions
- Source
- MoneyContext.scala
- Since
0.1
- Alphabetic
- By Inheritance
- MoneyContext
- Serializable
- Product
- Equals
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new MoneyContext(defaultCurrency: Currency, currencies: Set[Currency], rates: Seq[CurrencyExchangeRate], allowIndirectConversions: Boolean = true)
- defaultCurrency
Currency used when none is supplied to the Money factory
- rates
Collection of Exchange Rates used for currency conversions
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##(): Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- 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.
- moneyA
Money A
- moneyB
Money B
- Exceptions thrown
NoSuchExchangeRateException
when no exchange rate is available
- val allowIndirectConversions: Boolean
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- 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
- moneyA
Money A
- moneyB
Money B
- Exceptions thrown
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
- money
Money to be converted
- currency
Currency to be converted to
- Exceptions thrown
NoSuchExchangeRateException
when no exchange rate is available
- val currencies: Set[Currency]
- lazy val currencyMap: Map[String, Currency]
- val defaultCurrency: Currency
- def directRateFor(curA: Currency, curB: Currency): Option[CurrencyExchangeRate]
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
- 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
- moneyA
Money A
- moneyB
Money B
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def indirectRateFor(curA: Currency, curB: Currency): Option[CurrencyExchangeRate]
Return an Option on an exchange rate.
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
- curA
Currency A
- curB
Currency B
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def productElementNames: Iterator[String]
- Definition Classes
- Product
- val rates: Seq[CurrencyExchangeRate]
- 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.
- moneyA
Money A
- moneyB
Money B
- Exceptions thrown
NoSuchExchangeRateException
when no exchange rate is available
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- 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
- MoneyContext → AnyRef → Any
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- 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
- additionalCurrencies
Set[Currency]
- def withExchangeRates(rates: List[CurrencyExchangeRate]): MoneyContext
Create a copy of this context with a new list of rates
Create a copy of this context with a new list of rates
- rates
List[CurrencyExchangeRate]