Packages

• package
Definition Classes
root
• package

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

Definition Classes
squants
Since

0.1

• package

Definition Classes
squants
Since

0.1

• package
Definition Classes
squants
• package

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

Definition Classes
squants
Since

0.1

• package

Definition Classes
squants
Since

0.1

• package

Definition Classes
squants
Since

0.1

• package

Definition Classes
squants
Since

0.1

• package

Definition Classes
squants
Since

0.1

• package

Definition Classes
squants
Since

0.1

• package

Definition Classes
squants
Since

0.1

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

squants

Quantity 

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

A base class for measurable quantities, instances of which contain a value and a unit

Self Type
A
Source
Quantity.scala
Since

0.1

Linear Supertypes
Ordered[A], Comparable[A], Serializable, Serializable, AnyRef, Any
Ordering
1. Alphabetic
2. By Inheritance
Inherited
1. Quantity
2. Ordered
3. Comparable
4. Serializable
5. Serializable
6. AnyRef
7. Any
1. Hide All
2. Show All
Visibility
1. Public
2. All

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

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

approx

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

Returns the absolute value of this Quantity

Returns the absolute value of this Quantity

returns

Quantity

20. def approx(that: A)(implicit tolerance: A)

Returns boolean result of approximate equality comparison

Returns boolean result of approximate equality comparison

that

Quantity

tolerance

Quantity

21. final def asInstanceOf[T0]: T0
Definition Classes
Any
22. 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

java.lang.Math#ceil(double)

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

Implements Ordered.compare

Implements Ordered.compare

that

Quantity

returns

Int

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

Divide this quantity by a like quantity

Divide this quantity by a like quantity

that

Quantity

returns

Double

27. def divide(that: Double): A

Divide this quantity by some number

Divide this quantity by some number

that

Double

returns

Quantity

28. 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)

29. 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)

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

Override of equals method

Override of equals method

that

must be of matching value and unit

Definition Classes
Quantity → AnyRef → Any
32. def finalize(): Unit
Attributes
protected[java.lang]
Definition Classes
AnyRef
Annotations
@throws( classOf[java.lang.Throwable] )
33. 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

java.lang.Math#floor(double)

34. final def getClass(): Class[_]
Definition Classes
AnyRef → Any
35. def hashCode(): Int

Override of hashCode

Override of hashCode

Definition Classes
Quantity → AnyRef → Any
36. 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

37. final def isInstanceOf[T0]
Definition Classes
Any
38. 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

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

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

41. def minus(that: A): A

Subtract two like quantities

Subtract two like quantities

that

Quantity

returns

Quantity

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

Returns the negative value of this Quantity

Returns the negative value of this Quantity

returns

Quantity

44. def notWithin(range: QuantityRange[A])

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

45. final def notify(): Unit
Definition Classes
AnyRef
46. final def notifyAll(): Unit
Definition Classes
AnyRef
47. def plus(that: A): A

that

Quantity

returns

Quantity

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

49. def remainder(that: A)

Returns the remainder of a division by a like quantity

Returns the remainder of a division by a like quantity

that

Quantity

returns

Double

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

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

java.lang.Math#rint(double)

52. final def synchronized[T0](arg0: ⇒ T0): T0
Definition Classes
AnyRef
53. def times(that: Double): A

Multiply this quantity by some number

Multiply this quantity by some number

that

Double

returns

Quantity

54. def to(uom: UnitOfMeasure[A])

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

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

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

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

58. 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
59. 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]

60. def toTuple: (Double, String)

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

61. def unary_-(): A
62. final def wait(): Unit
Definition Classes
AnyRef
Annotations
@throws( ... )
63. final def wait(arg0: Long, arg1: Int): Unit
Definition Classes
AnyRef
Annotations
@throws( ... )
64. final def wait(arg0: Long): Unit
Definition Classes
AnyRef
Annotations
@throws( ... )
65. def within(range: QuantityRange[A])

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

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

range

QuantityRange

returns

Boolean

66. def ~=(that: A)(implicit tolerance: A)

approx

67. def (that: A)(implicit tolerance: A)

approx