New method "getCapacity". Deprecated "getInternalLength".


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1408280 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gilles Sadowski 2012-11-12 13:33:26 +00:00
parent 6080bc88a8
commit de9e8b8c78
2 changed files with 32 additions and 18 deletions

View File

@ -632,11 +632,25 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
* of the public interface of this class. * of the public interface of this class.
* *
* @return the length of the internal storage array. * @return the length of the internal storage array.
* @deprecated As of 3.1. Please use {@link #getCapacity()} instead.
*/ */
@Deprecated
synchronized int getInternalLength() { synchronized int getInternalLength() {
return internalArray.length; return internalArray.length;
} }
/**
* Gets the currently allocated size of the internal data structure used
* for storing elements.
* This is not to be confused with {@link #getNumElements() the number of
* elements actually stored}.
*
* @return the length of the internal array.
*/
public int getCapacity() {
return internalArray.length;
}
/** /**
* Returns the number of elements currently in the array. Please note * Returns the number of elements currently in the array. Please note
* that this is different from the length of the internal storage array. * that this is different from the length of the internal storage array.

View File

@ -52,7 +52,7 @@ public class ResizableDoubleArrayTest extends DoubleArrayAbstractTest {
ResizableDoubleArray testDa = new ResizableDoubleArray(2); ResizableDoubleArray testDa = new ResizableDoubleArray(2);
Assert.assertEquals(0, testDa.getNumElements()); Assert.assertEquals(0, testDa.getNumElements());
Assert.assertEquals(2, testDa.getInternalLength()); Assert.assertEquals(2, testDa.getCapacity());
Assert.assertEquals(defaultExpansionFactor, testDa.getExpansionFactor(), 0); Assert.assertEquals(defaultExpansionFactor, testDa.getExpansionFactor(), 0);
Assert.assertEquals(defaultContractionCriteria, testDa.getContractionCriteria(), 0); Assert.assertEquals(defaultContractionCriteria, testDa.getContractionCriteria(), 0);
Assert.assertEquals(defaultMode, testDa.getExpansionMode()); Assert.assertEquals(defaultMode, testDa.getExpansionMode());
@ -72,7 +72,7 @@ public class ResizableDoubleArrayTest extends DoubleArrayAbstractTest {
testDa = new ResizableDoubleArray(2, 2.0f); testDa = new ResizableDoubleArray(2, 2.0f);
Assert.assertEquals(0, testDa.getNumElements()); Assert.assertEquals(0, testDa.getNumElements());
Assert.assertEquals(2, testDa.getInternalLength()); Assert.assertEquals(2, testDa.getCapacity());
Assert.assertEquals(defaultExpansionFactor, testDa.getExpansionFactor(), 0); Assert.assertEquals(defaultExpansionFactor, testDa.getExpansionFactor(), 0);
Assert.assertEquals(defaultContractionCriteria, testDa.getContractionCriteria(), 0); Assert.assertEquals(defaultContractionCriteria, testDa.getContractionCriteria(), 0);
Assert.assertEquals(defaultMode, testDa.getExpansionMode()); Assert.assertEquals(defaultMode, testDa.getExpansionMode());
@ -90,7 +90,7 @@ public class ResizableDoubleArrayTest extends DoubleArrayAbstractTest {
testDa = new ResizableDoubleArray(2, 2.0f, 3.0f); testDa = new ResizableDoubleArray(2, 2.0f, 3.0f);
Assert.assertEquals(0, testDa.getNumElements()); Assert.assertEquals(0, testDa.getNumElements());
Assert.assertEquals(2, testDa.getInternalLength()); Assert.assertEquals(2, testDa.getCapacity());
Assert.assertEquals(defaultExpansionFactor, testDa.getExpansionFactor(), 0); Assert.assertEquals(defaultExpansionFactor, testDa.getExpansionFactor(), 0);
Assert.assertEquals(3.0f, testDa.getContractionCriteria(), 0); Assert.assertEquals(3.0f, testDa.getContractionCriteria(), 0);
Assert.assertEquals(defaultMode, testDa.getExpansionMode()); Assert.assertEquals(defaultMode, testDa.getExpansionMode());
@ -105,7 +105,7 @@ public class ResizableDoubleArrayTest extends DoubleArrayAbstractTest {
testDa = new ResizableDoubleArray(2, 2.0f, 3.0f, testDa = new ResizableDoubleArray(2, 2.0f, 3.0f,
ResizableDoubleArray.ADDITIVE_MODE); ResizableDoubleArray.ADDITIVE_MODE);
Assert.assertEquals(0, testDa.getNumElements()); Assert.assertEquals(0, testDa.getNumElements());
Assert.assertEquals(2, testDa.getInternalLength()); Assert.assertEquals(2, testDa.getCapacity());
Assert.assertEquals(defaultExpansionFactor, testDa.getExpansionFactor(), 0); Assert.assertEquals(defaultExpansionFactor, testDa.getExpansionFactor(), 0);
Assert.assertEquals(3.0f, testDa.getContractionCriteria(), 0); Assert.assertEquals(3.0f, testDa.getContractionCriteria(), 0);
Assert.assertEquals(ResizableDoubleArray.ADDITIVE_MODE, Assert.assertEquals(ResizableDoubleArray.ADDITIVE_MODE,
@ -157,16 +157,16 @@ public class ResizableDoubleArrayTest extends DoubleArrayAbstractTest {
da.addElement(2.0); da.addElement(2.0);
da.addElement(4.0); da.addElement(4.0);
da.addElement(6.0); da.addElement(6.0);
Assert.assertEquals(16, ((ResizableDoubleArray) da).getInternalLength()); Assert.assertEquals(16, ((ResizableDoubleArray) da).getCapacity());
Assert.assertEquals(3, da.getNumElements()); Assert.assertEquals(3, da.getNumElements());
da.setElement(3, 7.0); da.setElement(3, 7.0);
Assert.assertEquals(16, ((ResizableDoubleArray) da).getInternalLength()); Assert.assertEquals(16, ((ResizableDoubleArray) da).getCapacity());
Assert.assertEquals(4, da.getNumElements()); Assert.assertEquals(4, da.getNumElements());
da.setElement(10, 10.0); da.setElement(10, 10.0);
Assert.assertEquals(16, ((ResizableDoubleArray) da).getInternalLength()); Assert.assertEquals(16, ((ResizableDoubleArray) da).getCapacity());
Assert.assertEquals(11, da.getNumElements()); Assert.assertEquals(11, da.getNumElements());
da.setElement(9, 10.0); da.setElement(9, 10.0);
Assert.assertEquals(16, ((ResizableDoubleArray) da).getInternalLength()); Assert.assertEquals(16, ((ResizableDoubleArray) da).getCapacity());
Assert.assertEquals(11, da.getNumElements()); Assert.assertEquals(11, da.getNumElements());
try { try {
@ -180,12 +180,12 @@ public class ResizableDoubleArrayTest extends DoubleArrayAbstractTest {
ResizableDoubleArray testDa = new ResizableDoubleArray(2, 2.0f, 3.0f, ResizableDoubleArray testDa = new ResizableDoubleArray(2, 2.0f, 3.0f,
ResizableDoubleArray.ADDITIVE_MODE); ResizableDoubleArray.ADDITIVE_MODE);
Assert.assertEquals(2, testDa.getInternalLength()); Assert.assertEquals(2, testDa.getCapacity());
testDa.addElement(1d); testDa.addElement(1d);
testDa.addElement(1d); testDa.addElement(1d);
Assert.assertEquals(2, testDa.getInternalLength()); Assert.assertEquals(2, testDa.getCapacity());
testDa.addElement(1d); testDa.addElement(1d);
Assert.assertEquals(4, testDa.getInternalLength()); Assert.assertEquals(4, testDa.getCapacity());
} }
@Override @Override
@ -194,7 +194,7 @@ public class ResizableDoubleArrayTest extends DoubleArrayAbstractTest {
super.testAdd1000(); super.testAdd1000();
Assert.assertEquals("Internal Storage length should be 1024 if we started out with initial capacity of " + Assert.assertEquals("Internal Storage length should be 1024 if we started out with initial capacity of " +
"16 and an expansion factor of 2.0", "16 and an expansion factor of 2.0",
1024, ((ResizableDoubleArray) da).getInternalLength()); 1024, ((ResizableDoubleArray) da).getCapacity());
} }
@Test @Test
@ -214,14 +214,14 @@ public class ResizableDoubleArrayTest extends DoubleArrayAbstractTest {
// ADDITIVE_MODE (x's are occupied storage locations, 0's are open) // ADDITIVE_MODE (x's are occupied storage locations, 0's are open)
testDa = new ResizableDoubleArray(2, 2.0f, 2.5f, testDa = new ResizableDoubleArray(2, 2.0f, 2.5f,
ResizableDoubleArray.ADDITIVE_MODE); ResizableDoubleArray.ADDITIVE_MODE);
Assert.assertEquals(2, testDa.getInternalLength()); Assert.assertEquals(2, testDa.getCapacity());
testDa.addElements(new double[] { 1d }); // x,0 testDa.addElements(new double[] { 1d }); // x,0
testDa.addElements(new double[] { 2d }); // x,x testDa.addElements(new double[] { 2d }); // x,x
testDa.addElements(new double[] { 3d }); // x,x,x,0 -- expanded testDa.addElements(new double[] { 3d }); // x,x,x,0 -- expanded
Assert.assertEquals(1d, testDa.getElement(0), 0); Assert.assertEquals(1d, testDa.getElement(0), 0);
Assert.assertEquals(2d, testDa.getElement(1), 0); Assert.assertEquals(2d, testDa.getElement(1), 0);
Assert.assertEquals(3d, testDa.getElement(2), 0); Assert.assertEquals(3d, testDa.getElement(2), 0);
Assert.assertEquals(4, testDa.getInternalLength()); // x,x,x,0 Assert.assertEquals(4, testDa.getCapacity()); // x,x,x,0
Assert.assertEquals(3, testDa.getNumElements()); Assert.assertEquals(3, testDa.getNumElements());
} }
@ -249,26 +249,26 @@ public class ResizableDoubleArrayTest extends DoubleArrayAbstractTest {
// ADDITIVE_MODE (x's are occupied storage locations, 0's are open) // ADDITIVE_MODE (x's are occupied storage locations, 0's are open)
ResizableDoubleArray testDa = new ResizableDoubleArray(2, 2.0f, 2.5f, ResizableDoubleArray testDa = new ResizableDoubleArray(2, 2.0f, 2.5f,
ResizableDoubleArray.ADDITIVE_MODE); ResizableDoubleArray.ADDITIVE_MODE);
Assert.assertEquals(2, testDa.getInternalLength()); Assert.assertEquals(2, testDa.getCapacity());
testDa.addElement(1d); // x,0 testDa.addElement(1d); // x,0
testDa.addElement(2d); // x,x testDa.addElement(2d); // x,x
testDa.addElement(3d); // x,x,x,0 -- expanded testDa.addElement(3d); // x,x,x,0 -- expanded
Assert.assertEquals(1d, testDa.getElement(0), 0); Assert.assertEquals(1d, testDa.getElement(0), 0);
Assert.assertEquals(2d, testDa.getElement(1), 0); Assert.assertEquals(2d, testDa.getElement(1), 0);
Assert.assertEquals(3d, testDa.getElement(2), 0); Assert.assertEquals(3d, testDa.getElement(2), 0);
Assert.assertEquals(4, testDa.getInternalLength()); // x,x,x,0 Assert.assertEquals(4, testDa.getCapacity()); // x,x,x,0
Assert.assertEquals(3, testDa.getNumElements()); Assert.assertEquals(3, testDa.getNumElements());
testDa.addElementRolling(4d); testDa.addElementRolling(4d);
Assert.assertEquals(2d, testDa.getElement(0), 0); Assert.assertEquals(2d, testDa.getElement(0), 0);
Assert.assertEquals(3d, testDa.getElement(1), 0); Assert.assertEquals(3d, testDa.getElement(1), 0);
Assert.assertEquals(4d, testDa.getElement(2), 0); Assert.assertEquals(4d, testDa.getElement(2), 0);
Assert.assertEquals(4, testDa.getInternalLength()); // 0,x,x,x Assert.assertEquals(4, testDa.getCapacity()); // 0,x,x,x
Assert.assertEquals(3, testDa.getNumElements()); Assert.assertEquals(3, testDa.getNumElements());
testDa.addElementRolling(5d); // 0,0,x,x,x,0 -- time to contract testDa.addElementRolling(5d); // 0,0,x,x,x,0 -- time to contract
Assert.assertEquals(3d, testDa.getElement(0), 0); Assert.assertEquals(3d, testDa.getElement(0), 0);
Assert.assertEquals(4d, testDa.getElement(1), 0); Assert.assertEquals(4d, testDa.getElement(1), 0);
Assert.assertEquals(5d, testDa.getElement(2), 0); Assert.assertEquals(5d, testDa.getElement(2), 0);
Assert.assertEquals(4, testDa.getInternalLength()); // contracted -- x,x,x,0 Assert.assertEquals(4, testDa.getCapacity()); // contracted -- x,x,x,0
Assert.assertEquals(3, testDa.getNumElements()); Assert.assertEquals(3, testDa.getNumElements());
try { try {
testDa.getElement(4); testDa.getElement(4);