Replaced obsolete exceptions.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1178211 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Phil Steitz 2011-10-02 18:10:03 +00:00
parent 48f14e7769
commit 05cdc9f273
1 changed files with 16 additions and 20 deletions

View File

@ -19,7 +19,8 @@ package org.apache.commons.math.util;
import java.io.Serializable; import java.io.Serializable;
import java.util.Arrays; import java.util.Arrays;
import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.exception.MathIllegalArgumentException;
import org.apache.commons.math.exception.MathIllegalStateException;
import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.NullArgumentException;
import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.exception.util.LocalizedFormats;
@ -360,15 +361,16 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
/** /**
* Substitutes <code>value</code> for the most recently added value. * Substitutes <code>value</code> for the most recently added value.
* Returns the value that has been replaced. If the array is empty (i.e. * Returns the value that has been replaced. If the array is empty (i.e.
* if {@link #numElements} is zero), a MathRuntimeException is thrown. * if {@link #numElements} is zero), an IllegalStateException is thrown.
* *
* @param value new value to substitute for the most recently added value * @param value new value to substitute for the most recently added value
* @return value that has been replaced in the array * @return value that has been replaced in the array
* @throws IllegalStateException if the array is empty
* @since 2.0 * @since 2.0
*/ */
public synchronized double substituteMostRecentElement(double value) { public synchronized double substituteMostRecentElement(double value) {
if (numElements < 1) { if (numElements < 1) {
throw MathRuntimeException.createArrayIndexOutOfBoundsException( throw new MathIllegalStateException(
LocalizedFormats.CANNOT_SUBSTITUTE_ELEMENT_FROM_EMPTY_ARRAY); LocalizedFormats.CANNOT_SUBSTITUTE_ELEMENT_FROM_EMPTY_ARRAY);
} }
@ -393,19 +395,19 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
protected void checkContractExpand(float contraction, float expansion) { protected void checkContractExpand(float contraction, float expansion) {
if (contraction < expansion) { if (contraction < expansion) {
throw MathRuntimeException.createIllegalArgumentException( throw new MathIllegalArgumentException(
LocalizedFormats.CONTRACTION_CRITERIA_SMALLER_THAN_EXPANSION_FACTOR, LocalizedFormats.CONTRACTION_CRITERIA_SMALLER_THAN_EXPANSION_FACTOR,
contraction, expansion); contraction, expansion);
} }
if (contraction <= 1.0) { if (contraction <= 1.0) {
throw MathRuntimeException.createIllegalArgumentException( throw new MathIllegalArgumentException(
LocalizedFormats.CONTRACTION_CRITERIA_SMALLER_THAN_ONE, LocalizedFormats.CONTRACTION_CRITERIA_SMALLER_THAN_ONE,
contraction); contraction);
} }
if (expansion <= 1.0) { if (expansion <= 1.0) {
throw MathRuntimeException.createIllegalArgumentException( throw new MathIllegalArgumentException(
LocalizedFormats.EXPANSION_FACTOR_SMALLER_THAN_ONE, LocalizedFormats.EXPANSION_FACTOR_SMALLER_THAN_ONE,
expansion); expansion);
} }
@ -492,11 +494,11 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
*/ */
private synchronized void discardExtremeElements(int i,boolean front) { private synchronized void discardExtremeElements(int i,boolean front) {
if (i > numElements) { if (i > numElements) {
throw MathRuntimeException.createIllegalArgumentException( throw new MathIllegalArgumentException(
LocalizedFormats.TOO_MANY_ELEMENTS_TO_DISCARD_FROM_ARRAY, LocalizedFormats.TOO_MANY_ELEMENTS_TO_DISCARD_FROM_ARRAY,
i, numElements); i, numElements);
} else if (i < 0) { } else if (i < 0) {
throw MathRuntimeException.createIllegalArgumentException( throw new MathIllegalArgumentException(
LocalizedFormats.CANNOT_DISCARD_NEGATIVE_NUMBER_OF_ELEMENTS, LocalizedFormats.CANNOT_DISCARD_NEGATIVE_NUMBER_OF_ELEMENTS,
i); i);
} else { } else {
@ -578,15 +580,11 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
*/ */
public synchronized double getElement(int index) { public synchronized double getElement(int index) {
if (index >= numElements) { if (index >= numElements) {
throw MathRuntimeException.createArrayIndexOutOfBoundsException( throw new ArrayIndexOutOfBoundsException(index);
LocalizedFormats.INDEX_LARGER_THAN_MAX,
index, numElements - 1);
} else if (index >= 0) { } else if (index >= 0) {
return internalArray[startIndex + index]; return internalArray[startIndex + index];
} else { } else {
throw MathRuntimeException.createArrayIndexOutOfBoundsException( throw new ArrayIndexOutOfBoundsException(index);
LocalizedFormats.CANNOT_RETRIEVE_AT_NEGATIVE_INDEX,
index);
} }
} }
@ -696,9 +694,7 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
*/ */
public synchronized void setElement(int index, double value) { public synchronized void setElement(int index, double value) {
if (index < 0) { if (index < 0) {
throw MathRuntimeException.createArrayIndexOutOfBoundsException( throw new ArrayIndexOutOfBoundsException(index);
LocalizedFormats.CANNOT_SET_AT_NEGATIVE_INDEX,
index);
} }
if (index + 1 > numElements) { if (index + 1 > numElements) {
numElements = index + 1; numElements = index + 1;
@ -738,7 +734,7 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
public void setExpansionMode(int expansionMode) { public void setExpansionMode(int expansionMode) {
if (expansionMode != MULTIPLICATIVE_MODE && if (expansionMode != MULTIPLICATIVE_MODE &&
expansionMode != ADDITIVE_MODE) { expansionMode != ADDITIVE_MODE) {
throw MathRuntimeException.createIllegalArgumentException( throw new MathIllegalArgumentException(
LocalizedFormats.UNSUPPORTED_EXPANSION_MODE, LocalizedFormats.UNSUPPORTED_EXPANSION_MODE,
expansionMode, MULTIPLICATIVE_MODE, "MULTIPLICATIVE_MODE", expansionMode, MULTIPLICATIVE_MODE, "MULTIPLICATIVE_MODE",
ADDITIVE_MODE, "ADDITIVE_MODE"); ADDITIVE_MODE, "ADDITIVE_MODE");
@ -761,7 +757,7 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
this.initialCapacity = initialCapacity; this.initialCapacity = initialCapacity;
} }
} else { } else {
throw MathRuntimeException.createIllegalArgumentException( throw new MathIllegalArgumentException(
LocalizedFormats.INITIAL_CAPACITY_NOT_POSITIVE, LocalizedFormats.INITIAL_CAPACITY_NOT_POSITIVE,
initialCapacity); initialCapacity);
} }
@ -779,7 +775,7 @@ public class ResizableDoubleArray implements DoubleArray, Serializable {
// If index is negative thrown an error // If index is negative thrown an error
if (i < 0) { if (i < 0) {
throw MathRuntimeException.createIllegalArgumentException( throw new MathIllegalArgumentException(
LocalizedFormats.INDEX_NOT_POSITIVE, LocalizedFormats.INDEX_NOT_POSITIVE,
i); i);
} }