Skip to content

Commit

Permalink
Merge branch 'master' into release-1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
derekmorr authored May 25, 2017
2 parents 26d1487 + 853b609 commit d4fa4a8
Show file tree
Hide file tree
Showing 21 changed files with 548 additions and 163 deletions.
305 changes: 260 additions & 45 deletions README.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ object Console {
squants.space._,
squants.thermal._,
squants.time._,
squants.unitgroups.UnitGroup,
squants.experimental.formatter._,
squants.experimental.unitgroups.UnitGroup,
squants.DimensionlessConversions._,
squants.electro.CapacitanceConversions._,
squants.electro.ConductivityConversions._,
Expand Down
12 changes: 8 additions & 4 deletions shared/src/main/scala/squants/QuantityRange.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import scala.annotation.tailrec
* @tparam A the Quantity Type
*/
case class QuantityRange[A <: Quantity[A]](lower: A, upper: A) {
if (lower >= upper) throw new IllegalArgumentException("QuantityRange upper bound must be greater than or equal to the lower bound")
if (lower >= upper) {
throw new IllegalArgumentException("QuantityRange upper bound must be strictly greater than to the lower bound")
}

/**
* Create a Seq of `multiple` ranges equal in size to the original with sequential range values
Expand Down Expand Up @@ -254,7 +256,8 @@ case class QuantityRange[A <: Quantity[A]](lower: A, upper: A) {
def +-(that: A) = incFromDecTo(that)

/**
* Returns true if the quantity is contained within this range, otherwise false
* Returns true if the quantity is contained within this range, otherwise false.
* This check is *exclusive* of the range's upper limit.
* @param q Quantity
* @return
*/
Expand All @@ -279,11 +282,12 @@ case class QuantityRange[A <: Quantity[A]](lower: A, upper: A) {
def partiallyContains(range: QuantityRange[A]) = range.lower < upper && range.upper > lower

/**
* Returns true if `that` quantity is included within `this` range
* Returns true if `that` quantity is included within `this` range.
* This check is *inclusive* of the range's upper limit.
* @param q Quantity
* @return
*/
def includes(q: A) = q >= lower && q <= upper
def includes(q: A): Boolean = q >= lower && q <= upper

/**
* Returns true if `that` range is completely included in `this` range, otherwise false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package squants.formatter
package squants.experimental.formatter

import squants.Quantity
import squants.unitgroups.UnitGroup
import squants.experimental.unitgroups.UnitGroup

trait DefaultFormatter[A <: Quantity[A]] extends Formatter[A] {
def unitGroup: UnitGroup[A]

override def bestUnit(quantity: Quantity[A]): A = {
class DefaultFormatter[A <: Quantity[A]](unitGroup: UnitGroup[A]) extends Formatter[A] {
override def inBestUnit(quantity: Quantity[A]): A = {
if (unitGroup.units.isEmpty)
quantity.in(quantity.unit)
else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package squants.experimental.formatter

import squants.Quantity

trait Formatter[A <: Quantity[A]] {
def inBestUnit(quantity: Quantity[A]): A
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package squants.experimental.formatter

import squants.Quantity
import squants.information.Information
import squants.mass._
import squants.space.Length
import squants.experimental.unitgroups.UnitGroup
import squants.experimental.unitgroups.information.{IECInformation, MetricInformation}
import squants.experimental.unitgroups.misc.{AstronomicalLengthUnitGroup, TroyMasses}

object Formatters {
val AstroUnitFormatter: DefaultFormatter[Length] = new DefaultFormatter(AstronomicalLengthUnitGroup)

val TroyFormatter: DefaultFormatter[Mass] = new DefaultFormatter(TroyMasses)

val InformationMetricFormatter: DefaultFormatter[Information] = new DefaultFormatter(MetricInformation)

val InformationIECFormatter: DefaultFormatter[Information] = new DefaultFormatter(IECInformation)
}

object implicits {
implicit def implicitFormatter[A <: Quantity[A]](implicit implicitUnitGroup: UnitGroup[A]): Formatter[A] = {
new DefaultFormatter[A](implicitUnitGroup)
}
}

object syntax {
implicit class FormattedQuantity[A <: Quantity[A]](quantity: Quantity[A]) {
def inBestUnit(implicit formatter: Formatter[A]): Quantity[A] = {
formatter.inBestUnit(quantity)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package squants.unitgroups
package squants.experimental.unitgroups

import squants.Dimension
import squants.electro._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package squants.unitgroups
package squants.experimental.unitgroups

import scala.collection.immutable.{Set, SortedSet}

Expand All @@ -16,7 +16,7 @@ trait UnitGroup[A <: Quantity[A]] {
SortedSet[UnitOfMeasure[A]]() ++ units
}

/** [[Ordering]] instance for [[UnitOfMeasure]][A] */
/** [[scala.math.Ordering]] instance for [[UnitOfMeasure]][A] */
class UomOrdering[A <: Quantity[A]] extends Ordering[UnitOfMeasure[A]] {
override def compare(x: UnitOfMeasure[A], y: UnitOfMeasure[A]): Int = {
val siUnit = x(1).dimension.siUnit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package squants.unitgroups
package squants.experimental.unitgroups

import squants.UnitOfMeasure
import squants.information._

/**
* UnitGroups for [[Information]]
* UnitGroups for [[squants.information.Information]]
*/
package object information {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package squants.unitgroups
package squants.experimental.unitgroups

import squants.UnitOfMeasure
import squants.mass._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package squants.unitgroups.si
package squants.experimental.unitgroups.si

import squants.UnitOfMeasure
import squants.electro._
import squants.mass.{AreaDensity, KilogramsPerHectare, Mass, Tonnes}
import squants.motion.{KilometersPerHour, Velocity}
import squants.space._
import squants.time.{Days, Hours, Minutes, Time}
import squants.unitgroups.UnitGroup
import squants.unitgroups.si.strict.implicits.mkSiUnitGroup
import squants.experimental.unitgroups.UnitGroup
import squants.experimental.unitgroups.si.strict.implicits.mkSiUnitGroup

/**
* Contains all of units in [[squants.unitgroups.si.strict ]] plus extra units defined by
* Contains all of units in [[squants.experimental.unitgroups.si.strict ]] plus extra units defined by
* [[http://www.bipm.org/en/publications/si-brochure/table6.html The BIPM SI Brochure, Section 4.1.]]
*/
package object expanded {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package squants.unitgroups.si
package squants.experimental.unitgroups.si

import squants.{Dimension, Quantity}
import squants.{SiUnit, UnitOfMeasure}
import squants.unitgroups.UnitGroup
import squants.experimental.unitgroups.UnitGroup

/**
* UnitGroups for SI.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package squants.unitgroups
package squants.experimental.unitgroups

import squants.UnitOfMeasure
import squants.mass._
Expand Down
7 changes: 0 additions & 7 deletions shared/src/main/scala/squants/formatter/Formatter.scala

This file was deleted.

39 changes: 0 additions & 39 deletions shared/src/main/scala/squants/formatter/Formatters.scala

This file was deleted.

Loading

0 comments on commit d4fa4a8

Please sign in to comment.