Removal of statistical (min/max) and deleteFrontElements methods from DoubleArray interface (per our previous discussion)

Adjusted dependent Test and StoreUnivariateImpl classes accordingly to accomidate changes.

Added new constructor to FixedDoubleArray for double[].


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@140955 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark R. Diggory 2003-06-27 20:58:28 +00:00
parent fd93fdf0a4
commit 62577ea18b
7 changed files with 26 additions and 99 deletions

View File

@ -54,7 +54,6 @@
package org.apache.commons.math.stat;
import org.apache.commons.math.util.ContractableDoubleArray;
import org.apache.commons.math.util.DoubleArray;
/**
* @author <a href="mailto:tobrien@apache.org">Tim O'Brien</a>
@ -62,7 +61,7 @@ import org.apache.commons.math.util.DoubleArray;
public class StoreUnivariateImpl extends AbstractStoreUnivariate {
// Use an internal double array
DoubleArray eDA;
ContractableDoubleArray eDA;
// Store the windowSize
private int windowSize = Univariate.INFINITE_WINDOW;

View File

@ -123,25 +123,4 @@ public interface DoubleArray {
*/
void clear();
/**
* Discards values from the front of the list. This function removes n
* elements from the front of the array.
*
*@param i number of elements to discard from the front of the array.
*/
void discardFrontElements(int i);
/**
* Returns the minimum value stored in this array
*
* @return minimum value contained in this array
*/
double getMin();
/**
* Returns the maximum value stored in this array
*
* @return maximum value contained in this array
*/
double getMax();
}

View File

@ -408,33 +408,4 @@ public class ExpandableDoubleArray implements Serializable, DoubleArray {
return elementArray;
}
/* (non-Javadoc)
* @see org.apache.commons.math.DoubleArray#getMax()
*/
public double getMax() {
double max = internalArray[startIndex];
for (int i = startIndex + 1; i < (numElements + startIndex); i++) {
if (internalArray[i] > max) {
max = internalArray[i];
}
}
return max;
}
/* (non-Javadoc)
* @see org.apache.commons.math.DoubleArray#getMin()
*/
public double getMin() {
double min = internalArray[startIndex];
for (int i = startIndex + 1; i < (numElements + startIndex); i++) {
if (internalArray[i] < min) {
min = internalArray[i];
}
}
return min;
}
}

View File

@ -120,6 +120,22 @@ public class FixedDoubleArray implements DoubleArray {
internalArray = new double[maxElements];
}
/**
* Create a fixed array backed by the provided double[] implementation.
* the array should have all the elements occupied. the size and maxElements
* are drawn from the array's length.
*
* This implementation of DoubleArray was created to provide a more
* "performance-oriented" in-place rolling mechanism for calculations
* which need to operate on a rolling window of values.
* @param array the backing array
*/
public FixedDoubleArray(double[] array) {
this.maxElements = array.length;
this.size = array.length;
internalArray = array;
}
/**
* Retrieves the current size of the array.
* @see org.apache.commons.math.DoubleArray#getNumElements()
@ -324,37 +340,4 @@ public class FixedDoubleArray implements DoubleArray {
throw new RuntimeException(msg);
}
/**
* Retrieves the minimum double value contained in this array.
*
* @return The number less than all other numbers in this
* array.
* @see org.apache.commons.math.DoubleArray#getMin()
*/
public double getMin() {
double min = internalArray[0];
for (int i = 1; i < size; i++) {
if (internalArray[i] < min) {
min = internalArray[i];
}
}
return min;
}
/**
* Retrieves the maximum double value contained in this array.
*
* @return The number greater than all other numbers in this
* array.
* @see org.apache.commons.math.DoubleArray#getMax()
*/
public double getMax() {
double max = internalArray[0];
for (int i = 1; i < size; i++) {
if (internalArray[i] > max) {
max = internalArray[i];
}
}
return max;
}
}

View File

@ -53,6 +53,8 @@
*/
package org.apache.commons.math.util;
import org.apache.commons.math.stat.StatUtils;
import junit.framework.TestCase;
/**
@ -126,12 +128,12 @@ public abstract class DoubleArrayAbstractTest extends TestCase {
assertEquals(
"The max element should be 2.0",
2.0,
ra.getMax(),
StatUtils.max(ra.getElements()),
Double.MIN_VALUE);
assertEquals(
"The min element should be 1.0",
1.0,
ra.getMin(),
StatUtils.min(ra.getElements()),
Double.MIN_VALUE);
for (int i = 0; i < 1024; i++) {
@ -156,11 +158,11 @@ public abstract class DoubleArrayAbstractTest extends TestCase {
da.addElement(122.0);
da.addElement(1212.0);
assertEquals("Min should be -2.0", -2.0, da.getMin(), Double.MIN_VALUE);
assertEquals("Min should be -2.0", -2.0, StatUtils.min(da.getElements()), Double.MIN_VALUE);
assertEquals(
"Max should be 1212.0",
1212.0,
da.getMax(),
StatUtils.max(da.getElements()),
Double.MIN_VALUE);
}

View File

@ -198,17 +198,17 @@ public class ExpandableDoubleArrayTest extends DoubleArrayAbstractTest {
da.addElement(2.0);
assertEquals( "Number of elements should be 11", 11, da.getNumElements());
da.discardFrontElements(5);
((ExpandableDoubleArray)da).discardFrontElements(5);
assertEquals( "Number of elements should be 6", 6, da.getNumElements());
try {
da.discardFrontElements(-1);
((ExpandableDoubleArray)da).discardFrontElements(-1);
fail( "Trying to discard a negative number of element is not allowed");
} catch( Exception e ){
}
try {
da.discardFrontElements( 10000 );
((ExpandableDoubleArray)da).discardFrontElements( 10000 );
fail( "You can't discard more elements than the array contains");
} catch( Exception e ){
}

View File

@ -171,12 +171,5 @@ public class FixedDoubleArrayTest extends DoubleArrayAbstractTest {
}
public void testDiscardFront() {
try {
da.discardFrontElements( 2 );
fail( "Discard front elements should throw an exception");
} catch( Exception e ) {
}
}
}