commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1413424 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/clustering/EuclideanIntegerPoint.java
Date Sun, 25 Nov 2012 21:23:32 GMT
Author: tn
Date: Sun Nov 25 21:23:31 2012
New Revision: 1413424

URL: http://svn.apache.org/viewvc?rev=1413424&view=rev
Log:
Simplify hashCode/equals/toString methods by using appropriate methods from java.util.Arrays,
similar to EuclideanDoublePoint.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/clustering/EuclideanIntegerPoint.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/clustering/EuclideanIntegerPoint.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/clustering/EuclideanIntegerPoint.java?rev=1413424&r1=1413423&r2=1413424&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/clustering/EuclideanIntegerPoint.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/clustering/EuclideanIntegerPoint.java
Sun Nov 25 21:23:31 2012
@@ -18,6 +18,7 @@
 package org.apache.commons.math3.stat.clustering;
 
 import java.io.Serializable;
+import java.util.Arrays;
 import java.util.Collection;
 
 import org.apache.commons.math3.util.MathArrays;
@@ -77,26 +78,13 @@ public class EuclideanIntegerPoint imple
         if (!(other instanceof EuclideanIntegerPoint)) {
             return false;
         }
-        final int[] otherPoint = ((EuclideanIntegerPoint) other).getPoint();
-        if (point.length != otherPoint.length) {
-            return false;
-        }
-        for (int i = 0; i < point.length; i++) {
-            if (point[i] != otherPoint[i]) {
-                return false;
-            }
-        }
-        return true;
+        return Arrays.equals(point, ((EuclideanIntegerPoint) other).point);
     }
 
     /** {@inheritDoc} */
     @Override
     public int hashCode() {
-        int hashCode = 0;
-        for (Integer i : point) {
-            hashCode += i.hashCode() * 13 + 7;
-        }
-        return hashCode;
+        return Arrays.hashCode(point);
     }
 
     /**
@@ -105,16 +93,7 @@ public class EuclideanIntegerPoint imple
      */
     @Override
     public String toString() {
-        final StringBuilder buff = new StringBuilder("(");
-        final int[] coordinates = getPoint();
-        for (int i = 0; i < coordinates.length; i++) {
-            buff.append(coordinates[i]);
-            if (i < coordinates.length - 1) {
-                buff.append(",");
-            }
-        }
-        buff.append(")");
-        return buff.toString();
+        return Arrays.toString(point);
     }
 
 }



Mime
View raw message