pyc-website

main website for pyc inc.

git clone https://9o.is/git/pyc-website.git

MongoListFieldExtra.scala

(803B)


      1 package inc.pyc
      2 package model
      3 package field
      4 
      5 import com.mongodb._
      6 import net.liftweb._
      7 import common._
      8 import mongodb.record._
      9 import field._
     10 
     11 trait MongoListFieldExtra[OwnerType <: BsonRecord[OwnerType], ListType]
     12   extends MongoListField[OwnerType, ListType] {
     13 
     14   def add(a: ListType): OwnerType = 
     15     if (exists(a)) owner
     16     else this(a :: get)
     17     
     18   def remove(a: ListType): OwnerType =
     19     removeStr(a.toString)
     20     
     21   def removeStr(s: String): OwnerType =
     22     this(get.filterNot(_.toString == s))
     23     
     24   def exists(a: ListType): Boolean = 
     25     existsStr(a.toString)
     26     
     27   def existsStr(s: String): Boolean = 
     28     get.exists(_.toString == s) 
     29     
     30   def find(a: ListType): Box[ListType] = 
     31     findStr(a.toString)
     32     
     33   def findStr(s: String): Box[ListType] = 
     34     get.find(_.toString == s) 
     35 }