You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bi...@apache.org on 2009/05/04 04:55:22 UTC
svn commit: r771164 - in
/commons/proper/math/trunk/src/java/org/apache/commons/math/linear:
SparseFieldVector.java SparseRealVector.java
Author: billbarker
Date: Mon May 4 02:55:21 2009
New Revision: 771164
URL: http://svn.apache.org/viewvc?rev=771164&view=rev
Log:
Adding equals and hashCode
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseFieldVector.java
commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealVector.java
Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseFieldVector.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseFieldVector.java?rev=771164&r1=771163&r2=771164&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseFieldVector.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseFieldVector.java Mon May 4 02:55:21 2009
@@ -90,7 +90,6 @@
entries = new OpenIntToFieldHashMap<T> (field,expectedSize);
}
-
/**
* Create from a Field array.
* Only non-zero entries will be stored
@@ -581,5 +580,59 @@
}
+ /** {@inheritDoc} */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((field == null) ? 0 : field.hashCode());
+ result = prime * result + virtualSize;
+ OpenIntToFieldHashMap<T>.Iterator iter = entries.iterator();
+ while (iter.hasNext()) {
+ iter.advance();
+ int temp = iter.value().hashCode();
+ result = prime * result + temp;
+ }
+ return result;
+ }
+
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof SparseFieldVector))
+ return false;
+ SparseFieldVector<T> other = (SparseFieldVector<T>) obj;
+ if (field == null) {
+ if (other.field != null)
+ return false;
+ } else if (!field.equals(other.field))
+ return false;
+ if (virtualSize != other.virtualSize)
+ return false;
+ OpenIntToFieldHashMap<T>.Iterator iter = entries.iterator();
+ while (iter.hasNext()) {
+ iter.advance();
+ T test = other.getEntry(iter.key());
+ if (!test.equals(iter.value())) {
+ return false;
+ }
+ }
+ iter = other.getEntries().iterator();
+ while (iter.hasNext()) {
+ iter.advance();
+ T test = iter.value();
+ if (!test.equals(getEntry(iter.key()))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+
}
Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealVector.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealVector.java?rev=771164&r1=771163&r2=771164&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealVector.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/linear/SparseRealVector.java Mon May 4 02:55:21 2009
@@ -1290,7 +1290,7 @@
while (iter.hasNext()) {
iter.advance();
double test = iter.value();
- if (Double.doubleToLongBits(test) != Double.doubleToLongBits(iter.value())) {
+ if (Double.doubleToLongBits(test) != Double.doubleToLongBits(getEntry(iter.key()))) {
return false;
}
}