Skip to content
This repository
Browse code

Merge branch 'wip_1087_1088'

Fixes #1087, #1088

* wip_1087_1088:
  MappedField#canEqual: override is unnecessary
  Test #1087 -- Menu.param{s,}[T <: AnyRef]
  Test #1088 -- MappedField#equals requires getClass to equal. Also, respect scala.Equals#canEqual
  • Loading branch information...
commit 0b5068b50c7b2eadccb8aad9be4bfa54c0f2ee1e 2 parents c16413f + 2e4de02
nafg authored August 28, 2011
23  persistence/mapper/src/main/scala/net/liftweb/mapper/MappedField.scala
@@ -265,7 +265,7 @@ trait MappedNullableField[NullableFieldType <: Any,OwnerType <: Mapper[OwnerType
265 265
  * The strongly typed field that's mapped to a column (or many columns) in the database.
266 266
  * FieldType is the type of the field and OwnerType is the Owner of the field
267 267
  */
268  
-trait MappedField[FieldType <: Any,OwnerType <: Mapper[OwnerType]] extends TypedField[FieldType] with BaseOwnedMappedField[OwnerType] with FieldIdentifier with PSettableValueHolder[FieldType] {
  268
+trait MappedField[FieldType <: Any,OwnerType <: Mapper[OwnerType]] extends TypedField[FieldType] with BaseOwnedMappedField[OwnerType] with FieldIdentifier with PSettableValueHolder[FieldType] with scala.Equals {
269 269
 
270 270
   /**
271 271
    * Will be set to the type of the field
@@ -673,11 +673,22 @@ trait MappedField[FieldType <: Any,OwnerType <: Mapper[OwnerType]] extends Typed
673 673
    * Does the "right thing" comparing mapped fields
674 674
    */
675 675
   override def equals(other: Any): Boolean = {
676  
-    other match {
677  
-      case mapped: MappedField[_, _] => this.i_is_! == mapped.i_is_!
678  
-      case ov: AnyRef if (ov ne null) && dbFieldClass.isAssignableFrom(ov.getClass) => this.is == runFilters(ov.asInstanceOf[FieldType], setFilter)
679  
-      case ov => this.is == ov
680  
-    }
  676
+    (
  677
+      other match {
  678
+        case e: scala.Equals => e canEqual this
  679
+        case _ => true}
  680
+    ) && (
  681
+      other match {
  682
+        case mapped: MappedField[_, _] => this.i_is_! == mapped.i_is_!
  683
+        case ov: AnyRef if (ov ne null) && dbFieldClass.isAssignableFrom(ov.getClass) => this.is == runFilters(ov.asInstanceOf[FieldType], setFilter)
  684
+        case ov => this.is == ov
  685
+      }
  686
+    )
  687
+  }
  688
+
  689
+  def canEqual(that: Any) = that match {
  690
+    case ar: AnyRef => ar.getClass==this.getClass
  691
+    case _ => false
681 692
   }
682 693
 
683 694
   override def asHtml : Node = Text(toString)
8  web/webkit/src/main/scala/net/liftweb/sitemap/Menu.scala
@@ -91,7 +91,7 @@ object Menu extends MenuSingleton {
91 91
    * An intermediate class that holds the basic stuff that's needed to make a Menu item for SiteMap.
92 92
    * You must include at least one URI path element by calling the / method
93 93
    */
94  
-  class PreParamMenu[T](name: String, linkText: Loc.LinkText[T], parser: String => Box[T], encoder: T => String) {
  94
+  class PreParamMenu[T<:AnyRef](name: String, linkText: Loc.LinkText[T], parser: String => Box[T], encoder: T => String) {
95 95
     /**
96 96
      * The method to add a path element to the URL representing this menu item
97 97
      */
@@ -219,7 +219,7 @@ object Menu extends MenuSingleton {
219 219
    * An intermediate class that holds the basic stuff that's needed to make a Menu item for SiteMap.
220 220
    * You must include at least one URI path element by calling the / method
221 221
    */
222  
-  class PreParamsMenu[T](name: String, linkText: Loc.LinkText[T],
  222
+  class PreParamsMenu[T<:AnyRef](name: String, linkText: Loc.LinkText[T],
223 223
                          parser: List[String] => Box[T],
224 224
                          encoder: T => List[String]) {
225 225
     /**
@@ -559,11 +559,11 @@ sealed trait MenuSingleton {
559 559
    */
560 560
   def i(nameAndLink: String): PreMenu = Menu.apply(nameAndLink, S ? nameAndLink)
561 561
 
562  
-  def param[T](name: String, linkText: Loc.LinkText[T], parser: String => Box[T],
  562
+  def param[T<:AnyRef](name: String, linkText: Loc.LinkText[T], parser: String => Box[T],
563 563
                encoder: T => String): PreParamMenu[T] =
564 564
     new PreParamMenu[T](name, linkText, parser, encoder)
565 565
 
566  
-  def params[T](name: String, linkText: Loc.LinkText[T],
  566
+  def params[T<:AnyRef](name: String, linkText: Loc.LinkText[T],
567 567
                 parser: List[String] => Box[T],
568 568
                 encoder: T => List[String]): PreParamsMenu[T] =
569 569
     new PreParamsMenu[T](name, linkText, parser, encoder)

0 notes on commit 0b5068b

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