Author: apetrelli
Date: Thu May 7 21:41:52 2009
New Revision: 772784
URL: http://svn.apache.org/viewvc?rev=772784&view=rev
Log:
TILES-411
Fixed equals method and added "hashCode".
Modified:
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/Attribute.java
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/CompareUtil.java
Modified:
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/Attribute.java
URL:
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/Attribute.java?rev=772784&r1=772783&r2=772784&view=diff
==============================================================================
---
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/Attribute.java
(original)
+++
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/Attribute.java
Thu May 7 21:41:52 2009
@@ -244,7 +244,7 @@
* @param role Asociated role.
* @param type Attribute type.
* @deprecated Use
- * {...@link Attribute#Attribute(Object, String, String)))}.
+ * {...@link Attribute#Attribute(Object, String, String, String)}.
*/
public Attribute(String name, Object value, String role,
AttributeType type) {
@@ -406,7 +406,7 @@
* Sets the type of this attribute.
*
* @param type The attribute type.
- * @deprecated Use {...@link Attribute#setRenderer(String))}.
+ * @deprecated Use {...@link Attribute#setRenderer(String)}.
*/
public void setType(AttributeType type) {
this.renderer = type.toString();
@@ -498,8 +498,15 @@
public boolean equals(Object obj) {
Attribute attribute = (Attribute) obj;
return nullSafeEquals(value, attribute.value)
- || nullSafeEquals(renderer, attribute.renderer)
- || nullSafeEquals(roles, attribute.roles)
- || nullSafeEquals(expression, attribute.expression);
+ && nullSafeEquals(renderer, attribute.renderer)
+ && nullSafeEquals(roles, attribute.roles)
+ && nullSafeEquals(expression, attribute.expression);
+ }
+
+ /** {...@inheritdoc} */
+ @Override
+ public int hashCode() {
+ return nullSafeHashCode(value) + nullSafeHashCode(renderer)
+ + nullSafeHashCode(roles) + nullSafeHashCode(expression);
}
}
Modified:
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/CompareUtil.java
URL:
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/CompareUtil.java?rev=772784&r1=772783&r2=772784&view=diff
==============================================================================
---
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/CompareUtil.java
(original)
+++
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/CompareUtil.java
Thu May 7 21:41:52 2009
@@ -1,13 +1,67 @@
+/*
+ * $Id: Tiles2ToolTest.java 765774 2009-04-16 21:43:00Z apetrelli $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
package org.apache.tiles;
+/**
+ * Utilities to work with comparation between objects.
+ *
+ * @version $Rev$ $Date$
+ * @since 2.2.0
+ */
public final class CompareUtil {
+ /**
+ * Private constructor to avoid instantiation.
+ */
private CompareUtil() {}
+ /**
+ * Checks if two objects (eventually null) are the same. They are
considered the same
+ * even if they are both null.
+ *
+ * @param obj1 The first object to check.
+ * @param obj2 The second object to check.
+ * @return <code>true</code> if the objects are the same.
+ * @since 2.2.0
+ */
public static boolean nullSafeEquals(Object obj1, Object obj2) {
if (obj1 != null) {
return obj1.equals(obj2);
}
return obj2 == null;
}
+
+ /**
+ * Returns <code>0</code> if the object is null, the hash code of the
object
+ * otherwise.
+ *
+ * @param obj The object from which the hash code must be calculated..
+ * @return The hash code.
+ * @since 2.2.0
+ */
+ public static int nullSafeHashCode(Object obj) {
+ if (obj != null) {
+ return obj.hashCode();
+ }
+ return 0;
+ }
}