Skip to content

Commit 1684862

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

18 files changed

+50
-814
lines changed

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

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -155,36 +155,4 @@ public void incrementAll(double[] values, int begin, int length) throws MathIlle
155155
}
156156
}
157157
}
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-
}
190158
}

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 & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -362,54 +362,6 @@ public void clear() {
362362
covarianceImpl.clear();
363363
}
364364

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-
413365
// Getters and setters for statistics implementations
414366
/**
415367
* Sets statistics implementations.

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

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -794,53 +794,4 @@ private boolean shouldContract() {
794794
public ResizableDoubleArray copy() {
795795
return new ResizableDoubleArray(this);
796796
}
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-
}
846797
}

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

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -120,47 +120,6 @@ public double getVariance() {
120120
return variance;
121121
}
122122

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-
164123
/**
165124
* Generates a text report displaying values of statistics.
166125
* 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 & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -307,47 +307,6 @@ private static void clear(StorelessUnivariateStatistic s) {
307307
}
308308
}
309309

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-
351310
// Getters and setters for statistics implementations
352311

353312
/**

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
*/

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

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -110,38 +110,4 @@ public void clear() {
110110
Arrays.fill(sums, 0.0);
111111
Arrays.fill(productsSums, 0.0);
112112
}
113-
114-
/** {@inheritDoc} */
115-
@Override
116-
public int hashCode() {
117-
final int prime = 31;
118-
int result = 1;
119-
result = prime * result + (isBiasCorrected ? 1231 : 1237);
120-
result = prime * result + (int) (n ^ (n >>> 32));
121-
result = prime * result + Arrays.hashCode(productsSums);
122-
result = prime * result + Arrays.hashCode(sums);
123-
return result;
124-
}
125-
126-
/** {@inheritDoc} */
127-
@Override
128-
public boolean equals(Object obj) {
129-
if (this == obj) {
130-
return true;
131-
}
132-
if (!(obj instanceof VectorialCovariance)) {
133-
return false;
134-
}
135-
VectorialCovariance other = (VectorialCovariance) obj;
136-
if (isBiasCorrected != other.isBiasCorrected) {
137-
return false;
138-
}
139-
if (n != other.n) {
140-
return false;
141-
}
142-
if (!Arrays.equals(productsSums, other.productsSums)) {
143-
return false;
144-
}
145-
return Arrays.equals(sums, other.sums);
146-
}
147113
}

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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,26 +74,4 @@ public double[] getResult() {
7474
public long getN() {
7575
return (means.length == 0) ? 0 : n;
7676
}
77-
78-
/** {@inheritDoc} */
79-
@Override
80-
public int hashCode() {
81-
final int prime = 31;
82-
int result = 1;
83-
result = prime * result + Arrays.hashCode(getResult());
84-
return result;
85-
}
86-
87-
/** {@inheritDoc} */
88-
@Override
89-
public boolean equals(Object obj) {
90-
if (this == obj) {
91-
return true;
92-
}
93-
if (!(obj instanceof VectorialMean)) {
94-
return false;
95-
}
96-
VectorialMean other = (VectorialMean) obj;
97-
return Arrays.equals(getResult(), other.getResult());
98-
}
9977
}

0 commit comments

Comments
 (0)