Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Commit

Permalink
removed support for java.math.BigDecimal
Browse files Browse the repository at this point in the history
  • Loading branch information
maxaf committed Jan 2, 2011
1 parent 301f0b3 commit a5c0283
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 27 deletions.
21 changes: 3 additions & 18 deletions src/main/scala/salat/transformers.scala
Expand Up @@ -2,8 +2,7 @@ package com.bumnetworks.salat.transformers

import scala.tools.scalap.scalax.rules.scalasig._
import scala.math.{BigDecimal => ScalaBigDecimal}

import java.math.{BigDecimal => JavaBigDecimal, RoundingMode, MathContext}
import java.math.MathContext

import com.bumnetworks.salat._
import com.bumnetworks.salat.global.mathCtx
Expand All @@ -19,13 +18,6 @@ object out extends CasbahLogging {
case (t, x) => x
}

def JBigDecimalToDouble(implicit ctx: Context): Transformer = {
case (TypeRefType(_, symbol, _), x) if symbol.path == classOf[JavaBigDecimal].getName =>
x match {
case jbd: JavaBigDecimal => jbd.round(implicitly[MathContext]).doubleValue
}
}

def SBigDecimalToDouble(implicit ctx: Context): Transformer = {
case (TypeRefType(_, symbol, _), x) if symbol.path == classOf[ScalaBigDecimal].getName =>
x match {
Expand All @@ -39,21 +31,14 @@ object out extends CasbahLogging {
}

def *(implicit ctx: Context) =
(InContext _) :: (SBigDecimalToDouble _) :: (JBigDecimalToDouble _) :: Nil
(InContext _) :: (SBigDecimalToDouble _) :: Nil
}

object in extends CasbahLogging {
def Fallback(implicit ctx: Context): Transformer = {
case (t, x) => x
}

def DoubleToJBigDecimal(implicit ctx: Context): Transformer = {
case (t @ TypeRefType(_, symbol, _), x) if symbol.path == classOf[JavaBigDecimal].getName =>
x match {
case d: Double => new JavaBigDecimal(d.toString, implicitly[MathContext])
}
}

def DoubleToSBigDecimal(implicit ctx: Context): Transformer = {
case (t @ TypeRefType(_, symbol, _), x) if symbol.path == classOf[ScalaBigDecimal].getName =>
x match {
Expand All @@ -71,5 +56,5 @@ object in extends CasbahLogging {
}

def *(implicit ctx: Context) =
(InContext _) :: (DoubleToSBigDecimal _) :: (DoubleToJBigDecimal _) :: Nil
(InContext _) :: (DoubleToSBigDecimal _) :: Nil
}
2 changes: 0 additions & 2 deletions src/test/scala/salat/SalatSpec.scala
Expand Up @@ -7,8 +7,6 @@ import com.mongodb.casbah.Imports._
import scala.tools.scalap.scalax.rules.scalasig._
import scala.math.{BigDecimal => ScalaBigDecimal}

import java.math.{BigDecimal => JavaBigDecimal}

import org.specs._
import org.specs.specification.PendingUntilFixed

Expand Down
11 changes: 4 additions & 7 deletions src/test/scala/salat/TestModel.scala
Expand Up @@ -11,16 +11,14 @@ import scala.collection.immutable.{Map => IMap}
import scala.collection.mutable.{Map => MMap}
import scala.math.{BigDecimal => ScalaBigDecimal}

import java.math.{BigDecimal => JavaBigDecimal}

case class A(x: String, y: Option[String] = Some("default y"), z: B)
case class B(p: Option[Int], q: Int = 1067, r: C)
case class C(l: Seq[String] = Nil, m: List[Int], n: List[D])
case class D(h: IMap[String, A], i: MMap[String, Int] = MMap.empty, j: Option[B])

case class E(a: String, b: Int, c: ScalaBigDecimal, d: JavaBigDecimal,
aa: Option[String] = None, bb: Option[Int] = None, cc: Option[ScalaBigDecimal] = None, dd: Option[JavaBigDecimal] = None,
aaa: Option[String], bbb: Option[Int], ccc: Option[ScalaBigDecimal], ddd: Option[JavaBigDecimal])
case class E(a: String, b: Int, c: ScalaBigDecimal,
aa: Option[String] = None, bb: Option[Int] = None, cc: Option[ScalaBigDecimal] = None,
aaa: Option[String], bbb: Option[Int], ccc: Option[ScalaBigDecimal])

object `package` {
implicit object GraterA extends Grater(classOf[A])
Expand All @@ -40,6 +38,5 @@ object `package` {

def numbers = E(a = "a value", aa = None, aaa = Some("aaa value"),
b = 2, bb = None, bbb = Some(22),
c = ScalaBigDecimal(3.30003), cc = None, ccc = Some(ScalaBigDecimal(33.30003)),
d = new JavaBigDecimal(4.400004), dd = None, ddd = Some(new JavaBigDecimal(44.400004)))
c = ScalaBigDecimal(3.30003), cc = None, ccc = Some(ScalaBigDecimal(33.30003)))
}

0 comments on commit a5c0283

Please sign in to comment.