Package

squants

Permalink

package squants

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

Source
package.scala
Version

0.1

Since

0.1

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. squants
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract class AbstractQuantityNumeric[A <: Quantity[A]] extends Numeric[A]

    Permalink

    Base class for creating objects to manage quantities as Numeric.

    Base class for creating objects to manage quantities as Numeric.

    One limitation is the times operation which is not supported by every quantity type

    A

    Quantity type

  2. type Acceleration = squants.motion.Acceleration

    Permalink
  3. type Angle = squants.space.Angle

    Permalink
  4. type Area = squants.space.Area

    Permalink
  5. trait BaseDimension extends AnyRef

    Permalink

    SI Base Quantity

  6. type ChemicalAmount = squants.mass.ChemicalAmount

    Permalink
  7. type Density = squants.mass.Density

    Permalink
  8. trait Dimension[A <: Quantity[A]] extends AnyRef

    Permalink

    Represents a Dimension or Quantity Type

    Represents a Dimension or Quantity Type

    This trait should be mixed into the Companion Objects of specific Quantity Types.

    A

    Quantity Type

  9. final class Dimensionless extends Quantity[Dimensionless] with TimeIntegral[Frequency]

    Permalink

    Represents a quantity of some thing for which there is no dimension.

    Represents a quantity of some thing for which there is no dimension.

    This may be used to represent counts or other discrete amounts of everyday life, but may also represent ratios between like quantities where the units have cancelled out.

    Since

    0.1

  10. trait DimensionlessUnit extends UnitOfMeasure[Dimensionless] with UnitConverter

    Permalink

    Base trait for units of squants.Dimensionless

    Base trait for units of squants.Dimensionless

    The DimensionlessUnit is a useful paradox

  11. case class DoubleVector(coordinates: Double*) extends SVector[Double] with Product with Serializable

    Permalink

    Double (Real Number) Vector

    Double (Real Number) Vector

    coordinates

    Double*

    Since

    0.3.0

  12. type ElectricCurrent = squants.electro.ElectricCurrent

    Permalink
  13. type Energy = squants.energy.Energy

    Permalink
  14. type Force = squants.motion.Force

    Permalink
  15. type Jerk = squants.motion.Jerk

    Permalink
  16. type Length = squants.space.Length

    Permalink
  17. trait LikeRatio[A <: Quantity[A]] extends Ratio[A, A]

    Permalink
  18. type LuminousIntensity = squants.photo.LuminousIntensity

    Permalink
  19. type Mass = squants.mass.Mass

    Permalink
  20. type MassFlow = squants.motion.MassFlow

    Permalink
  21. type Momentum = squants.motion.Momentum

    Permalink
  22. type Money = squants.market.Money

    Permalink
  23. type Power = squants.energy.Power

    Permalink
  24. type PowerRamp = squants.energy.PowerRamp

    Permalink
  25. type Price[A <: Quantity[A]] = squants.market.Price[A]

    Permalink
  26. trait PrimaryUnit extends UnitConverter

    Permalink

    Identifies the Unit of Measure with a conversionFactor of 1.0.

    Identifies the Unit of Measure with a conversionFactor of 1.0.

    It is used as the intermediary unit during conversions

    Each Quantity should have one and only one ValueUnit

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

    Permalink

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

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

    Since

    0.1

  28. case class QuantityParseException(message: String, expression: String) extends Exception with Product with Serializable

    Permalink
  29. case class QuantityRange[A <: Quantity[A]](lower: A, upper: A) extends Product with Serializable

    Permalink

    Represents a Range starting at one Quantity value and going up to another

    Represents a Range starting at one Quantity value and going up to another

    A

    the Quantity Type

    lower

    Quantity representing the lower bound of the range

    upper

    Quantity representing the upper bound of the range

    Since

    0.1

  30. type QuantitySeries[A <: Quantity[A]] = IndexedSeq[QuantityRange[A]]

    Permalink
  31. case class QuantityVector[A <: Quantity[A]](coordinates: A*) extends SVector[A] with Product with Serializable

    Permalink

    Quantity Vector

    Quantity Vector

    A

    QuantityType

    coordinates

    Variable list of A

    Since

    0.3.0

  32. trait Ratio[A <: Quantity[A], B <: Quantity[B]] extends AnyRef

    Permalink

    Defines an interface and partial implementation for types that represent a ratio between any two quantities

    Defines an interface and partial implementation for types that represent a ratio between any two quantities

    A

    Quantity A

    B

    Quantity B

    Since

    0.1

  33. trait SVector[A] extends AnyRef

    Permalink

    Root trait for representing Vectors

    Root trait for representing Vectors

    A

    Type for the Vector's coordinate values

    Since

    0.3.0

  34. trait SiBaseUnit extends SiUnit

    Permalink

    A marker trait identifying SI Base Units

  35. trait SiUnit extends AnyRef

    Permalink

    A market trait identifying SI Units

  36. type SolidAngle = squants.space.SolidAngle

    Permalink
  37. implicit class SquantifiedBigDecimal extends AnyRef

    Permalink

    Provides implicit conversions that allow BigDecimals to lead in * operations

    Provides implicit conversions that allow BigDecimals to lead in * operations

    BigDecimal(1.5) * Kilometers(10) should be(Kilometers(15))
  38. implicit class SquantifiedDouble extends AnyRef

    Permalink

    Provides implicit conversions that allow Doubles to lead in * operations

    Provides implicit conversions that allow Doubles to lead in * operations

    1.5 * Kilometers(10) should be(Kilometers(15))
  39. implicit class SquantifiedLong extends AnyRef

    Permalink

    Provides implicit conversions that allow Longs to lead in * operations

    Provides implicit conversions that allow Longs to lead in * operations

    5 * Kilometers(10) should be(Kilometers(15))
  40. type Temperature = squants.thermal.Temperature

    Permalink
  41. type Time = squants.time.Time

    Permalink
  42. trait UnitConverter extends AnyRef

    Permalink

    A Unit of Measure that require a simple multiplier for converting to and from the underlying value's unit

  43. trait UnitOfMeasure[A <: Quantity[A]] extends Serializable

    Permalink

    A Unit of Measure is used to define the scale of a quantity measurement

    A Unit of Measure is used to define the scale of a quantity measurement

    Each Quantity Dimension must include at least one Unit of Measure, and one and only Primary. Other units of measure are defined with conversionFactors relative to the Primary.

    A

    The type of Quantity being measured

    Since

    0.1

  44. type Velocity = squants.motion.Velocity

    Permalink
  45. type Volume = squants.space.Volume

    Permalink
  46. type VolumeFlow = squants.motion.VolumeFlow

    Permalink

Value Members

  1. val Amperes: squants.electro.Amperes.type

    Permalink
  2. object BinarySystem

    Permalink

    Singleton defining Metric System multipliers

    Singleton defining Metric System multipliers

    Since

    0.1

  3. val Candelas: squants.photo.Candelas.type

    Permalink
  4. object Dimensionless extends Dimension[Dimensionless] with Serializable

    Permalink

    Factory singleton for squants.Dimensionless

  5. object DimensionlessConversions

    Permalink
  6. object Dozen extends DimensionlessUnit

    Permalink

    Represents a unit of dozen (12)

  7. object Each extends DimensionlessUnit with PrimaryUnit with SiUnit

    Permalink

    Represents a unit of singles

  8. object Gross extends DimensionlessUnit

    Permalink

    Represents a unit of gross (144)

  9. val Kelvin: squants.thermal.Kelvin.type

    Permalink
  10. val Kilograms: squants.mass.Kilograms.type

    Permalink
  11. val Meters: squants.space.Meters.type

    Permalink
  12. object MetricSystem

    Permalink

    Singleton defining Metric System multipliers

    Singleton defining Metric System multipliers

    Since

    0.1

  13. val Moles: squants.mass.Moles.type

    Permalink
  14. object Percent extends DimensionlessUnit

    Permalink

    Represents a number of hundredths (0.01)

  15. val Radians: squants.space.Radians.type

    Permalink
  16. object SVector

    Permalink
  17. object Score extends DimensionlessUnit

    Permalink

    Represents a unit of scores (20)

  18. val Seconds: squants.time.Seconds.type

    Permalink
  19. val SquareRadians: SquaredRadians.type

    Permalink
  20. package electro

    Permalink

    Since

    0.1

  21. package energy

    Permalink

    Since

    0.1

  22. package information

    Permalink
  23. package market

    Permalink

    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

    Since

    0.1

  24. package mass

    Permalink

    Since

    0.1

  25. package motion

    Permalink

    Since

    0.1

  26. package photo

    Permalink

    Since

    0.1

  27. package radio

    Permalink

    Since

    0.1

  28. package space

    Permalink

    Since

    0.1

  29. package thermal

    Permalink

    Since

    0.1

  30. package time

    Permalink

    Since

    0.1

Inherited from AnyRef

Inherited from Any

Ungrouped