Packages

  • package root
    Definition Classes
    root
  • package squants

    The Scala API for Quantities, Units of Measure and Dimensional Analysis

    Squants

    The Scala API for Quantities, Units of Measure and Dimensional Analysis

    Overview

    Squants is a framework of data types and a domain specific language (DSL) for representing Quantities, their Units of Measure, and their Dimensional relationships. The API supports typesafe dimensional analysis, improved domain models and more. All types are immutable and thread-safe.

    Typedefs and implicits for common usages

    Definition Classes
    root
    Version

    0.1

    Since

    0.1

  • package market

    Squants Market API

    Squants Market API

    Market Types are similar but not quite the same as other quantities in the library.

    The primary type, squants.market.Money, is derived from Quantity, and its Units of Measure are Currencies. However, because the conversion multipliers between units can not be predefined, many of the behaviors have been overridden and augmented to realize correct behavior.

    squants.market.Prices represent a Ratio between Money and some other Quantity. Prices can be created from ratios of Money and a Quantity

    val money: Money = USD(10)
    val length: Length = Meters(1)
    val price: Price[Length] = money / length

    Multiplying a Price * Quantity will yield Money amount that represents the cost of the quantity

    val cost: Money = price * Meters(3.8)

    and multiplying Price * Money will yield the corresponding Quantity amount

    val budget: Money = USD(250)
    val quote: Length = price * budget

    squants.market.CurrencyExchangeRates represent conversion rates between currencies. Use them to explicitly convert Money values in one currency to values in another.

    squants.market.MoneyContext provide the implicit context necessary to perform cross-currency operations on Money values with conversions automatically applied.

    Some binary math operations will work on Moneys of like Currency with no MoneyContext in scope. Attempts to perform these operations on Moneys of dissimilar currencies will throw an exception at runtime.

    Other operations, including direct conversions to other currencies, require a MoneyContext and will not compile without it. However, there is no compile time check to determine if the correct exchange rates will be available at runtime. Operation requiring conversion without the required rates available will throw a NoSuchExchangeRateException at runtime.

    The defaultMoneyContext uses the USD as the default and provides a list of ~20 common currencies, and NO exchange rates. If your application requires something different you should initialize your own implicit MoneyContext

    Definition Classes
    squants
    Since

    0.1

  • ARS
  • AUD
  • BRL
  • BTC
  • CAD
  • CHF
  • CLP
  • CNY
  • CZK
  • Currency
  • CurrencyExchangeRate
  • DKK
  • ETH
  • EUR
  • GBP
  • HKD
  • INR
  • JPY
  • KRW
  • LTC
  • MXN
  • MYR
  • Money
  • MoneyContext
  • MoneyConversions
  • NAD
  • NOK
  • NZD
  • NoSuchCurrencyException
  • NoSuchExchangeRateException
  • Price
  • RUB
  • SEK
  • USD
  • XAG
  • XAU
  • ZAR
c

squants.market

MoneyContext

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

Linear Supertypes
Serializable, Product, Equals, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. MoneyContext
  2. Serializable
  3. Product
  4. Equals
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. 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

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. 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

  5. val allowIndirectConversions: Boolean
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  8. 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

  9. 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

  10. val currencies: Set[Currency]
  11. lazy val currencyMap: Map[String, Currency]
  12. val defaultCurrency: Currency
  13. 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

  14. 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

  15. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  16. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  17. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  18. 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

  19. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  20. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  21. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  22. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  23. def productElementNames: Iterator[String]
    Definition Classes
    Product
  24. val rates: Seq[CurrencyExchangeRate]
  25. 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

  26. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  27. 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
  28. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  29. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  30. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  31. 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]

  32. 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]

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Ungrouped