Skip to content

Commit 5fd1193

Browse files
committed
MATH-1671: Remove equals and hashcode implementations
1 parent dba20b8 commit 5fd1193

18 files changed

+52
-834
lines changed

commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/AbstractStorelessUnivariateStatistic.java

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.apache.commons.math4.legacy.exception.NullArgumentException;
2121
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
2222
import org.apache.commons.math4.legacy.core.MathArrays;
23-
import org.apache.commons.numbers.core.Precision;
2423

2524
/**
2625
* Abstract base class for implementations of the
@@ -155,36 +154,4 @@ public void incrementAll(double[] values, int begin, int length) throws MathIlle
155154
}
156155
}
157156
}
158-
159-
/**
160-
* Returns true iff <code>object</code> is the same type of
161-
* {@link StorelessUnivariateStatistic} (the object's class equals this
162-
* instance) returning the same values as this for <code>getResult()</code>
163-
* and <code>getN()</code>.
164-
*
165-
* @param object object to test equality against.
166-
* @return true if object returns the same value as this
167-
*/
168-
@Override
169-
public boolean equals(Object object) {
170-
if (object == this ) {
171-
return true;
172-
}
173-
if (object == null || object.getClass() != this.getClass()) {
174-
return false;
175-
}
176-
StorelessUnivariateStatistic stat = (StorelessUnivariateStatistic) object;
177-
return Precision.equalsIncludingNaN(stat.getResult(), this.getResult()) &&
178-
Precision.equalsIncludingNaN(stat.getN(), this.getN());
179-
}
180-
181-
/**
182-
* Returns hash code based on getResult() and getN().
183-
*
184-
* @return hash code
185-
*/
186-
@Override
187-
public int hashCode() {
188-
return 31 * (31 + Double.hashCode(getResult())) + Double.hashCode(getN());
189-
}
190157
}

commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/AggregateSummaryStatistics.java

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -329,34 +329,5 @@ public void addValue(double value) {
329329
aggregateStatistics.addValue(value);
330330
}
331331
}
332-
333-
/**
334-
* Returns true iff <code>object</code> is a
335-
* <code>SummaryStatistics</code> instance and all statistics have the
336-
* same values as this.
337-
* @param object the object to test equality against.
338-
* @return true if object equals this
339-
*/
340-
@Override
341-
public boolean equals(Object object) {
342-
if (object == this) {
343-
return true;
344-
}
345-
if (!(object instanceof AggregatingSummaryStatistics)) {
346-
return false;
347-
}
348-
AggregatingSummaryStatistics stat = (AggregatingSummaryStatistics)object;
349-
return super.equals(stat) &&
350-
aggregateStatistics.equals(stat.aggregateStatistics);
351-
}
352-
353-
/**
354-
* Returns hash code based on values of statistics.
355-
* @return hash code
356-
*/
357-
@Override
358-
public int hashCode() {
359-
return 123 + super.hashCode() + aggregateStatistics.hashCode();
360-
}
361332
}
362333
}

commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/MultivariateSummaryStatistics.java

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
import org.apache.commons.math4.legacy.stat.descriptive.Statistics.StorelessSumOfLogs;
3232
import org.apache.commons.math4.legacy.stat.descriptive.Statistics.StorelessSumOfSquares;
3333
import org.apache.commons.math4.core.jdkmath.JdkMath;
34-
import org.apache.commons.math4.legacy.core.MathArrays;
35-
import org.apache.commons.numbers.core.Precision;
3634

3735
/**
3836
* <p>Computes summary statistics for a stream of n-tuples added using the
@@ -362,54 +360,6 @@ public void clear() {
362360
covarianceImpl.clear();
363361
}
364362

365-
/**
366-
* Returns true iff <code>object</code> is a <code>MultivariateSummaryStatistics</code>
367-
* instance and all statistics have the same values as this.
368-
* @param object the object to test equality against.
369-
* @return true if object equals this
370-
*/
371-
@Override
372-
public boolean equals(Object object) {
373-
if (object == this ) {
374-
return true;
375-
}
376-
if (!(object instanceof MultivariateSummaryStatistics)) {
377-
return false;
378-
}
379-
MultivariateSummaryStatistics stat = (MultivariateSummaryStatistics) object;
380-
return MathArrays.equalsIncludingNaN(stat.getGeometricMean(), getGeometricMean()) &&
381-
MathArrays.equalsIncludingNaN(stat.getMax(), getMax()) &&
382-
MathArrays.equalsIncludingNaN(stat.getMean(), getMean()) &&
383-
MathArrays.equalsIncludingNaN(stat.getMin(), getMin()) &&
384-
Precision.equalsIncludingNaN(stat.getN(), getN()) &&
385-
MathArrays.equalsIncludingNaN(stat.getSum(), getSum()) &&
386-
MathArrays.equalsIncludingNaN(stat.getSumSq(), getSumSq()) &&
387-
MathArrays.equalsIncludingNaN(stat.getSumLog(), getSumLog()) &&
388-
stat.getCovariance().equals( getCovariance());
389-
}
390-
391-
/**
392-
* Returns hash code based on values of statistics.
393-
*
394-
* @return hash code
395-
*/
396-
@Override
397-
public int hashCode() {
398-
// This does not have to use all the statistics.
399-
// Here we avoid duplicate use of stats that are related.
400-
// - sum-of-logs; geometric mean
401-
// - mean; sum + n
402-
// - variance; sum-of-squares + sum + n
403-
int result = 31 + Arrays.hashCode(getSumLog());
404-
result = result * 31 + Arrays.hashCode(getMax());
405-
result = result * 31 + Arrays.hashCode(getMin());
406-
result = result * 31 + Double.hashCode(getN());
407-
result = result * 31 + Arrays.hashCode(getSum());
408-
result = result * 31 + Arrays.hashCode(getSumSq());
409-
result = result * 31 + getCovariance().hashCode();
410-
return result;
411-
}
412-
413363
// Getters and setters for statistics implementations
414364
/**
415365
* Sets statistics implementations.

commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/ResizableDoubleArray.java

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
*/
1717
package org.apache.commons.math4.legacy.stat.descriptive;
1818

19-
import java.util.Arrays;
20-
2119
import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException;
2220
import org.apache.commons.math4.legacy.exception.MathIllegalStateException;
2321
import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException;
@@ -794,53 +792,4 @@ private boolean shouldContract() {
794792
public ResizableDoubleArray copy() {
795793
return new ResizableDoubleArray(this);
796794
}
797-
798-
/**
799-
* Returns true iff object is a ResizableDoubleArray with the same properties
800-
* as this and an identical internal storage array.
801-
*
802-
* @param object object to be compared for equality with this
803-
* @return true iff object is a ResizableDoubleArray with the same data and
804-
* properties as this
805-
* @since 2.0
806-
*/
807-
@Override
808-
public boolean equals(Object object) {
809-
if (object == this ) {
810-
return true;
811-
}
812-
if (!(object instanceof ResizableDoubleArray)) {
813-
return false;
814-
}
815-
boolean result = true;
816-
final ResizableDoubleArray other = (ResizableDoubleArray) object;
817-
result = result && other.contractionCriterion == contractionCriterion;
818-
result = result && other.expansionFactor == expansionFactor;
819-
result = result && other.expansionMode == expansionMode;
820-
result = result && other.numElements == numElements;
821-
result = result && other.startIndex == startIndex;
822-
if (!result) {
823-
return false;
824-
} else {
825-
return Arrays.equals(internalArray, other.internalArray);
826-
}
827-
}
828-
829-
/**
830-
* Returns a hash code consistent with equals.
831-
*
832-
* @return the hash code representing this {@code ResizableDoubleArray}.
833-
* @since 2.0
834-
*/
835-
@Override
836-
public int hashCode() {
837-
final int[] hashData = new int[6];
838-
hashData[0] = Double.valueOf(expansionFactor).hashCode();
839-
hashData[1] = Double.valueOf(contractionCriterion).hashCode();
840-
hashData[2] = expansionMode.hashCode();
841-
hashData[3] = Arrays.hashCode(internalArray);
842-
hashData[4] = numElements;
843-
hashData[5] = startIndex;
844-
return Arrays.hashCode(hashData);
845-
}
846795
}

commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/StatisticalSummaryValues.java

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717
package org.apache.commons.math4.legacy.stat.descriptive;
1818

1919
import org.apache.commons.math4.core.jdkmath.JdkMath;
20-
import org.apache.commons.numbers.core.Precision;
2120

2221
/**
23-
* Value object representing the results of a univariate statistical summary.
24-
*
22+
* Value object representing the results of a univariate statistical summary.
2523
*/
2624
public class StatisticalSummaryValues
2725
implements StatisticalSummary {
@@ -120,47 +118,6 @@ public double getVariance() {
120118
return variance;
121119
}
122120

123-
/**
124-
* Returns true iff <code>object</code> is a
125-
* <code>StatisticalSummaryValues</code> instance and all statistics have
126-
* the same values as this.
127-
*
128-
* @param object the object to test equality against.
129-
* @return true if object equals this
130-
*/
131-
@Override
132-
public boolean equals(Object object) {
133-
if (object == this ) {
134-
return true;
135-
}
136-
if (!(object instanceof StatisticalSummaryValues)) {
137-
return false;
138-
}
139-
StatisticalSummaryValues stat = (StatisticalSummaryValues) object;
140-
return Precision.equalsIncludingNaN(stat.getMax(), getMax()) &&
141-
Precision.equalsIncludingNaN(stat.getMean(), getMean()) &&
142-
Precision.equalsIncludingNaN(stat.getMin(), getMin()) &&
143-
Precision.equalsIncludingNaN(stat.getN(), getN()) &&
144-
Precision.equalsIncludingNaN(stat.getSum(), getSum()) &&
145-
Precision.equalsIncludingNaN(stat.getVariance(), getVariance());
146-
}
147-
148-
/**
149-
* Returns hash code based on values of statistics.
150-
*
151-
* @return hash code
152-
*/
153-
@Override
154-
public int hashCode() {
155-
int result = 31 + Double.hashCode(getMax());
156-
result = result * 31 + Double.hashCode(getMean());
157-
result = result * 31 + Double.hashCode(getMin());
158-
result = result * 31 + Double.hashCode(getN());
159-
result = result * 31 + Double.hashCode(getSum());
160-
result = result * 31 + Double.hashCode(getVariance());
161-
return result;
162-
}
163-
164121
/**
165122
* Generates a text report displaying values of statistics.
166123
* Each statistic is displayed on a separate line.

commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SummaryStatistics.java

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.apache.commons.math4.legacy.exception.MathIllegalStateException;
2424
import org.apache.commons.math4.legacy.exception.NullArgumentException;
2525
import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
26-
import org.apache.commons.numbers.core.Precision;
2726
import org.apache.commons.statistics.descriptive.DoubleStatistics;
2827
import org.apache.commons.statistics.descriptive.Statistic;
2928

@@ -307,47 +306,6 @@ private static void clear(StorelessUnivariateStatistic s) {
307306
}
308307
}
309308

310-
/**
311-
* Returns true iff <code>object</code> is a
312-
* <code>SummaryStatistics</code> instance and all statistics have the
313-
* same values as this.
314-
* @param object the object to test equality against.
315-
* @return true if object equals this
316-
*/
317-
@Override
318-
public boolean equals(Object object) {
319-
if (object == this) {
320-
return true;
321-
}
322-
if (!(object instanceof SummaryStatistics)) {
323-
return false;
324-
}
325-
SummaryStatistics stat = (SummaryStatistics)object;
326-
return Precision.equalsIncludingNaN(stat.getMax(), getMax()) &&
327-
Precision.equalsIncludingNaN(stat.getMean(), getMean()) &&
328-
Precision.equalsIncludingNaN(stat.getMin(), getMin()) &&
329-
Precision.equalsIncludingNaN(stat.getN(), getN()) &&
330-
Precision.equalsIncludingNaN(stat.getSum(), getSum()) &&
331-
Precision.equalsIncludingNaN(stat.getVariance(), getVariance());
332-
}
333-
334-
/**
335-
* Returns hash code based on values of statistics.
336-
* @return hash code
337-
*/
338-
@Override
339-
public int hashCode() {
340-
// This does not have to use all the statistics.
341-
// Here we avoid duplicate use of stats that are related.
342-
// - mean; sum + n
343-
int result = 31 + Double.hashCode(getMax());
344-
result = result * 31 + Double.hashCode(getMin());
345-
result = result * 31 + Double.hashCode(getN());
346-
result = result * 31 + Double.hashCode(getSum());
347-
result = result * 31 + Double.hashCode(getVariance());
348-
return result;
349-
}
350-
351309
// Getters and setters for statistics implementations
352310

353311
/**

commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SynchronizedMultivariateSummaryStatistics.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -156,22 +156,6 @@ public synchronized void clear() {
156156
super.clear();
157157
}
158158

159-
/**
160-
* {@inheritDoc}
161-
*/
162-
@Override
163-
public synchronized boolean equals(Object object) {
164-
return super.equals(object);
165-
}
166-
167-
/**
168-
* {@inheritDoc}
169-
*/
170-
@Override
171-
public synchronized int hashCode() {
172-
return super.hashCode();
173-
}
174-
175159
/**
176160
* {@inheritDoc}
177161
*/

commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/SynchronizedSummaryStatistics.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,22 +138,6 @@ public synchronized void clear() {
138138
super.clear();
139139
}
140140

141-
/**
142-
* {@inheritDoc}
143-
*/
144-
@Override
145-
public synchronized boolean equals(Object object) {
146-
return super.equals(object);
147-
}
148-
149-
/**
150-
* {@inheritDoc}
151-
*/
152-
@Override
153-
public synchronized int hashCode() {
154-
return super.hashCode();
155-
}
156-
157141
/**
158142
* {@inheritDoc}
159143
*/

0 commit comments

Comments
 (0)