scala-news-reader

rss/atom news reader in scala

git clone https://9o.is/git/scala-news-reader.git

MongoListFieldExtra.scala

(793B)


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