diff --git a/findbugs-exclude-filter.xml b/findbugs-exclude-filter.xml index 2d39ca7ec..1d85f4847 100644 --- a/findbugs-exclude-filter.xml +++ b/findbugs-exclude-filter.xml @@ -43,6 +43,23 @@ + + + + + + + + + + + + + + + + + diff --git a/src/java/org/apache/commons/math/genetics/RandomKey.java b/src/java/org/apache/commons/math/genetics/RandomKey.java index 9dd771847..11315c310 100644 --- a/src/java/org/apache/commons/math/genetics/RandomKey.java +++ b/src/java/org/apache/commons/math/genetics/RandomKey.java @@ -148,7 +148,7 @@ public abstract class RandomKey extends AbstractListChromosome implem @Override protected boolean isSame(Chromosome another) { // type check - if (! (another instanceof RandomKey)) + if (! (another instanceof RandomKey)) return false; RandomKey anotherRk = (RandomKey) another; // size check diff --git a/src/java/org/apache/commons/math/genetics/RandomKeyMutation.java b/src/java/org/apache/commons/math/genetics/RandomKeyMutation.java index 8105e77d5..9d2060df8 100644 --- a/src/java/org/apache/commons/math/genetics/RandomKeyMutation.java +++ b/src/java/org/apache/commons/math/genetics/RandomKeyMutation.java @@ -37,7 +37,7 @@ public class RandomKeyMutation implements MutationPolicy { * {@link RandomKey} instance */ public Chromosome mutate(Chromosome original) { - if (!(original instanceof RandomKey)) { + if (!(original instanceof RandomKey)) { throw MathRuntimeException.createIllegalArgumentException( "RandomKeyMutation works only with RandomKeys, got " + original.getClass().getSimpleName()); diff --git a/src/java/org/apache/commons/math/linear/SparseFieldVector.java b/src/java/org/apache/commons/math/linear/SparseFieldVector.java index 3b04f04c3..7cbd19b95 100644 --- a/src/java/org/apache/commons/math/linear/SparseFieldVector.java +++ b/src/java/org/apache/commons/math/linear/SparseFieldVector.java @@ -181,7 +181,7 @@ public class SparseFieldVector> implements FieldVector /** {@inheritDoc} */ public FieldVector append(FieldVector v) { - if (v instanceof SparseFieldVector) { + if (v instanceof SparseFieldVector) { return append((SparseFieldVector) v); } else { return append(v.toArray()); @@ -438,7 +438,7 @@ public class SparseFieldVector> implements FieldVector /** {@inheritDoc} */ public FieldMatrix outerProduct(FieldVector v) throws IllegalArgumentException { - if(v instanceof SparseFieldVector) + if(v instanceof SparseFieldVector) return outerProduct((SparseFieldVector)v); else return outerProduct(v.toArray()); @@ -513,7 +513,7 @@ public class SparseFieldVector> implements FieldVector /** {@inheritDoc} */ public FieldVector subtract(FieldVector v) throws IllegalArgumentException { - if(v instanceof SparseFieldVector) + if(v instanceof SparseFieldVector) return subtract((SparseFieldVector)v); else return subtract(v.toArray()); @@ -573,7 +573,7 @@ public class SparseFieldVector> implements FieldVector /** {@inheritDoc} */ public FieldVector add(FieldVector v) throws IllegalArgumentException { - if (v instanceof SparseFieldVector) { + if (v instanceof SparseFieldVector) { return add((SparseFieldVector)v); } else { return add(v.toArray()); diff --git a/src/java/org/apache/commons/math/transform/FastFourierTransformer.java b/src/java/org/apache/commons/math/transform/FastFourierTransformer.java index 08712be92..3980ed749 100644 --- a/src/java/org/apache/commons/math/transform/FastFourierTransformer.java +++ b/src/java/org/apache/commons/math/transform/FastFourierTransformer.java @@ -613,11 +613,8 @@ public class FastFourierTransformer implements Serializable { * http://jcp.org/en/jsr/detail?id=83 * may require additional exception throws for other basic requirements. */ - private class MultiDimensionalComplexMatrix - implements Serializable, Cloneable { - - /** Serializable version identifier. */ - private static final long serialVersionUID = 0x564FCD47EBA8169BL; + private static class MultiDimensionalComplexMatrix + implements Cloneable { /** Size in all dimensions. */ protected int[] dimensionSize; diff --git a/src/java/org/apache/commons/math/util/ResizableDoubleArray.java b/src/java/org/apache/commons/math/util/ResizableDoubleArray.java index 5e0f492c2..49b138598 100644 --- a/src/java/org/apache/commons/math/util/ResizableDoubleArray.java +++ b/src/java/org/apache/commons/math/util/ResizableDoubleArray.java @@ -338,20 +338,20 @@ public class ResizableDoubleArray implements DoubleArray, Serializable { * expansionCriteria * * @param expansionFactor factor to be checked - * @param contractionCritera criteria to be checked + * @param contractionCriteria criteria to be checked * @throws IllegalArgumentException if the contractionCriteria is less than * the expansionCriteria. */ protected void checkContractExpand( - float contractionCritera, + float contractionCriteria, float expansionFactor) { - if (contractionCritera < expansionFactor) { + if (contractionCriteria < expansionFactor) { throw MathRuntimeException.createIllegalArgumentException( "contraction criteria ({0}) smaller than the expansion factor ({1}). This would " + "lead to a never ending loop of expansion and contraction as a newly expanded " + "internal storage array would immediately satisfy the criteria for contraction", - contractionCritera, expansionFactor); + contractionCriteria, expansionFactor); } if (contractionCriteria <= 1.0) { @@ -365,7 +365,7 @@ public class ResizableDoubleArray implements DoubleArray, Serializable { if (expansionFactor <= 1.0) { throw MathRuntimeException.createIllegalArgumentException( "expansion factor smaller than one ({0})", - contractionCriteria); + expansionFactor); } } @@ -648,7 +648,9 @@ public class ResizableDoubleArray implements DoubleArray, Serializable { */ public void setContractionCriteria(float contractionCriteria) { checkContractExpand(contractionCriteria, getExpansionFactor()); - this.contractionCriteria = contractionCriteria; + synchronized(this) { + this.contractionCriteria = contractionCriteria; + } } @@ -693,7 +695,9 @@ public class ResizableDoubleArray implements DoubleArray, Serializable { public void setExpansionFactor(float expansionFactor) { checkContractExpand(getContractionCriteria(), expansionFactor); // The check above verifies that the expansion factor is > 1.0; - this.expansionFactor = expansionFactor; + synchronized(this) { + this.expansionFactor = expansionFactor; + } } /** @@ -711,7 +715,9 @@ public class ResizableDoubleArray implements DoubleArray, Serializable { expansionMode, MULTIPLICATIVE_MODE, "MULTIPLICATIVE_MODE", ADDITIVE_MODE, "ADDITIVE_MODE"); } - this.expansionMode = expansionMode; + synchronized(this) { + this.expansionMode = expansionMode; + } } /** @@ -876,17 +882,15 @@ public class ResizableDoubleArray implements DoubleArray, Serializable { * @since 2.0 */ @Override - public int hashCode() { + public synchronized int hashCode() { int[] hashData = new int[7]; hashData[0] = new Float(expansionFactor).hashCode(); hashData[1] = new Float(contractionCriteria).hashCode(); hashData[2] = expansionMode; - synchronized(this) { hashData[3] = Arrays.hashCode(internalArray); hashData[4] = initialCapacity; hashData[5] = numElements; hashData[6] = startIndex; - } return Arrays.hashCode(hashData); } diff --git a/src/test/org/apache/commons/math/estimation/LevenbergMarquardtEstimatorTest.java b/src/test/org/apache/commons/math/estimation/LevenbergMarquardtEstimatorTest.java index af27e260a..806bb456a 100644 --- a/src/test/org/apache/commons/math/estimation/LevenbergMarquardtEstimatorTest.java +++ b/src/test/org/apache/commons/math/estimation/LevenbergMarquardtEstimatorTest.java @@ -793,18 +793,6 @@ public class LevenbergMarquardtEstimatorTest addMeasurement(new LocalMeasurement(x, y, w)); } - public double getA() { - return a.getEstimate(); - } - - public double getB() { - return b.getEstimate(); - } - - public double getC() { - return c.getEstimate(); - } - public double theoreticalValue(double x) { return ( (a.getEstimate() * x + b.getEstimate() ) * x + c.getEstimate()); } diff --git a/src/test/org/apache/commons/math/genetics/RandomKeyTest.java b/src/test/org/apache/commons/math/genetics/RandomKeyTest.java index 3224c9d02..5e2c0d2e6 100644 --- a/src/test/org/apache/commons/math/genetics/RandomKeyTest.java +++ b/src/test/org/apache/commons/math/genetics/RandomKeyTest.java @@ -28,14 +28,12 @@ public class RandomKeyTest { @Test(expected=IllegalArgumentException.class) public void testConstructor1() { - @SuppressWarnings("unused") - DummyRandomKey drk = new DummyRandomKey(new Double[] {0.2, 0.3, 1.2}); + new DummyRandomKey(new Double[] {0.2, 0.3, 1.2}); } @Test(expected=IllegalArgumentException.class) public void testConstructor2() { - @SuppressWarnings("unused") - DummyRandomKey drk = new DummyRandomKey(new Double[] {0.2, 0.3, -0.2}); + new DummyRandomKey(new Double[] {0.2, 0.3, -0.2}); } @Test diff --git a/src/test/org/apache/commons/math/linear/BlockFieldMatrixTest.java b/src/test/org/apache/commons/math/linear/BlockFieldMatrixTest.java index 2061fffc2..6a0dfd1cc 100644 --- a/src/test/org/apache/commons/math/linear/BlockFieldMatrixTest.java +++ b/src/test/org/apache/commons/math/linear/BlockFieldMatrixTest.java @@ -549,50 +549,50 @@ public final class BlockFieldMatrixTest extends TestCase { // test submatrix accessors public void testGetSubMatrix() { FieldMatrix m = new BlockFieldMatrix(subTestData); - checkGetSubMatrix(m, subRows23Cols00, 2 , 3 , 0, 0, false); - checkGetSubMatrix(m, subRows00Cols33, 0 , 0 , 3, 3, false); - checkGetSubMatrix(m, subRows01Cols23, 0 , 1 , 2, 3, false); - checkGetSubMatrix(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 }, false); - checkGetSubMatrix(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 }, false); - checkGetSubMatrix(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 }, false); - checkGetSubMatrix(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 }, false); - checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); - checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); - checkGetSubMatrix(m, null, 1, 0, 2, 4, true); - checkGetSubMatrix(m, null, -1, 1, 2, 2, true); - checkGetSubMatrix(m, null, 1, 0, 2, 2, true); - checkGetSubMatrix(m, null, 1, 0, 2, 4, true); - checkGetSubMatrix(m, null, new int[] {}, new int[] { 0 }, true); - checkGetSubMatrix(m, null, new int[] { 0 }, new int[] { 4 }, true); + checkGetSubMatrix(m, subRows23Cols00, 2 , 3 , 0, 0); + checkGetSubMatrix(m, subRows00Cols33, 0 , 0 , 3, 3); + checkGetSubMatrix(m, subRows01Cols23, 0 , 1 , 2, 3); + checkGetSubMatrix(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 }); + checkGetSubMatrix(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 }); + checkGetSubMatrix(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 }); + checkGetSubMatrix(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 }); + checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }); + checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }); + checkGetSubMatrix(m, null, 1, 0, 2, 4); + checkGetSubMatrix(m, null, -1, 1, 2, 2); + checkGetSubMatrix(m, null, 1, 0, 2, 2); + checkGetSubMatrix(m, null, 1, 0, 2, 4); + checkGetSubMatrix(m, null, new int[] {}, new int[] { 0 }); + checkGetSubMatrix(m, null, new int[] { 0 }, new int[] { 4 }); } private void checkGetSubMatrix(FieldMatrix m, Fraction[][] reference, - int startRow, int endRow, int startColumn, int endColumn, - boolean mustFail) { + int startRow, int endRow, int startColumn, int endColumn) { try { FieldMatrix sub = m.getSubMatrix(startRow, endRow, startColumn, endColumn); - assertEquals(new BlockFieldMatrix(reference), sub); - if (mustFail) { + if (reference != null) { + assertEquals(new BlockFieldMatrix(reference), sub); + } else { fail("Expecting MatrixIndexException"); } } catch (MatrixIndexException e) { - if (!mustFail) { + if (reference != null) { throw e; } } } private void checkGetSubMatrix(FieldMatrix m, Fraction[][] reference, - int[] selectedRows, int[] selectedColumns, - boolean mustFail) { + int[] selectedRows, int[] selectedColumns) { try { FieldMatrix sub = m.getSubMatrix(selectedRows, selectedColumns); - assertEquals(new BlockFieldMatrix(reference), sub); - if (mustFail) { - fail("Expecting MatrixIndexException"); + if (reference != null) { + assertEquals(new BlockFieldMatrix(reference), sub); + } else { + fail("Expecting MatrixIndexException"); } } catch (MatrixIndexException e) { - if (!mustFail) { + if (reference != null) { throw e; } } @@ -621,57 +621,57 @@ public final class BlockFieldMatrixTest extends TestCase { public void testCopySubMatrix() { FieldMatrix m = new BlockFieldMatrix(subTestData); - checkCopy(m, subRows23Cols00, 2 , 3 , 0, 0, false); - checkCopy(m, subRows00Cols33, 0 , 0 , 3, 3, false); - checkCopy(m, subRows01Cols23, 0 , 1 , 2, 3, false); - checkCopy(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 }, false); - checkCopy(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 }, false); - checkCopy(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 }, false); - checkCopy(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 }, false); - checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); - checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); + checkCopy(m, subRows23Cols00, 2 , 3 , 0, 0); + checkCopy(m, subRows00Cols33, 0 , 0 , 3, 3); + checkCopy(m, subRows01Cols23, 0 , 1 , 2, 3); + checkCopy(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 }); + checkCopy(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 }); + checkCopy(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 }); + checkCopy(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 }); + checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }); + checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }); - checkCopy(m, null, 1, 0, 2, 4, true); - checkCopy(m, null, -1, 1, 2, 2, true); - checkCopy(m, null, 1, 0, 2, 2, true); - checkCopy(m, null, 1, 0, 2, 4, true); - checkCopy(m, null, new int[] {}, new int[] { 0 }, true); - checkCopy(m, null, new int[] { 0 }, new int[] { 4 }, true); + checkCopy(m, null, 1, 0, 2, 4); + checkCopy(m, null, -1, 1, 2, 2); + checkCopy(m, null, 1, 0, 2, 2); + checkCopy(m, null, 1, 0, 2, 4); + checkCopy(m, null, new int[] {}, new int[] { 0 }); + checkCopy(m, null, new int[] { 0 }, new int[] { 4 }); } private void checkCopy(FieldMatrix m, Fraction[][] reference, - int startRow, int endRow, int startColumn, int endColumn, - boolean mustFail) { + int startRow, int endRow, int startColumn, int endColumn) { try { Fraction[][] sub = (reference == null) ? new Fraction[1][1] : new Fraction[reference.length][reference[0].length]; m.copySubMatrix(startRow, endRow, startColumn, endColumn, sub); - assertEquals(new BlockFieldMatrix(reference), new BlockFieldMatrix(sub)); - if (mustFail) { - fail("Expecting MatrixIndexException"); + if (reference != null) { + assertEquals(new BlockFieldMatrix(reference), new BlockFieldMatrix(sub)); + } else { + fail("Expecting MatrixIndexException"); } } catch (MatrixIndexException e) { - if (!mustFail) { + if (reference != null) { throw e; } } } private void checkCopy(FieldMatrix m, Fraction[][] reference, - int[] selectedRows, int[] selectedColumns, - boolean mustFail) { + int[] selectedRows, int[] selectedColumns) { try { Fraction[][] sub = (reference == null) ? new Fraction[1][1] : new Fraction[reference.length][reference[0].length]; m.copySubMatrix(selectedRows, selectedColumns, sub); - assertEquals(new BlockFieldMatrix(reference), new BlockFieldMatrix(sub)); - if (mustFail) { - fail("Expecting MatrixIndexException"); + if (reference != null) { + assertEquals(new BlockFieldMatrix(reference), new BlockFieldMatrix(sub)); + } else { + fail("Expecting MatrixIndexException"); } } catch (MatrixIndexException e) { - if (!mustFail) { + if (reference != null) { throw e; } } diff --git a/src/test/org/apache/commons/math/linear/BlockRealMatrixTest.java b/src/test/org/apache/commons/math/linear/BlockRealMatrixTest.java index 88278bc78..67a0aa4b6 100644 --- a/src/test/org/apache/commons/math/linear/BlockRealMatrixTest.java +++ b/src/test/org/apache/commons/math/linear/BlockRealMatrixTest.java @@ -476,50 +476,50 @@ public final class BlockRealMatrixTest extends TestCase { // test submatrix accessors public void testGetSubMatrix() { RealMatrix m = new BlockRealMatrix(subTestData); - checkGetSubMatrix(m, subRows23Cols00, 2 , 3 , 0, 0, false); - checkGetSubMatrix(m, subRows00Cols33, 0 , 0 , 3, 3, false); - checkGetSubMatrix(m, subRows01Cols23, 0 , 1 , 2, 3, false); - checkGetSubMatrix(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 }, false); - checkGetSubMatrix(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 }, false); - checkGetSubMatrix(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 }, false); - checkGetSubMatrix(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 }, false); - checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); - checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); - checkGetSubMatrix(m, null, 1, 0, 2, 4, true); - checkGetSubMatrix(m, null, -1, 1, 2, 2, true); - checkGetSubMatrix(m, null, 1, 0, 2, 2, true); - checkGetSubMatrix(m, null, 1, 0, 2, 4, true); - checkGetSubMatrix(m, null, new int[] {}, new int[] { 0 }, true); - checkGetSubMatrix(m, null, new int[] { 0 }, new int[] { 4 }, true); + checkGetSubMatrix(m, subRows23Cols00, 2 , 3 , 0, 0); + checkGetSubMatrix(m, subRows00Cols33, 0 , 0 , 3, 3); + checkGetSubMatrix(m, subRows01Cols23, 0 , 1 , 2, 3); + checkGetSubMatrix(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 }); + checkGetSubMatrix(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 }); + checkGetSubMatrix(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 }); + checkGetSubMatrix(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 }); + checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }); + checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }); + checkGetSubMatrix(m, null, 1, 0, 2, 4); + checkGetSubMatrix(m, null, -1, 1, 2, 2); + checkGetSubMatrix(m, null, 1, 0, 2, 2); + checkGetSubMatrix(m, null, 1, 0, 2, 4); + checkGetSubMatrix(m, null, new int[] {}, new int[] { 0 }); + checkGetSubMatrix(m, null, new int[] { 0 }, new int[] { 4 }); } private void checkGetSubMatrix(RealMatrix m, double[][] reference, - int startRow, int endRow, int startColumn, int endColumn, - boolean mustFail) { + int startRow, int endRow, int startColumn, int endColumn) { try { RealMatrix sub = m.getSubMatrix(startRow, endRow, startColumn, endColumn); - assertEquals(new BlockRealMatrix(reference), sub); - if (mustFail) { - fail("Expecting MatrixIndexException"); + if (reference != null) { + assertEquals(new BlockRealMatrix(reference), sub); + } else { + fail("Expecting MatrixIndexException"); } } catch (MatrixIndexException e) { - if (!mustFail) { + if (reference != null) { throw e; } } } private void checkGetSubMatrix(RealMatrix m, double[][] reference, - int[] selectedRows, int[] selectedColumns, - boolean mustFail) { + int[] selectedRows, int[] selectedColumns) { try { RealMatrix sub = m.getSubMatrix(selectedRows, selectedColumns); - assertEquals(new BlockRealMatrix(reference), sub); - if (mustFail) { - fail("Expecting MatrixIndexException"); + if (reference != null) { + assertEquals(new BlockRealMatrix(reference), sub); + } else { + fail("Expecting MatrixIndexException"); } } catch (MatrixIndexException e) { - if (!mustFail) { + if (reference != null) { throw e; } } @@ -546,57 +546,57 @@ public final class BlockRealMatrixTest extends TestCase { public void testCopySubMatrix() { RealMatrix m = new BlockRealMatrix(subTestData); - checkCopy(m, subRows23Cols00, 2 , 3 , 0, 0, false); - checkCopy(m, subRows00Cols33, 0 , 0 , 3, 3, false); - checkCopy(m, subRows01Cols23, 0 , 1 , 2, 3, false); - checkCopy(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 }, false); - checkCopy(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 }, false); - checkCopy(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 }, false); - checkCopy(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 }, false); - checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); - checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); + checkCopy(m, subRows23Cols00, 2 , 3 , 0, 0); + checkCopy(m, subRows00Cols33, 0 , 0 , 3, 3); + checkCopy(m, subRows01Cols23, 0 , 1 , 2, 3); + checkCopy(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 }); + checkCopy(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 }); + checkCopy(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 }); + checkCopy(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 }); + checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }); + checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }); - checkCopy(m, null, 1, 0, 2, 4, true); - checkCopy(m, null, -1, 1, 2, 2, true); - checkCopy(m, null, 1, 0, 2, 2, true); - checkCopy(m, null, 1, 0, 2, 4, true); - checkCopy(m, null, new int[] {}, new int[] { 0 }, true); - checkCopy(m, null, new int[] { 0 }, new int[] { 4 }, true); + checkCopy(m, null, 1, 0, 2, 4); + checkCopy(m, null, -1, 1, 2, 2); + checkCopy(m, null, 1, 0, 2, 2); + checkCopy(m, null, 1, 0, 2, 4); + checkCopy(m, null, new int[] {}, new int[] { 0 }); + checkCopy(m, null, new int[] { 0 }, new int[] { 4 }); } private void checkCopy(RealMatrix m, double[][] reference, - int startRow, int endRow, int startColumn, int endColumn, - boolean mustFail) { + int startRow, int endRow, int startColumn, int endColumn) { try { double[][] sub = (reference == null) ? new double[1][1] : new double[reference.length][reference[0].length]; m.copySubMatrix(startRow, endRow, startColumn, endColumn, sub); - assertEquals(new BlockRealMatrix(reference), new BlockRealMatrix(sub)); - if (mustFail) { - fail("Expecting MatrixIndexException"); + if (reference != null) { + assertEquals(new BlockRealMatrix(reference), new BlockRealMatrix(sub)); + } else { + fail("Expecting MatrixIndexException"); } } catch (MatrixIndexException e) { - if (!mustFail) { + if (reference != null) { throw e; } } } private void checkCopy(RealMatrix m, double[][] reference, - int[] selectedRows, int[] selectedColumns, - boolean mustFail) { + int[] selectedRows, int[] selectedColumns) { try { double[][] sub = (reference == null) ? new double[1][1] : new double[reference.length][reference[0].length]; m.copySubMatrix(selectedRows, selectedColumns, sub); - assertEquals(new BlockRealMatrix(reference), new BlockRealMatrix(sub)); - if (mustFail) { - fail("Expecting MatrixIndexException"); + if (reference != null) { + assertEquals(new BlockRealMatrix(reference), new BlockRealMatrix(sub)); + } else { + fail("Expecting MatrixIndexException"); } } catch (MatrixIndexException e) { - if (!mustFail) { + if (reference != null) { throw e; } } diff --git a/src/test/org/apache/commons/math/linear/EigenDecompositionImplTest.java b/src/test/org/apache/commons/math/linear/EigenDecompositionImplTest.java index d0c5b8bcd..4a56dbad7 100644 --- a/src/test/org/apache/commons/math/linear/EigenDecompositionImplTest.java +++ b/src/test/org/apache/commons/math/linear/EigenDecompositionImplTest.java @@ -293,13 +293,13 @@ public class EigenDecompositionImplTest extends TestCase { boolean found = false; int i = 0; while (!found && i < searchMatrix.getColumnDimension()) { - double multiplier = 1d; + double multiplier = 1.0; boolean matching = true; int j = 0; while (matching && j < searchMatrix.getRowDimension()) { double colEntry = searchMatrix.getEntry(j, i); // Use the first entry where both are non-zero as scalar - if (multiplier == 1d && Math.abs(colEntry) > 1E-14 + if (Math.abs(multiplier - 1.0) <= Math.ulp(1.0) && Math.abs(colEntry) > 1E-14 && Math.abs(column[j]) > 1e-14) { multiplier = colEntry / column[j]; } diff --git a/src/test/org/apache/commons/math/linear/FieldMatrixImplTest.java b/src/test/org/apache/commons/math/linear/FieldMatrixImplTest.java index d51cb2ca1..bd48469eb 100644 --- a/src/test/org/apache/commons/math/linear/FieldMatrixImplTest.java +++ b/src/test/org/apache/commons/math/linear/FieldMatrixImplTest.java @@ -363,50 +363,50 @@ public final class FieldMatrixImplTest extends TestCase { // test submatrix accessors public void testGetSubMatrix() { FieldMatrix m = new Array2DRowFieldMatrix(subTestData); - checkGetSubMatrix(m, subRows23Cols00, 2 , 3 , 0, 0, false); - checkGetSubMatrix(m, subRows00Cols33, 0 , 0 , 3, 3, false); - checkGetSubMatrix(m, subRows01Cols23, 0 , 1 , 2, 3, false); - checkGetSubMatrix(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 }, false); - checkGetSubMatrix(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 }, false); - checkGetSubMatrix(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 }, false); - checkGetSubMatrix(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 }, false); - checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); - checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); - checkGetSubMatrix(m, null, 1, 0, 2, 4, true); - checkGetSubMatrix(m, null, -1, 1, 2, 2, true); - checkGetSubMatrix(m, null, 1, 0, 2, 2, true); - checkGetSubMatrix(m, null, 1, 0, 2, 4, true); - checkGetSubMatrix(m, null, new int[] {}, new int[] { 0 }, true); - checkGetSubMatrix(m, null, new int[] { 0 }, new int[] { 4 }, true); + checkGetSubMatrix(m, subRows23Cols00, 2 , 3 , 0, 0); + checkGetSubMatrix(m, subRows00Cols33, 0 , 0 , 3, 3); + checkGetSubMatrix(m, subRows01Cols23, 0 , 1 , 2, 3); + checkGetSubMatrix(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 }); + checkGetSubMatrix(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 }); + checkGetSubMatrix(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 }); + checkGetSubMatrix(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 }); + checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }); + checkGetSubMatrix(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }); + checkGetSubMatrix(m, null, 1, 0, 2, 4); + checkGetSubMatrix(m, null, -1, 1, 2, 2); + checkGetSubMatrix(m, null, 1, 0, 2, 2); + checkGetSubMatrix(m, null, 1, 0, 2, 4); + checkGetSubMatrix(m, null, new int[] {}, new int[] { 0 }); + checkGetSubMatrix(m, null, new int[] { 0 }, new int[] { 4 }); } private void checkGetSubMatrix(FieldMatrix m, Fraction[][] reference, - int startRow, int endRow, int startColumn, int endColumn, - boolean mustFail) { + int startRow, int endRow, int startColumn, int endColumn) { try { FieldMatrix sub = m.getSubMatrix(startRow, endRow, startColumn, endColumn); - assertEquals(new Array2DRowFieldMatrix(reference), sub); - if (mustFail) { - fail("Expecting MatrixIndexException"); + if (reference != null) { + assertEquals(new Array2DRowFieldMatrix(reference), sub); + } else { + fail("Expecting MatrixIndexException"); } } catch (MatrixIndexException e) { - if (!mustFail) { + if (reference != null) { throw e; } } } private void checkGetSubMatrix(FieldMatrix m, Fraction[][] reference, - int[] selectedRows, int[] selectedColumns, - boolean mustFail) { + int[] selectedRows, int[] selectedColumns) { try { FieldMatrix sub = m.getSubMatrix(selectedRows, selectedColumns); - assertEquals(new Array2DRowFieldMatrix(reference), sub); - if (mustFail) { - fail("Expecting MatrixIndexException"); + if (reference != null) { + assertEquals(new Array2DRowFieldMatrix(reference), sub); + } else { + fail("Expecting MatrixIndexException"); } } catch (MatrixIndexException e) { - if (!mustFail) { + if (reference != null) { throw e; } } @@ -414,57 +414,57 @@ public final class FieldMatrixImplTest extends TestCase { public void testCopySubMatrix() { FieldMatrix m = new Array2DRowFieldMatrix(subTestData); - checkCopy(m, subRows23Cols00, 2 , 3 , 0, 0, false); - checkCopy(m, subRows00Cols33, 0 , 0 , 3, 3, false); - checkCopy(m, subRows01Cols23, 0 , 1 , 2, 3, false); - checkCopy(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 }, false); - checkCopy(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 }, false); - checkCopy(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 }, false); - checkCopy(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 }, false); - checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); - checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }, false); + checkCopy(m, subRows23Cols00, 2 , 3 , 0, 0); + checkCopy(m, subRows00Cols33, 0 , 0 , 3, 3); + checkCopy(m, subRows01Cols23, 0 , 1 , 2, 3); + checkCopy(m, subRows02Cols13, new int[] { 0, 2 }, new int[] { 1, 3 }); + checkCopy(m, subRows03Cols12, new int[] { 0, 3 }, new int[] { 1, 2 }); + checkCopy(m, subRows03Cols123, new int[] { 0, 3 }, new int[] { 1, 2, 3 }); + checkCopy(m, subRows20Cols123, new int[] { 2, 0 }, new int[] { 1, 2, 3 }); + checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }); + checkCopy(m, subRows31Cols31, new int[] { 3, 1 }, new int[] { 3, 1 }); - checkCopy(m, null, 1, 0, 2, 4, true); - checkCopy(m, null, -1, 1, 2, 2, true); - checkCopy(m, null, 1, 0, 2, 2, true); - checkCopy(m, null, 1, 0, 2, 4, true); - checkCopy(m, null, new int[] {}, new int[] { 0 }, true); - checkCopy(m, null, new int[] { 0 }, new int[] { 4 }, true); + checkCopy(m, null, 1, 0, 2, 4); + checkCopy(m, null, -1, 1, 2, 2); + checkCopy(m, null, 1, 0, 2, 2); + checkCopy(m, null, 1, 0, 2, 4); + checkCopy(m, null, new int[] {}, new int[] { 0 }); + checkCopy(m, null, new int[] { 0 }, new int[] { 4 }); } private void checkCopy(FieldMatrix m, Fraction[][] reference, - int startRow, int endRow, int startColumn, int endColumn, - boolean mustFail) { + int startRow, int endRow, int startColumn, int endColumn) { try { Fraction[][] sub = (reference == null) ? new Fraction[1][1] : new Fraction[reference.length][reference[0].length]; m.copySubMatrix(startRow, endRow, startColumn, endColumn, sub); - assertEquals(new Array2DRowFieldMatrix(reference), new Array2DRowFieldMatrix(sub)); - if (mustFail) { - fail("Expecting MatrixIndexException"); + if (reference != null) { + assertEquals(new Array2DRowFieldMatrix(reference), new Array2DRowFieldMatrix(sub)); + } else { + fail("Expecting MatrixIndexException"); } } catch (MatrixIndexException e) { - if (!mustFail) { + if (reference != null) { throw e; } } } private void checkCopy(FieldMatrix m, Fraction[][] reference, - int[] selectedRows, int[] selectedColumns, - boolean mustFail) { + int[] selectedRows, int[] selectedColumns) { try { Fraction[][] sub = (reference == null) ? new Fraction[1][1] : new Fraction[reference.length][reference[0].length]; m.copySubMatrix(selectedRows, selectedColumns, sub); - assertEquals(new Array2DRowFieldMatrix(reference), new Array2DRowFieldMatrix(sub)); - if (mustFail) { - fail("Expecting MatrixIndexException"); + if (reference != null) { + assertEquals(new Array2DRowFieldMatrix(reference), new Array2DRowFieldMatrix(sub)); + } else { + fail("Expecting MatrixIndexException"); } } catch (MatrixIndexException e) { - if (!mustFail) { + if (reference != null) { throw e; } } diff --git a/src/test/org/apache/commons/math/linear/SparseFieldMatrixTest.java b/src/test/org/apache/commons/math/linear/SparseFieldMatrixTest.java index 22f43205c..e4377f3c8 100644 --- a/src/test/org/apache/commons/math/linear/SparseFieldMatrixTest.java +++ b/src/test/org/apache/commons/math/linear/SparseFieldMatrixTest.java @@ -149,11 +149,11 @@ public class SparseFieldMatrixTest extends TestCase { public void testCopyFunctions() { SparseFieldMatrix m1 = createSparseMatrix(testData); FieldMatrix m2 = m1.copy(); - assertTrue(m2 instanceof SparseFieldMatrix); + assertEquals(m1.getClass(), m2.getClass()); assertEquals((m2), m1); SparseFieldMatrix m3 = createSparseMatrix(testData); FieldMatrix m4 = m3.copy(); - assertTrue(m4 instanceof SparseFieldMatrix); + assertEquals(m3.getClass(), m4.getClass()); assertEquals((m4), m3); } diff --git a/src/test/org/apache/commons/math/linear/SparseRealMatrixTest.java b/src/test/org/apache/commons/math/linear/SparseRealMatrixTest.java index 3b7a4f3dd..727deee8f 100644 --- a/src/test/org/apache/commons/math/linear/SparseRealMatrixTest.java +++ b/src/test/org/apache/commons/math/linear/SparseRealMatrixTest.java @@ -130,11 +130,11 @@ public final class SparseRealMatrixTest extends TestCase { public void testCopyFunctions() { OpenMapRealMatrix m1 = createSparseMatrix(testData); RealMatrix m2 = m1.copy(); - assertTrue(m2 instanceof OpenMapRealMatrix); + assertEquals(m1.getClass(), m2.getClass()); assertEquals((m2), m1); OpenMapRealMatrix m3 = createSparseMatrix(testData); RealMatrix m4 = m3.copy(); - assertTrue(m4 instanceof OpenMapRealMatrix); + assertEquals(m3.getClass(), m4.getClass()); assertEquals((m4), m3); } diff --git a/src/test/org/apache/commons/math/ode/TestProblem1.java b/src/test/org/apache/commons/math/ode/TestProblem1.java index 54a4b46ba..0e64548cf 100644 --- a/src/test/org/apache/commons/math/ode/TestProblem1.java +++ b/src/test/org/apache/commons/math/ode/TestProblem1.java @@ -62,12 +62,8 @@ public class TestProblem1 y = problem.y.clone(); } - /** - * Clone operation. - * @return a copy of the instance - */ - @Override - public Object clone() { + /** {@inheritDoc} */ + public TestProblem1 copy() { return new TestProblem1(this); } diff --git a/src/test/org/apache/commons/math/ode/TestProblem2.java b/src/test/org/apache/commons/math/ode/TestProblem2.java index abd8a2e8b..9e2cf20cc 100644 --- a/src/test/org/apache/commons/math/ode/TestProblem2.java +++ b/src/test/org/apache/commons/math/ode/TestProblem2.java @@ -63,12 +63,8 @@ public class TestProblem2 y = problem.y.clone(); } - /** - * Clone operation. - * @return a copy of the instance - */ - @Override - public Object clone() { + /** {@inheritDoc} */ + public TestProblem2 copy() { return new TestProblem2(this); } diff --git a/src/test/org/apache/commons/math/ode/TestProblem3.java b/src/test/org/apache/commons/math/ode/TestProblem3.java index dfee1f472..7c888c911 100644 --- a/src/test/org/apache/commons/math/ode/TestProblem3.java +++ b/src/test/org/apache/commons/math/ode/TestProblem3.java @@ -78,12 +78,8 @@ public class TestProblem3 y = problem.y.clone(); } - /** - * Clone operation. - * @return a copy of the instance - */ - @Override - public Object clone() { + /** {@inheritDoc} */ + public TestProblem3 copy() { return new TestProblem3(this); } diff --git a/src/test/org/apache/commons/math/ode/TestProblem4.java b/src/test/org/apache/commons/math/ode/TestProblem4.java index ca3b223d4..ba24cec11 100644 --- a/src/test/org/apache/commons/math/ode/TestProblem4.java +++ b/src/test/org/apache/commons/math/ode/TestProblem4.java @@ -68,12 +68,8 @@ public class TestProblem4 y = problem.y.clone(); } - /** - * Clone operation. - * @return a copy of the instance - */ - @Override - public Object clone() { + /** {@inheritDoc} */ + public TestProblem4 copy() { return new TestProblem4(this); } diff --git a/src/test/org/apache/commons/math/ode/TestProblem5.java b/src/test/org/apache/commons/math/ode/TestProblem5.java index 99b66dff6..95d1009d8 100644 --- a/src/test/org/apache/commons/math/ode/TestProblem5.java +++ b/src/test/org/apache/commons/math/ode/TestProblem5.java @@ -35,5 +35,9 @@ public class TestProblem5 super(); setFinalConditions(2 * t0 - t1); } - + + /** {@inheritDoc} */ + public TestProblem5 copy() { + return new TestProblem5(); + } } diff --git a/src/test/org/apache/commons/math/ode/TestProblem6.java b/src/test/org/apache/commons/math/ode/TestProblem6.java index 2c5d45ea1..d588f8009 100644 --- a/src/test/org/apache/commons/math/ode/TestProblem6.java +++ b/src/test/org/apache/commons/math/ode/TestProblem6.java @@ -63,13 +63,9 @@ public class TestProblem6 y = problem.y.clone(); } - /** - * Clone operation. - * @return a copy of the instance - */ - @Override - public Object clone() { - return new TestProblem6(this); + /** {@inheritDoc} */ + public TestProblem6 copy() { + return new TestProblem6(this); } @Override diff --git a/src/test/org/apache/commons/math/ode/TestProblemAbstract.java b/src/test/org/apache/commons/math/ode/TestProblemAbstract.java index 850597bd4..c6d4bb901 100644 --- a/src/test/org/apache/commons/math/ode/TestProblemAbstract.java +++ b/src/test/org/apache/commons/math/ode/TestProblemAbstract.java @@ -25,7 +25,7 @@ import org.apache.commons.math.ode.events.EventHandler; * integrated during the junit tests for the ODE integrators. */ public abstract class TestProblemAbstract - implements FirstOrderDifferentialEquations, Cloneable { + implements FirstOrderDifferentialEquations { /** Serializable version identifier. */ private static final long serialVersionUID = -8521928974502839379L; @@ -82,11 +82,10 @@ public abstract class TestProblemAbstract } /** - * Clone operation. + * Copy operation. * @return a copy of the instance */ - @Override - public abstract Object clone(); + public abstract TestProblemAbstract copy(); /** * Set the initial conditions diff --git a/src/test/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaIntegratorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaIntegratorTest.java index 3bb675371..cd23aff05 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaIntegratorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaIntegratorTest.java @@ -83,7 +83,7 @@ public class ClassicalRungeKuttaIntegratorTest double previousError = Double.NaN; for (int i = 4; i < 10; ++i) { - TestProblemAbstract pb = (TestProblemAbstract) problems[k].clone(); + TestProblemAbstract pb = problems[k].copy(); double step = (pb.getFinalTime() - pb.getInitialTime()) * Math.pow(2.0, -i); FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step); diff --git a/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java index bcf41e0b1..fb6eddb69 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java @@ -230,7 +230,7 @@ public class DormandPrince853IntegratorTest public void testNoDenseOutput() throws DerivativeException, IntegratorException { TestProblem1 pb1 = new TestProblem1(); - TestProblem1 pb2 = (TestProblem1) pb1.clone(); + TestProblem1 pb2 = pb1.copy(); double minStep = 0.1 * (pb1.getFinalTime() - pb1.getInitialTime()); double maxStep = pb1.getFinalTime() - pb1.getInitialTime(); double scalAbsoluteTolerance = 1.0e-4; diff --git a/src/test/org/apache/commons/math/ode/nonstiff/EulerIntegratorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/EulerIntegratorTest.java index b739c5ae4..ac4fb7a06 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/EulerIntegratorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/EulerIntegratorTest.java @@ -62,7 +62,7 @@ public class EulerIntegratorTest double previousError = Double.NaN; for (int i = 4; i < 10; ++i) { - TestProblemAbstract pb = (TestProblemAbstract) problems[k].clone(); + TestProblemAbstract pb = problems[k].copy(); double step = (pb.getFinalTime() - pb.getInitialTime()) * Math.pow(2.0, -i); diff --git a/src/test/org/apache/commons/math/ode/nonstiff/GillIntegratorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/GillIntegratorTest.java index 8855385a1..fce8de0cb 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/GillIntegratorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/GillIntegratorTest.java @@ -63,7 +63,7 @@ public class GillIntegratorTest double previousError = Double.NaN; for (int i = 5; i < 10; ++i) { - TestProblemAbstract pb = (TestProblemAbstract) problems[k].clone(); + TestProblemAbstract pb = problems[k].copy(); double step = (pb.getFinalTime() - pb.getInitialTime()) * Math.pow(2.0, -i); diff --git a/src/test/org/apache/commons/math/ode/nonstiff/MidpointIntegratorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/MidpointIntegratorTest.java index 4ce9a4aae..8e35e6a96 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/MidpointIntegratorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/MidpointIntegratorTest.java @@ -62,7 +62,7 @@ public class MidpointIntegratorTest double previousError = Double.NaN; for (int i = 4; i < 10; ++i) { - TestProblemAbstract pb = (TestProblemAbstract) problems[k].clone(); + TestProblemAbstract pb = problems[k].copy(); double step = (pb.getFinalTime() - pb.getInitialTime()) * Math.pow(2.0, -i); FirstOrderIntegrator integ = new MidpointIntegrator(step); diff --git a/src/test/org/apache/commons/math/ode/nonstiff/ThreeEighthesIntegratorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/ThreeEighthesIntegratorTest.java index 27c5ba46e..40a7ef360 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/ThreeEighthesIntegratorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/ThreeEighthesIntegratorTest.java @@ -63,7 +63,7 @@ public class ThreeEighthesIntegratorTest double previousError = Double.NaN; for (int i = 4; i < 10; ++i) { - TestProblemAbstract pb = (TestProblemAbstract) problems[k].clone(); + TestProblemAbstract pb = problems[k].copy(); double step = (pb.getFinalTime() - pb.getInitialTime()) * Math.pow(2.0, -i); diff --git a/src/test/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java b/src/test/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java index 61a51bfce..951995b7e 100644 --- a/src/test/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java +++ b/src/test/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java @@ -128,15 +128,15 @@ public class DummyStepInterpolatorTest { } private static class BadStepInterpolator extends DummyStepInterpolator { - public BadStepInterpolator() { - super(); - } - public BadStepInterpolator(double[] y, boolean forward) { - super(y, forward); - } - @Override - protected void doFinalize() - throws DerivativeException { + @SuppressWarnings("unused") + public BadStepInterpolator() { + } + public BadStepInterpolator(double[] y, boolean forward) { + super(y, forward); + } + @Override + protected void doFinalize() + throws DerivativeException { throw new DerivativeException(null); } } diff --git a/src/test/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizerTest.java b/src/test/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizerTest.java index 4250e5074..2d4ac43d9 100644 --- a/src/test/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizerTest.java +++ b/src/test/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizerTest.java @@ -59,7 +59,7 @@ public class MultiStartMultivariateRealOptimizerTest { } - private class Rosenbrock implements MultivariateRealFunction { + private static class Rosenbrock implements MultivariateRealFunction { private int count; diff --git a/src/test/org/apache/commons/math/optimization/direct/NelderMeadTest.java b/src/test/org/apache/commons/math/optimization/direct/NelderMeadTest.java index 05c872705..18afaafab 100644 --- a/src/test/org/apache/commons/math/optimization/direct/NelderMeadTest.java +++ b/src/test/org/apache/commons/math/optimization/direct/NelderMeadTest.java @@ -204,7 +204,7 @@ public class NelderMeadTest { } } - private class Rosenbrock implements MultivariateRealFunction { + private static class Rosenbrock implements MultivariateRealFunction { private int count; @@ -225,7 +225,7 @@ public class NelderMeadTest { } - private class Powell implements MultivariateRealFunction { + private static class Powell implements MultivariateRealFunction { private int count; diff --git a/src/test/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java b/src/test/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java index 3e2637bf5..c532ecd7f 100644 --- a/src/test/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java +++ b/src/test/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java @@ -434,8 +434,7 @@ public class LevenbergMarquardtOptimizerTest Arrays.fill(target, 0.0); double[] weights = new double[circle.getN()]; Arrays.fill(weights, 2.0); - optimum = - optimizer.optimize(circle, target, weights, new double[] { 98.680, 47.345 }); + optimizer.optimize(circle, target, weights, new double[] { 98.680, 47.345 }); cov = optimizer.getCovariances(); assertEquals(0.0016, cov[0][0], 0.001); assertEquals(3.2e-7, cov[0][1], 1.0e-9); diff --git a/src/test/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizerTest.java b/src/test/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizerTest.java index b2bb31e7a..1cf1e7794 100644 --- a/src/test/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizerTest.java +++ b/src/test/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizerTest.java @@ -429,10 +429,6 @@ extends TestCase { points.add(new Point2D.Double(px, py)); } - public int getN() { - return points.size(); - } - public double getRadius(Point2D.Double center) { double r = 0; for (Point2D.Double point : points) { diff --git a/src/test/org/apache/commons/math/stat/ranking/NaturalRankingTest.java b/src/test/org/apache/commons/math/stat/ranking/NaturalRankingTest.java index c3ae13d8f..1c293cb48 100644 --- a/src/test/org/apache/commons/math/stat/ranking/NaturalRankingTest.java +++ b/src/test/org/apache/commons/math/stat/ranking/NaturalRankingTest.java @@ -199,5 +199,6 @@ public class NaturalRankingTest extends TestCase { ranking = new NaturalRanking(NaNStrategy.MINIMAL); ranks = ranking.rank(data); correctRanks = new double[] { 3, 4, 1.5, 1.5 }; + TestUtils.assertEquals(correctRanks, ranks, 0d); } } diff --git a/src/test/org/apache/commons/math/util/MathUtilsTest.java b/src/test/org/apache/commons/math/util/MathUtilsTest.java index 124710cd6..d048f5f71 100644 --- a/src/test/org/apache/commons/math/util/MathUtilsTest.java +++ b/src/test/org/apache/commons/math/util/MathUtilsTest.java @@ -52,7 +52,7 @@ public final class MathUtilsTest extends TestCase { */ private long binomialCoefficient(int n, int k) throws ArithmeticException { if (binomialCache.size() > n) { - Long cachedResult = binomialCache.get(n).get(new Integer(k)); + Long cachedResult = binomialCache.get(n).get(Integer.valueOf(k)); if (cachedResult != null) { return cachedResult.longValue(); } @@ -80,7 +80,7 @@ public final class MathUtilsTest extends TestCase { for (int i = binomialCache.size(); i < n + 1; i++) { binomialCache.add(new HashMap()); } - binomialCache.get(n).put(new Integer(k), new Long(result)); + binomialCache.get(n).put(Integer.valueOf(k), Long.valueOf(result)); return result; }