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 electro

    Definition Classes
    squants
    Since

    0.1

  • package energy

    Definition Classes
    squants
    Since

    0.1

  • package experimental
    Definition Classes
    squants
  • package information
    Definition Classes
    squants
  • 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

  • package mass

    Definition Classes
    squants
    Since

    0.1

  • package motion

    Definition Classes
    squants
    Since

    0.1

  • package photo

    Definition Classes
    squants
    Since

    0.1

  • package radio

    Definition Classes
    squants
    Since

    0.1

  • package space

    Definition Classes
    squants
    Since

    0.1

  • package thermal

    Definition Classes
    squants
    Since

    0.1

  • package time

    Definition Classes
    squants
    Since

    0.1

  • AbstractQuantityNumeric
  • BaseDimension
  • BinarySystem
  • Dimension
  • Dimensionless
  • DimensionlessConversions
  • DimensionlessUnit
  • DoubleVector
  • Dozen
  • Each
  • Gross
  • LikeRatio
  • MetricSystem
  • Percent
  • Platform
  • PrimaryUnit
  • Quantity
  • QuantityParseException
  • QuantityRange
  • QuantityVector
  • Ratio
  • SVector
  • Score
  • SiBaseUnit
  • SiUnit
  • SquantifiedBigDecimal
  • SquantifiedDouble
  • SquantifiedInt
  • SquantifiedLong
  • UnitConverter
  • UnitOfMeasure
c

squants

Quantity

abstract class Quantity[A <: Quantity[A]] extends Serializable with Ordered[A]

Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Quantity
  2. Ordered
  3. Comparable
  4. Serializable
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new Quantity()

Abstract Value Members

  1. abstract def dimension: Dimension[A]

    The Dimension this quantity represents

  2. abstract def unit: UnitOfMeasure[A]

    The Unit of Measure the value represents

    The Unit of Measure the value represents

    returns

    UnitOfMeasure[A]

  3. abstract def value: Double

    The value of the quantity given the unit

    The value of the quantity given the unit

    returns

    Double

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. def %(that: A): Double
  4. def %(that: Double): A
  5. def *(that: Price[A]): Money
  6. def *(that: Double): A
  7. def +(that: A): A
  8. def +-(that: A): QuantityRange[A]
  9. def -(that: A): A
  10. def /(that: A): Double
  11. def /(that: Double): A
  12. def /%(that: A): (Double, A)
  13. def /%(that: Double): (A, A)
  14. def <(that: A): Boolean
    Definition Classes
    Ordered
  15. def <=(that: A): Boolean
    Definition Classes
    Ordered
  16. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  17. def =~(that: A)(implicit tolerance: A): Boolean

    approx

  18. def >(that: A): Boolean
    Definition Classes
    Ordered
  19. def >=(that: A): Boolean
    Definition Classes
    Ordered
  20. def abs: A

    Returns the absolute value of this Quantity

    Returns the absolute value of this Quantity

    returns

    Quantity

  21. def approx(that: A)(implicit tolerance: A): Boolean

    Returns boolean result of approximate equality comparison

    Returns boolean result of approximate equality comparison

    that

    Quantity

    tolerance

    Quantity

  22. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  23. def ceil: A

    Returns the smallest (closest to negative infinity) Quantity value that is greater than or equal to the argument and is equal to a mathematical integer.

    Returns the smallest (closest to negative infinity) Quantity value that is greater than or equal to the argument and is equal to a mathematical integer.

    returns

    Quantity

    See also

    java.lang.Math#ceil(double)

  24. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  25. def compare(that: A): Int

    Implements Ordered.compare

    Implements Ordered.compare

    that

    Quantity

    returns

    Int

    Definition Classes
    Quantity → Ordered
  26. def compareTo(that: A): Int
    Definition Classes
    Ordered → Comparable
  27. def divide(that: A): Double

    Divide this quantity by a like quantity

    Divide this quantity by a like quantity

    that

    Quantity

    returns

    Double

  28. def divide(that: Double): A

    Divide this quantity by some number

    Divide this quantity by some number

    that

    Double

    returns

    Quantity

  29. def divideAndRemainder(that: A): (Double, A)

    Returns a Pair that includes the result of divideToInteger and remainder

    Returns a Pair that includes the result of divideToInteger and remainder

    that

    Quantity

    returns

    (Double, Quantity)

  30. def divideAndRemainder(that: Double): (A, A)

    Returns a Pair that includes the result of divideToInteger and remainder

    Returns a Pair that includes the result of divideToInteger and remainder

    that

    Double

    returns

    (Quantity, Quantity)

  31. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  32. def equals(that: Any): Boolean

    Override of equals method

    Override of equals method

    that

    must be of matching value and unit

    Definition Classes
    Quantity → AnyRef → Any
  33. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  34. def floor: A

    Returns the largest (closest to positive infinity) Quantity value that is less than or equal to the argument and is equal to a mathematical integer

    Returns the largest (closest to positive infinity) Quantity value that is less than or equal to the argument and is equal to a mathematical integer

    returns

    Quantity

    See also

    java.lang.Math#floor(double)

  35. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  36. def hashCode(): Int

    Override of hashCode

    Override of hashCode

    Definition Classes
    Quantity → AnyRef → Any
  37. def in(uom: UnitOfMeasure[A]): A

    Returns an equivalent Quantity boxed with the supplied Unit

    Returns an equivalent Quantity boxed with the supplied Unit

    uom

    UnitOfMeasure[A]

    returns

    Quantity

  38. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  39. def map(f: (Double) => Double): A

    Applies a function to the underlying value of the Quantity, returning a new Quantity in the same unit

    Applies a function to the underlying value of the Quantity, returning a new Quantity in the same unit

    f

    Double => Double function

  40. def max(that: A): A

    Returns the max of this and that Quantity

    Returns the max of this and that Quantity

    that

    Quantity

    returns

    Quantity

  41. def min(that: A): A

    Returns the min of this and that Quantity

    Returns the min of this and that Quantity

    that

    Quantity

    returns

    Quantity

  42. def minus(that: A): A

    Subtract two like quantities

    Subtract two like quantities

    that

    Quantity

    returns

    Quantity

  43. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  44. def negate: A

    Returns the negative value of this Quantity

    Returns the negative value of this Quantity

    returns

    Quantity

  45. def notWithin(range: QuantityRange[A]): Boolean

    Returns true if this value is not within (contains) the range

    Returns true if this value is not within (contains) the range

    range

    QuantityRange

    returns

    Boolean

  46. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  47. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  48. def plus(that: A): A

    Add two like quantities

    Add two like quantities

    that

    Quantity

    returns

    Quantity

  49. def plusOrMinus(that: A): QuantityRange[A]

    Returns a QuantityRange representing the range for this value +- that

    Returns a QuantityRange representing the range for this value +- that

    that

    Quantity

    returns

    QuantityRange

  50. def remainder(that: A): Double

    Returns the remainder of a division by a like quantity

    Returns the remainder of a division by a like quantity

    that

    Quantity

    returns

    Double

  51. def remainder(that: Double): A

    Returns the remainder of a division by a number

    Returns the remainder of a division by a number

    that

    Quantity

    returns

    Quantity

  52. def rint: A

    Returns the Quantity value that is closest in value to the argument and is equal to a mathematical integer.

    Returns the Quantity value that is closest in value to the argument and is equal to a mathematical integer.

    returns

    Quantity

    See also

    java.lang.Math#rint(double)

  53. def rounded(scale: Int, mode: RoundingMode = RoundingMode.HALF_EVEN): A

    Returns the Quantity with its coefficient value rounded using scale and mode.

    Returns the Quantity with its coefficient value rounded using scale and mode. The unit is maintained.

    scale

    Int - scale of the value to be returned

    mode

    RoundingMode - defaults to HALF_EVEN

    returns

    Quantity

  54. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  55. def times(that: Double): A

    Multiply this quantity by some number

    Multiply this quantity by some number

    that

    Double

    returns

    Quantity

  56. def to(uom: UnitOfMeasure[A]): Double

    Returns a Double representing the quantity in terms of the supplied unit

    Returns a Double representing the quantity in terms of the supplied unit

    val d = Feet(3)
    (d to Inches) should be(36)
    uom

    UnitOfMeasure[A]

    returns

    Double

  57. def to(that: A): QuantityRange[A]

    Returns a QuantityRange that goes from this to that

    Returns a QuantityRange that goes from this to that

    that

    Quantity

    returns

    QuantityRange

  58. def toString(uom: UnitOfMeasure[A], format: String): String

    Returns a string representing the quantity's value in the given unit in the given format

    Returns a string representing the quantity's value in the given unit in the given format

    uom

    UnitOfMeasure[A] with UnitConverter

    format

    String containing the format for the value (ie "%.3f")

    returns

    String

  59. def toString(uom: UnitOfMeasure[A]): String

    Returns a string representing the quantity's value in the given unit

    Returns a string representing the quantity's value in the given unit

    uom

    UnitOfMeasure[A] with UnitConverter

    returns

    String

  60. def toString(): String

    Returns a string representing the quantity's value in unit

    Returns a string representing the quantity's value in unit

    returns

    String

    Definition Classes
    Quantity → AnyRef → Any
  61. def toTuple(uom: UnitOfMeasure[A]): (Double, String)

    Returns a pair representing the numeric value and the uom's symbol

    Returns a pair representing the numeric value and the uom's symbol

    uom

    UnitOfMeasure[A]

  62. def toTuple: (Double, String)

    Returns a tuple representing the numeric value and the unit's symbol

  63. def unary_-: A
  64. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  65. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  66. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  67. def within(range: QuantityRange[A]): Boolean

    Returns true if this value is within (contains) the range

    Returns true if this value is within (contains) the range

    range

    QuantityRange

    returns

    Boolean

  68. def ~=(that: A)(implicit tolerance: A): Boolean

    approx

  69. def (that: A)(implicit tolerance: A): Boolean

    approx

Inherited from Ordered[A]

Inherited from Comparable[A]

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped