Created
October 19, 2011 02:49
-
-
Save rrichardson/1297364 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait SlashemField[V, M <: Record[M]] extends OwnedField[M] { | |
def valueBoxFromAny(a: Any): Box[V] = { | |
try { | |
Full(a.asInstanceOf[V]) | |
} catch { | |
case _ => Empty | |
} | |
} | |
} | |
class SlashemObjectIdField[T <: Record[T]](owner: T) extends ObjectIdField[T](owner) with SlashemField[ObjectId, T] { | |
override def valueBoxFromAny(a: Any) : Box[ObjectId]= { | |
try { | |
a match { | |
case "" => Empty | |
case s: String => Full(new ObjectId(s)) | |
case i: ObjectId => Full(i) | |
case _ => Empty | |
} | |
} catch { | |
case _ => Empty | |
} | |
} | |
} | |
// error | |
[error] /slashem/src/main/scala/com/foursquare/slashem/Schema.scala:567: overriding method valueBoxFromAny in class ObjectIdField of type (a: Any)net.liftweb.common.Box[org.bson.types.ObjectId] with Serializable; | |
[error] method valueBoxFromAny has incompatible type | |
[error] override def valueBoxFromAny(a: Any) : Box[ObjectId]= { | |
[error] ^ | |
[error] one error found | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
class SlashemIntListField[T <: Record[T]](owner: T) extends IntListFieldT with SlashemField[List[Int], T] {
override def valueBoxFromAny(a: Any) ={
try {
a match {
case "" => Empty
case ar: Array[Int] => Full(ar.toList)
case ar: Array[Integer] => Full(ar.toList.map(x=>x.intValue))
case s: String => Full(s.split(" ").map(x => x.toInt).toList)
case _ => Empty
}
} catch {
case _ => Empty
}
}
}