Skip to content

Commit

Permalink
Merge branch 'wip_1087_1088'
Browse files Browse the repository at this point in the history
Fixes lift#1087, lift#1088

* wip_1087_1088:
  MappedField#canEqual: override is unnecessary
  Test lift#1087 -- Menu.param{s,}[T <: AnyRef]
  Test lift#1088 -- MappedField#equals requires getClass to equal. Also, respect scala.Equals#canEqual
  • Loading branch information
nafg committed Aug 29, 2011
2 parents c16413f + 2e4de02 commit 0b5068b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Expand Up @@ -265,7 +265,7 @@ trait MappedNullableField[NullableFieldType <: Any,OwnerType <: Mapper[OwnerType
* The strongly typed field that's mapped to a column (or many columns) in the database.
* FieldType is the type of the field and OwnerType is the Owner of the field
*/
trait MappedField[FieldType <: Any,OwnerType <: Mapper[OwnerType]] extends TypedField[FieldType] with BaseOwnedMappedField[OwnerType] with FieldIdentifier with PSettableValueHolder[FieldType] {
trait MappedField[FieldType <: Any,OwnerType <: Mapper[OwnerType]] extends TypedField[FieldType] with BaseOwnedMappedField[OwnerType] with FieldIdentifier with PSettableValueHolder[FieldType] with scala.Equals {

/**
* Will be set to the type of the field
Expand Down Expand Up @@ -673,11 +673,22 @@ trait MappedField[FieldType <: Any,OwnerType <: Mapper[OwnerType]] extends Typed
* Does the "right thing" comparing mapped fields
*/
override def equals(other: Any): Boolean = {
other match {
case mapped: MappedField[_, _] => this.i_is_! == mapped.i_is_!
case ov: AnyRef if (ov ne null) && dbFieldClass.isAssignableFrom(ov.getClass) => this.is == runFilters(ov.asInstanceOf[FieldType], setFilter)
case ov => this.is == ov
}
(
other match {
case e: scala.Equals => e canEqual this
case _ => true}
) && (
other match {
case mapped: MappedField[_, _] => this.i_is_! == mapped.i_is_!
case ov: AnyRef if (ov ne null) && dbFieldClass.isAssignableFrom(ov.getClass) => this.is == runFilters(ov.asInstanceOf[FieldType], setFilter)
case ov => this.is == ov
}
)
}

def canEqual(that: Any) = that match {
case ar: AnyRef => ar.getClass==this.getClass
case _ => false
}

override def asHtml : Node = Text(toString)
Expand Down
8 changes: 4 additions & 4 deletions web/webkit/src/main/scala/net/liftweb/sitemap/Menu.scala
Expand Up @@ -91,7 +91,7 @@ object Menu extends MenuSingleton {
* An intermediate class that holds the basic stuff that's needed to make a Menu item for SiteMap.
* You must include at least one URI path element by calling the / method
*/
class PreParamMenu[T](name: String, linkText: Loc.LinkText[T], parser: String => Box[T], encoder: T => String) {
class PreParamMenu[T<:AnyRef](name: String, linkText: Loc.LinkText[T], parser: String => Box[T], encoder: T => String) {
/**
* The method to add a path element to the URL representing this menu item
*/
Expand Down Expand Up @@ -219,7 +219,7 @@ object Menu extends MenuSingleton {
* An intermediate class that holds the basic stuff that's needed to make a Menu item for SiteMap.
* You must include at least one URI path element by calling the / method
*/
class PreParamsMenu[T](name: String, linkText: Loc.LinkText[T],
class PreParamsMenu[T<:AnyRef](name: String, linkText: Loc.LinkText[T],
parser: List[String] => Box[T],
encoder: T => List[String]) {
/**
Expand Down Expand Up @@ -559,11 +559,11 @@ sealed trait MenuSingleton {
*/
def i(nameAndLink: String): PreMenu = Menu.apply(nameAndLink, S ? nameAndLink)

def param[T](name: String, linkText: Loc.LinkText[T], parser: String => Box[T],
def param[T<:AnyRef](name: String, linkText: Loc.LinkText[T], parser: String => Box[T],
encoder: T => String): PreParamMenu[T] =
new PreParamMenu[T](name, linkText, parser, encoder)

def params[T](name: String, linkText: Loc.LinkText[T],
def params[T<:AnyRef](name: String, linkText: Loc.LinkText[T],
parser: List[String] => Box[T],
encoder: T => List[String]): PreParamsMenu[T] =
new PreParamsMenu[T](name, linkText, parser, encoder)
Expand Down

0 comments on commit 0b5068b

Please sign in to comment.