Skip to content
This repository
Browse code

Fix deprecation for 2.9 compliance

  • Loading branch information...
commit 82f48ca3a8fe0a294877bf5bbba776ba8ad1bc47 1 parent 4fa6b02
Indrajit Raychaudhuri indrajitr authored
4 persistence/mapper/src/main/scala/net/liftweb/mapper/ManyToMany.scala
@@ -138,14 +138,14 @@ trait ManyToMany extends BaseKeyedMapper {
138 138 protected def childAt(n: Int) = children(n)
139 139 def apply(n: Int) = childAt(n)
140 140 def indexOf(e: T2) =
141   - children.findIndexOf(e eq)
  141 + children.indexWhere(e eq)
142 142
143 143 // 2.7
144 144 // def insertAll(n: Int, iter: Iterable[T2]) {
145 145 // 2.8
146 146 def insertAll(n: Int, traversable: Traversable[T2]) {
147 147 val ownedJoins = traversable map own
148   - val n2 = joins.findIndexOf(isJoinForChild(children(n)))
  148 + val n2 = joins.indexWhere(isJoinForChild(children(n)))
149 149 val before = joins.take(n2)
150 150 val after = joins.drop(n2)
151 151
4 persistence/mapper/src/main/scala/net/liftweb/mapper/MappedInt.scala
@@ -33,7 +33,7 @@ import js._
33 33 abstract class MappedEnum[T<:Mapper[T], ENUM <: Enumeration](val fieldOwner: T, val enum: ENUM) extends MappedField[ENUM#Value, T] {
34 34 private var data: ENUM#Value = defaultValue
35 35 private var orgData: ENUM#Value = defaultValue
36   - def defaultValue: ENUM#Value = enum.iterator.next
  36 + def defaultValue: ENUM#Value = enum.values.iterator.next
37 37 def dbFieldClass = classOf[ENUM#Value]
38 38
39 39 /**
@@ -132,7 +132,7 @@ abstract class MappedEnum[T<:Mapper[T], ENUM <: Enumeration](val fieldOwner: T,
132 132 * Build a list for the select. Return a tuple of (String, String) where the first string
133 133 * is the id.string of the Value and the second string is the Text name of the Value.
134 134 */
135   - def buildDisplayList: List[(Int, String)] = enum.map(a => (a.id, a.toString)).toList
  135 + def buildDisplayList: List[(Int, String)] = enum.values.map(a => (a.id, a.toString)).toList
136 136
137 137 /**
138 138 * Create an input field for the item
10 persistence/mapper/src/main/scala/net/liftweb/mapper/MappedLong.scala
@@ -58,7 +58,7 @@ extends MappedLong[T](theOwner) with MappedForeignKey[Long,T,O] with BaseForeign
58 58 def asSafeJs(obs: Box[KeyObfuscator]): JsExp =
59 59 obs.map(o => JE.Str(o.obscure(dbKeyToTable, is))).openOr(JE.Num(is))
60 60
61   - override def asJsonValue: Box[JsonAST.JValue] =
  61 + override def asJsonValue: Box[JsonAST.JValue] =
62 62 if (defined_?) super.asJsonValue else Full(JsonAST.JNull)
63 63
64 64 override def setFromAny(in: Any): Long =
@@ -81,7 +81,7 @@ extends MappedLong[T](theOwner) with MappedForeignKey[Long,T,O] with BaseForeign
81 81 primeObj(v)
82 82 fieldOwner
83 83 }
84   -
  84 +
85 85 def apply(v: O): T = {
86 86 apply(v.primaryKeyField.is)
87 87 primeObj(Full(v))
@@ -187,7 +187,7 @@ abstract class MappedEnumList[T<:Mapper[T], ENUM <: Enumeration](val fieldOwner:
187 187 private def toLong: Long = is.foldLeft(0L)((a,b) => a + rot(b.id))
188 188
189 189 def fromLong(in: Long): Seq[ENUM#Value] =
190   - enum.iterator.toList.filter(v => (in & rot(v.id)) != 0)
  190 + enum.values.iterator.toList.filter(v => (in & rot(v.id)) != 0)
191 191
192 192 def jdbcFriendly(field: String) = new java.lang.Long(toLong)
193 193 override def jdbcFriendly = new java.lang.Long(toLong)
@@ -241,7 +241,7 @@ abstract class MappedEnumList[T<:Mapper[T], ENUM <: Enumeration](val fieldOwner:
241 241 * Create an input field for the item
242 242 */
243 243 override def _toForm: Box[NodeSeq] =
244   - Full(SHtml.checkbox[ENUM#Value](enum.iterator.toList, is,this(_)).toForm)
  244 + Full(SHtml.checkbox[ENUM#Value](enum.values.iterator.toList, is,this(_)).toForm)
245 245 }
246 246
247 247 /**
@@ -283,7 +283,7 @@ abstract class MappedNullableLong[T<:Mapper[T]](val fieldOwner: T) extends Mappe
283 283
284 284 def asJsExp: JsExp = is.map(v => JE.Num(v)) openOr JE.JsNull
285 285
286   - def asJsonValue: Box[JsonAST.JValue] =
  286 + def asJsonValue: Box[JsonAST.JValue] =
287 287 Full(is.map(v => JsonAST.JInt(v)) openOr JsonAST.JNull)
288 288
289 289 override def readPermission_? = true
2  persistence/mapper/src/main/scala/net/liftweb/mapper/OneToMany.scala
@@ -156,7 +156,7 @@ trait OneToMany[K,T<:KeyedMapper[K, T]] extends KeyedMapper[K,T] { this: T =>
156 156 }
157 157
158 158 override def indexOf[B >: O](e: B): Int =
159   - delegate.findIndexOf(e.asInstanceOf[AnyRef].eq)
  159 + delegate.indexWhere(e.asInstanceOf[AnyRef].eq)
160 160
161 161 // 2.7
162 162 // def insertAll(n: Int, iter: Iterable[O]) {
22 persistence/mapper/src/main/scala/net/liftweb/mapper/view/Paginator.scala
@@ -13,9 +13,9 @@
13 13 * See the License for the specific language governing permissions and
14 14 * limitations under the License.
15 15 */
16   -package net.liftweb
17   -package mapper
18   -package view
  16 +package net.liftweb
  17 +package mapper
  18 +package view
19 19
20 20 import scala.xml.{NodeSeq, Text, Elem}
21 21 import net.liftweb.common.Loggable
@@ -25,12 +25,12 @@ import net.liftweb.http.S.?
25 25 import net.liftweb.util.Helpers._
26 26 import net.liftweb.mapper.{Mapper, MetaMapper, MappedField,
27 27 QueryParam, OrderBy, StartAt, MaxRows, Ascending, Descending}
28   -
  28 +
29 29 /**
30 30 * Helper for when using paginators with a ModelSnippet.
31 31 * Adds a dispatch that delegates the "paginate" snippet to the paginator member.
32 32 * @author nafg and Timothy Perrett
33   - */
  33 + */
34 34 trait PaginatedModelSnippet[T <: Mapper[T]] extends ModelSnippet[T] {
35 35 abstract override def dispatch: DispatchIt = super.dispatch orElse Map("paginate" -> paginator.paginate _ )
36 36 /**
@@ -39,8 +39,8 @@ trait PaginatedModelSnippet[T <: Mapper[T]] extends ModelSnippet[T] {
39 39 val paginator: PaginatorSnippet[T]
40 40 }
41 41
42   -/**
43   - * Paginate mapper instances by supplying the model you
  42 +/**
  43 + * Paginate mapper instances by supplying the model you
44 44 * wish to paginate and Paginator will run your query for you etc.
45 45 *
46 46 * @param meta The singleton of the Mapper class you're paginating
@@ -51,7 +51,7 @@ class MapperPaginator[T <: Mapper[T]](val meta: MetaMapper[T]) extends Paginator
51 51 * QueryParams to use always
52 52 */
53 53 var constantParams: Seq[QueryParam[T]] = Nil
54   -
  54 +
55 55 def count = meta.count(constantParams: _*)
56 56 def page = meta.findAll(constantParams ++ Seq[QueryParam[T]](MaxRows(itemsPerPage), StartAt(first)): _*)
57 57 }
@@ -73,10 +73,10 @@ class SortedMapperPaginator[T <: Mapper[T]](meta: MetaMapper[T],
73 73 initialSort: net.liftweb.mapper.MappedField[_, T],
74 74 _headers: (String, MappedField[_, T])*)
75 75 extends MapperPaginator[T](meta) with SortedPaginator[T, MappedField[_, T]] {
76   -
  76 +
77 77 val headers = _headers.toList
78   - sort = (headers.findIndexOf{case (_,`initialSort`)=>true; case _ => false}, true)
79   -
  78 + sort = (headers.indexWhere{case (_,`initialSort`)=>true; case _ => false}, true)
  79 +
80 80 override def page = meta.findAll(constantParams ++ Seq[QueryParam[T]](mapperSort, MaxRows(itemsPerPage), StartAt(first)): _*)
81 81 private def mapperSort = sort match {
82 82 case (fieldIndex, ascending) =>
32 persistence/mapper/src/main/scala/net/liftweb/mapper/view/TableEditor.scala
@@ -72,15 +72,15 @@ trait ItemsList[T <: Mapper[T]] {
72 72 * The sort direction
73 73 */
74 74 var ascending = true
75   -
  75 +
76 76 /**
77 77 * Returns the items (current + added - removed), sorted.
78 78 * Sorting sorts strings case-insensitive, as well as Ordered and java.lang.Comparable.
79 79 * Anything else where both values are nonnull are sorted via their toString method (case sensitive)
80 80 */
81 81 def items: Seq[T] = {
82   - import scala.util.Sorting._
83   - val unsorted: List[T] = current -- removed ++ added
  82 + import scala.util.Sorting._
  83 + val unsorted: List[T] = current.filterNot(removed.contains) ++ added
84 84 sortField match {
85 85 case None =>
86 86 unsorted
@@ -138,17 +138,17 @@ trait ItemsList[T <: Mapper[T]] {
138 138 def save {
139 139 val (successAdd, failAdd) = added.partition(_.save)
140 140 added = failAdd
141   -
  141 +
142 142 val (successRemove, failRemove) = removed.partition(_.delete_!)
143   - current --= successRemove
  143 + current = current.filterNot(successRemove.contains)
144 144 removed = failRemove
145   -
  145 +
146 146 for(c <- current if c.validate.isEmpty) c.save
147   -
  147 +
148 148 current ++= successAdd
149 149 }
150   -
151   -
  150 +
  151 +
152 152 def sortBy(field: MappedField[_, T]) = (sortField, ascending) match {
153 153 case (Some(f), true) if f eq field =>
154 154 ascending = false
@@ -165,7 +165,7 @@ trait ItemsList[T <: Mapper[T]] {
165 165 ascending = true
166 166 }
167 167 }
168   -
  168 +
169 169 reload
170 170 }
171 171
@@ -180,7 +180,7 @@ trait ItemsList[T <: Mapper[T]] {
180 180 */
181 181 object TableEditor {
182 182 net.liftweb.http.LiftRules.addToPackages("net.liftweb.mapper.view")
183   -
  183 +
184 184 private[view] val map = new scala.collection.mutable.HashMap[String, TableEditorImpl[_]]
185 185 def registerTable[T<:Mapper[T]](name: String, meta: T with MetaMapper[T], title: String) =
186 186 map(name) = new TableEditorImpl(title, meta)
@@ -229,7 +229,7 @@ protected class TableEditorImpl[T <: Mapper[T]](val title: String, meta: T with
229 229 trait ItemsListEditor[T<:Mapper[T]] {
230 230 def items: ItemsList[T]
231 231 def title: String
232   -
  232 +
233 233 def onInsert: Unit = items.add
234 234 def onRemove(item: T): Unit = items.remove(item)
235 235 def onSubmit: Unit = try {
@@ -239,11 +239,11 @@ trait ItemsListEditor[T<:Mapper[T]] {
239 239 S.error("Not all items could be saved!")
240 240 }
241 241 def sortFn(f: MappedField[_, T]): ()=>Unit = items.sortFn(f)
242   -
  242 +
243 243 val fieldFilter: MappedField[_,T]=>Boolean = (f: MappedField[_,T])=>true
244   -
  244 +
245 245 def customBind(item: T): NodeSeq=>NodeSeq = (ns: NodeSeq) => ns
246   -
  246 +
247 247 def edit(xhtml: NodeSeq): NodeSeq = {
248 248 def unsavedScript = (<head><script type="text/javascript">
249 249 var safeToContinue = false
@@ -307,5 +307,5 @@ trait ItemsListEditor[T<:Mapper[T]] {
307 307 "saveBtn" -> SHtml.submit(?("Save"), onSubmit _, noPrompt)
308 308 )
309 309 }
310   -
  310 +
311 311 }

0 comments on commit 82f48ca

Please sign in to comment.
Something went wrong with that request. Please try again.