Permalink
Browse files

A couple of type safety improvements and test fixes.

  • Loading branch information...
1 parent 67c0084 commit a53d29094bcd08622b60ce3d03af9b0506c55bdc @nuttycom nuttycom committed Jul 27, 2011
@@ -102,22 +102,23 @@ sealed case class MongoOrFilter(queries: ListSet[MongoFilter]) extends MongoFilt
sealed case class MongoAndFilter(queries: ListSet[MongoFilter]) extends MongoFilter { self =>
def filter: JValue = {
- val (notEqs, eqs) = queries partition { filter => filter match {
- case MongoFieldFilter(lhs, e @ $eq, rhs) => false
+ val (notEqs, eqs) = queries partition {
+ case MongoFieldFilter(lhs, $eq, rhs) => false
case _ => true
- }}
+ }
+
JObject(notEqsQuery(notEqs).fields ::: eqsQuery(eqs).fields)
}
private def notEqsQuery(queries: ListSet[MongoFilter]) = {
implicit val mergeMonoid = MergeMonoid
val objects = queries.map(_.filter).toList
- (JObject(Nil) :: objects).asMA.sum.asInstanceOf[JObject]
+ (JObject(Nil) :: objects).asMA.sum asUnsafe JObject
}
private def eqsQuery(queries: ListSet[MongoFilter]) = {
implicit val concatMonoid = ConcatMonoid
- val fields = queries.map(_.asInstanceOf[MongoFieldFilter]).map(v => JField(JPathExtension.toMongoField(v.lhs), v.rhs.toJValue).asInstanceOf[JValue]).toList
- (JObject(Nil) :: fields).asMA.sum.asInstanceOf[JObject]
+ val fields = queries.collect{ case MongoFieldFilter(lhs, _, rhs) => JField(JPathExtension.toMongoField(lhs), rhs.toJValue) }.toList
+ JObject(fields)
}
def unary_! : MongoFilter = MongoOrFilter(queries.map(!_))
@@ -281,7 +281,7 @@ class MockDatabaseCollectionSpec extends Specification{
val feeds = collection.select(MongoSelection(Set()), None, None, None, None, None, false).head \\ "feeds"
- feeds.asInstanceOf[JObject].fields.length mustEqual (1)
+ (feeds(0) asUnsafe JObject).fields.length mustEqual (1)
}
"insert by update field when upsert is true" in{
val collection = newCollection

0 comments on commit a53d290

Please sign in to comment.