当前位置: 首页>>代码示例>>Java>>正文


Java MathRuntimeException.createArrayIndexOutOfBoundsException方法代码示例

本文整理汇总了Java中org.apache.commons.math.MathRuntimeException.createArrayIndexOutOfBoundsException方法的典型用法代码示例。如果您正苦于以下问题:Java MathRuntimeException.createArrayIndexOutOfBoundsException方法的具体用法?Java MathRuntimeException.createArrayIndexOutOfBoundsException怎么用?Java MathRuntimeException.createArrayIndexOutOfBoundsException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math.MathRuntimeException的用法示例。


在下文中一共展示了MathRuntimeException.createArrayIndexOutOfBoundsException方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: substituteMostRecentElement

import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
 * Substitutes <code>value</code> for the most recently added value.
 * Returns the value that has been replaced. If the array is empty (i.e.
 * if {@link #numElements} is zero), a MathRuntimeException is thrown.
 *
 * @param value new value to substitute for the most recently added value
 * @return value that has been replaced in the array
 * @since 2.0
 */
public synchronized double substituteMostRecentElement(double value) {
    if (numElements < 1) {
        throw MathRuntimeException.createArrayIndexOutOfBoundsException(
                "cannot substitute an element from an empty array");
    }

    double discarded = internalArray[startIndex + (numElements - 1)];

    internalArray[startIndex + (numElements - 1)] = value;

    return discarded;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:22,代码来源:ResizableDoubleArray.java

示例2: getElement

import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
 * Returns the element at the specified index
 *
 * @param index index to fetch a value from
 * @return value stored at the specified index
 * @throws ArrayIndexOutOfBoundsException if <code>index</code> is less than
 *         zero or is greater than <code>getNumElements() - 1</code>.
 */
public synchronized double getElement(int index) {
    if (index >= numElements) {
        throw MathRuntimeException.createArrayIndexOutOfBoundsException(
                "the index specified: {0} is larger than the current maximal index {1}",
                index, numElements - 1);
    } else if (index >= 0) {
        return internalArray[startIndex + index];
    } else {
        throw MathRuntimeException.createArrayIndexOutOfBoundsException(
                "elements cannot be retrieved from a negative array index {0}",
                index);
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:22,代码来源:ResizableDoubleArray.java

示例3: getElement

import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
 * Returns the element at the specified index
 * 
 * @param index index to fetch a value from
 * @return value stored at the specified index
 * @throws ArrayIndexOutOfBoundsException if <code>index</code> is less than
 *         zero or is greater than <code>getNumElements() - 1</code>.
 */
public synchronized double getElement(int index) {
    if (index >= numElements) {
        throw MathRuntimeException.createArrayIndexOutOfBoundsException(
                "the index specified: {0} is larger than the current maximal index {1}",
                index, numElements - 1);
    } else if (index >= 0) {
        return internalArray[startIndex + index];
    } else {
        throw MathRuntimeException.createArrayIndexOutOfBoundsException(
                "elements cannot be retrieved from a negative array index {0}",
                index);
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:22,代码来源:ResizableDoubleArray.java

示例4: setElement

import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
 * Sets the element at the specified index.  If the specified index is greater than
 * <code>getNumElements() - 1</code>, the <code>numElements</code> property
 * is increased to <code>index +1</code> and additional storage is allocated 
 * (if necessary) for the new element and all  (uninitialized) elements 
 * between the new element and the previous end of the array).
 * 
 * @param index index to store a value in
 * @param value value to store at the specified index
 * @throws ArrayIndexOutOfBoundsException if <code>index</code> is less than
 *         zero.
 */
public synchronized void setElement(int index, double value) {
    if (index < 0) {
        throw MathRuntimeException.createArrayIndexOutOfBoundsException(
                "cannot set an element at a negative index {0}",
                index);
    }
    if (index + 1 > numElements) {
        numElements = index + 1;
    }       
    if ((startIndex + index) >= internalArray.length) {
        expandTo(startIndex + (index + 1));
    }    
    internalArray[startIndex + index] = value;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:27,代码来源:ResizableDoubleArray.java

示例5: substituteMostRecentElement

import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
 * Substitutes <code>value</code> for the most recently added value.
 * Returns the value that has been replaced. If the array is empty (i.e. 
 * if {@link #numElements} is zero), a MathRuntimeException is thrown.
 * 
 * @param value new value to substitute for the most recently added value
 * @return value that has been replaced in the array
 * @since 2.0
 */
public synchronized double substituteMostRecentElement(double value) {
    if (numElements < 1) {
        throw MathRuntimeException.createArrayIndexOutOfBoundsException(
                "cannot substitute an element from an empty array");
    }

    double discarded = internalArray[startIndex + (numElements - 1)];

    internalArray[startIndex + (numElements - 1)] = value;

    return discarded;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:22,代码来源:ResizableDoubleArray.java

示例6: setElement

import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
 * Sets the element at the specified index.  If the specified index is greater than
 * <code>getNumElements() - 1</code>, the <code>numElements</code> property
 * is increased to <code>index +1</code> and additional storage is allocated
 * (if necessary) for the new element and all  (uninitialized) elements
 * between the new element and the previous end of the array).
 *
 * @param index index to store a value in
 * @param value value to store at the specified index
 * @throws ArrayIndexOutOfBoundsException if <code>index</code> is less than
 *         zero.
 */
public synchronized void setElement(int index, double value) {
    if (index < 0) {
        throw MathRuntimeException.createArrayIndexOutOfBoundsException(
                LocalizedFormats.CANNOT_SET_AT_NEGATIVE_INDEX,
                index);
    }
    if (index + 1 > numElements) {
        numElements = index + 1;
    }
    if ((startIndex + index) >= internalArray.length) {
        expandTo(startIndex + (index + 1));
    }
    internalArray[startIndex + index] = value;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:27,代码来源:ResizableDoubleArray.java

示例7: setElement

import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
 * Sets the element at the specified index.  If the specified index is greater than
 * <code>getNumElements() - 1</code>, the <code>numElements</code> property
 * is increased to <code>index +1</code> and additional storage is allocated
 * (if necessary) for the new element and all  (uninitialized) elements
 * between the new element and the previous end of the array).
 *
 * @param index index to store a value in
 * @param value value to store at the specified index
 * @throws ArrayIndexOutOfBoundsException if <code>index</code> is less than
 *         zero.
 */
public synchronized void setElement(int index, double value) {
    if (index < 0) {
        throw MathRuntimeException.createArrayIndexOutOfBoundsException(
                "cannot set an element at a negative index {0}",
                index);
    }
    if (index + 1 > numElements) {
        numElements = index + 1;
    }
    if ((startIndex + index) >= internalArray.length) {
        expandTo(startIndex + (index + 1));
    }
    internalArray[startIndex + index] = value;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:27,代码来源:ResizableDoubleArray.java


注:本文中的org.apache.commons.math.MathRuntimeException.createArrayIndexOutOfBoundsException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。