Revision: 14854
http://gate.svn.sourceforge.net/gate/?rev=14854&view=rev
Author: markagreenwood
Date: 2011-12-23 18:00:55 +0000 (Fri, 23 Dec 2011)
Log Message:
-----------
make sure that if we have custom equals methods we also have hashCode methods,
just in case someone tries storing these things somewhere weird
Modified Paths:
--------------
gate/trunk/src/gate/creole/gazetteer/GazetteerList.java
gate/trunk/src/gate/creole/gazetteer/GazetteerNode.java
gate/trunk/src/gate/creole/gazetteer/LinearDefinition.java
gate/trunk/src/gate/creole/gazetteer/LinearNode.java
gate/trunk/src/gate/creole/gazetteer/MappingDefinition.java
gate/trunk/src/gate/creole/ontology/DataType.java
gate/trunk/src/gate/security/SessionImpl.java
Modified: gate/trunk/src/gate/creole/gazetteer/GazetteerList.java
===================================================================
--- gate/trunk/src/gate/creole/gazetteer/GazetteerList.java 2011-12-23
08:27:22 UTC (rev 14853)
+++ gate/trunk/src/gate/creole/gazetteer/GazetteerList.java 2011-12-23
18:00:55 UTC (rev 14854)
@@ -311,19 +311,26 @@
entries.clear();
}
-
- public boolean equals(Object o) {
- boolean result = false;
- if (o instanceof GazetteerList) {
- result = true;
- GazetteerList list2 = (GazetteerList) o;
- result &= entries.equals(list2.entries);
- } // if
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((entries == null) ? 0 : entries.hashCode());
return result;
- } // equals()
+ }
+ @Override
+ public boolean equals(Object obj) {
+ if(this == obj) return true;
+ if(obj == null) return false;
+ if(getClass() != obj.getClass()) return false;
+ GazetteerList other = (GazetteerList)obj;
+ if(entries == null) {
+ if(other.entries != null) return false;
+ } else if(!entries.equals(other.entries)) return false;
+ return true;
+ }
-
public Object get(int index) {
return entries.get(index);
}
Modified: gate/trunk/src/gate/creole/gazetteer/GazetteerNode.java
===================================================================
--- gate/trunk/src/gate/creole/gazetteer/GazetteerNode.java 2011-12-23
08:27:22 UTC (rev 14853)
+++ gate/trunk/src/gate/creole/gazetteer/GazetteerNode.java 2011-12-23
18:00:55 UTC (rev 14854)
@@ -215,6 +215,10 @@
}
return result;
}
+
+ public int hashCode() {
+ return toString().hashCode();
+ }
/**
* @return the entry
Modified: gate/trunk/src/gate/creole/gazetteer/LinearDefinition.java
===================================================================
--- gate/trunk/src/gate/creole/gazetteer/LinearDefinition.java 2011-12-23
08:27:22 UTC (rev 14853)
+++ gate/trunk/src/gate/creole/gazetteer/LinearDefinition.java 2011-12-23
18:00:55 UTC (rev 14854)
@@ -514,17 +514,36 @@
gazListsByNode.clear();
isModified = true;
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((lists == null) ? 0 : lists.hashCode());
+ result = prime * result + ((nodes == null) ? 0 : nodes.hashCode());
+ result =
+ prime * result
+ + ((nodesByList == null) ? 0 : nodesByList.hashCode());
+ return result;
+ }
- public boolean equals(Object o) {
- if ( o instanceof LinearDefinition ) {
- LinearDefinition def = (LinearDefinition) o;
- return nodes.equals(def.nodes) &&
- lists.equals(def.lists) &&
- nodesByList.equals(def.nodesByList);
- } else {
- return false;
- }
- } // equals()
+ @Override
+ public boolean equals(Object obj) {
+ if(this == obj) return true;
+ if(obj == null) return false;
+ if(getClass() != obj.getClass()) return false;
+ LinearDefinition other = (LinearDefinition)obj;
+ if(lists == null) {
+ if(other.lists != null) return false;
+ } else if(!lists.equals(other.lists)) return false;
+ if(nodes == null) {
+ if(other.nodes != null) return false;
+ } else if(!nodes.equals(other.nodes)) return false;
+ if(nodesByList == null) {
+ if(other.nodesByList != null) return false;
+ } else if(!nodesByList.equals(other.nodesByList)) return false;
+ return true;
+ }
/*---end of implementation of interface java.util.List---*/
@@ -534,7 +553,7 @@
/*-----------internal classes -------------*/
- /**SafeIterator class provides an iterator which is safe to be iterated and
objects removed from it*/
+/**SafeIterator class provides an iterator which is safe to be iterated and
objects removed from it*/
private class SafeIterator implements Iterator {
private Iterator iter = LinearDefinition.this.nodes.iterator();
private boolean removeCalled = false;
Modified: gate/trunk/src/gate/creole/gazetteer/LinearNode.java
===================================================================
--- gate/trunk/src/gate/creole/gazetteer/LinearNode.java 2011-12-23
08:27:22 UTC (rev 14853)
+++ gate/trunk/src/gate/creole/gazetteer/LinearNode.java 2011-12-23
18:00:55 UTC (rev 14854)
@@ -140,28 +140,36 @@
return result;
}
- /**Checks this node vs another one for equality.
- * @param o another node
- * @return true if languages,list,major type and minor type match.*/
- public boolean equals(Object o) {
- boolean result = false;
- if ( o instanceof LinearNode ) {
- LinearNode node = (LinearNode) o;
- result = true;
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((language == null) ? 0 : language.hashCode());
+ result = prime * result + ((list == null) ? 0 : list.hashCode());
+ result = prime * result + ((major == null) ? 0 : major.hashCode());
+ result = prime * result + ((minor == null) ? 0 : minor.hashCode());
+ return result;
+ }
- if (null != this.getLanguage())
- result &= this.getLanguage().equals(node.getLanguage());
-
- if ( null != this.getList())
- result &= this.getList().equals(node.getList());
-
- if ( null!=this.getMajorType())
- result &= this.getMajorType().equals(node.getMajorType());
-
- if ( null!= this.getMinorType())
- result &= this.getMinorType().equals(node.getMinorType());
- }
- return result;
+ @Override
+ public boolean equals(Object obj) {
+ if(this == obj) return true;
+ if(obj == null) return false;
+ if(getClass() != obj.getClass()) return false;
+ LinearNode other = (LinearNode)obj;
+ if(language == null) {
+ if(other.language != null) return false;
+ } else if(!language.equals(other.language)) return false;
+ if(list == null) {
+ if(other.list != null) return false;
+ } else if(!list.equals(other.list)) return false;
+ if(major == null) {
+ if(other.major != null) return false;
+ } else if(!major.equals(other.major)) return false;
+ if(minor == null) {
+ if(other.minor != null) return false;
+ } else if(!minor.equals(other.minor)) return false;
+ return true;
}
} // class LinearNode
\ No newline at end of file
Modified: gate/trunk/src/gate/creole/gazetteer/MappingDefinition.java
===================================================================
--- gate/trunk/src/gate/creole/gazetteer/MappingDefinition.java 2011-12-23
08:27:22 UTC (rev 14853)
+++ gate/trunk/src/gate/creole/gazetteer/MappingDefinition.java 2011-12-23
18:00:55 UTC (rev 14854)
@@ -298,17 +298,36 @@
nodesByList.clear();
}
- public boolean equals(Object o) {
- if ( o instanceof MappingDefinition ) {
- MappingDefinition def = (MappingDefinition) o;
- return nodes.equals(def.nodes) &&
- lists.equals(def.lists) &&
- nodesByList.equals(def.nodesByList);
- } else {
- return false;
- }
- } // equals()
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((lists == null) ? 0 : lists.hashCode());
+ result = prime * result + ((nodes == null) ? 0 : nodes.hashCode());
+ result =
+ prime * result
+ + ((nodesByList == null) ? 0 : nodesByList.hashCode());
+ return result;
+ }
+ @Override
+ public boolean equals(Object obj) {
+ if(this == obj) return true;
+ if(obj == null) return false;
+ if(getClass() != obj.getClass()) return false;
+ MappingDefinition other = (MappingDefinition)obj;
+ if(lists == null) {
+ if(other.lists != null) return false;
+ } else if(!lists.equals(other.lists)) return false;
+ if(nodes == null) {
+ if(other.nodes != null) return false;
+ } else if(!nodes.equals(other.nodes)) return false;
+ if(nodesByList == null) {
+ if(other.nodesByList != null) return false;
+ } else if(!nodesByList.equals(other.nodesByList)) return false;
+ return true;
+ }
+
public List subList(int i1, int i2) {
return nodes.subList(i1,i2);
}
Modified: gate/trunk/src/gate/creole/ontology/DataType.java
===================================================================
--- gate/trunk/src/gate/creole/ontology/DataType.java 2011-12-23 08:27:22 UTC
(rev 14853)
+++ gate/trunk/src/gate/creole/ontology/DataType.java 2011-12-23 18:00:55 UTC
(rev 14854)
@@ -375,6 +375,11 @@
}
return false;
}
+
+ @Override
+ public int hashCode() {
+ return getXmlSchemaURIString().hashCode();
+ }
/**
* Checks whether the provided value is a valid value for the datatype
Modified: gate/trunk/src/gate/security/SessionImpl.java
===================================================================
--- gate/trunk/src/gate/security/SessionImpl.java 2011-12-23 08:27:22 UTC
(rev 14853)
+++ gate/trunk/src/gate/security/SessionImpl.java 2011-12-23 18:00:55 UTC
(rev 14854)
@@ -97,23 +97,32 @@
return this.timeout;
}
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ return result;
+ }
/**
- *
- * this one is necessary for the contains() operations in Lists
- * It is possible that two users have two different GroupImpl that refer
- * to the very same GATE group in the DB, because they got it from the
security
- * factory at different times. So we assume that two instances refer the
same
- * GATE group if NAME1==NAME2
- *
- * */
- public boolean equals(Object obj)
- {
- Assert.assertTrue(obj instanceof Session);
-
- Session s2 = (Session)obj;
-
- return (this.id.equals(s2.getID()));
+ *
+ * this one is necessary for the contains() operations in Lists
+ * It is possible that two users have two different GroupImpl that refer
+ * to the very same GATE group in the DB, because they got it from the
security
+ * factory at different times. So we assume that two instances refer the same
+ * GATE group if NAME1==NAME2
+ *
+ * */
+ @Override
+ public boolean equals(Object obj) {
+ if(this == obj) return true;
+ if(obj == null) return false;
+ if(getClass() != obj.getClass()) return false;
+ SessionImpl other = (SessionImpl)obj;
+ if(id == null) {
+ if(other.id != null) return false;
+ } else if(!id.equals(other.id)) return false;
+ return true;
}
-
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create
new or port existing apps to sell to consumers worldwide. Explore the
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs