You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by br...@apache.org on 2004/02/16 21:54:13 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/broker/core MtoNBroker.java ValueContainer.java
brj 2004/02/16 12:54:13
Modified: src/java/org/apache/ojb/broker/core MtoNBroker.java
ValueContainer.java
Log:
improved equals() and hashCode()
Revision Changes Path
1.5 +29 -15 db-ojb/src/java/org/apache/ojb/broker/core/MtoNBroker.java
Index: MtoNBroker.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/MtoNBroker.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MtoNBroker.java 20 Dec 2003 16:36:35 -0000 1.4
+++ MtoNBroker.java 16 Feb 2004 20:54:13 -0000 1.5
@@ -54,6 +54,14 @@
* <http://www.apache.org/>.
*/
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.ojb.broker.MtoNImplementor;
import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.PersistenceBrokerException;
@@ -68,13 +76,6 @@
import org.apache.ojb.broker.util.logging.Logger;
import org.apache.ojb.broker.util.logging.LoggerFactory;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Vector;
-
/**
* Manage all stuff related to non-decomposed M:N association.
*
@@ -308,7 +309,7 @@
/**
* This is a helper class to model a Key of an Object
*/
- private final class Key
+ private static final class Key
{
final ValueContainer[] m_containers;
@@ -338,15 +339,28 @@
public boolean equals(Object other)
{
- boolean result = false;
-
- if (other instanceof Key)
+ if (other == this)
+ {
+ return true;
+ }
+ if (!(other instanceof Key))
{
- Key otherKey = (Key)other;
- result = Arrays.equals(m_containers, otherKey.m_containers);
+ return false;
}
+
+ Key otherKey = (Key) other;
+ EqualsBuilder eb = new EqualsBuilder();
+
+ eb.append(m_containers, otherKey.m_containers);
+ return eb.isEquals();
+ }
+
+ public int hashCode()
+ {
+ HashCodeBuilder hb = new HashCodeBuilder();
+ hb.append(m_containers);
- return result;
+ return hb.toHashCode();
}
}
}
1.4 +6 -4 db-ojb/src/java/org/apache/ojb/broker/core/ValueContainer.java
Index: ValueContainer.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/ValueContainer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ValueContainer.java 20 Dec 2003 16:07:54 -0000 1.3
+++ ValueContainer.java 16 Feb 2004 20:54:13 -0000 1.4
@@ -49,14 +49,16 @@
public boolean equals(Object obj)
{
- if (obj instanceof ValueContainer)
+ if (obj == this)
{
- return m_value.equals(((ValueContainer)obj).m_value);
+ return true;
}
- else
+ if (!(obj instanceof ValueContainer))
{
return false;
}
+
+ return m_value.equals(((ValueContainer)obj).m_value);
}
public int hashCode()
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org