/** * This function allows you to control the number of elements contained * in this array, and can be used to "throw out" the last n values in an * array. This function will also expand the internal array as needed. * * @param i a new number of elements * @throws IllegalArgumentException if <code>i</code> is negative. */ public synchronized void setNumElements(int i) { // If index is negative thrown an error if (i < 0) { String msg = "Number of elements must be zero or a positive " + "integer"; throw new IllegalArgumentException(msg); } // Test the new num elements, check to see if the array needs to be // expanded to accomodate this new number of elements if ((startIndex + i) > internalArray.length) { expandTo(startIndex + i); } // Set the new number of elements to new value numElements = i; }
/** * 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) { String msg = "Cannot set an element at a negative index"; throw new ArrayIndexOutOfBoundsException(msg); } if (index + 1 > numElements) { numElements = index + 1; } if ((startIndex + index) >= internalArray.length) { expandTo(startIndex + (index + 1)); } internalArray[startIndex + index] = value; }
/** * This function allows you to control the number of elements contained * in this array, and can be used to "throw out" the last n values in an * array. This function will also expand the internal array as needed. * * @param i a new number of elements * @throws IllegalArgumentException if <code>i</code> is negative. */ public synchronized void setNumElements(int i) { // If index is negative thrown an error if (i < 0) { throw MathRuntimeException.createIllegalArgumentException( LocalizedFormats.INDEX_NOT_POSITIVE, i); } // Test the new num elements, check to see if the array needs to be // expanded to accommodate this new number of elements if ((startIndex + i) > internalArray.length) { expandTo(startIndex + i); } // Set the new number of elements to new value numElements = i; }
/** * 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; }
/** * This function allows you to control the number of elements contained * in this array, and can be used to "throw out" the last n values in an * array. This function will also expand the internal array as needed. * * @param i a new number of elements * @throws IllegalArgumentException if <code>i</code> is negative. */ public synchronized void setNumElements(int i) { // If index is negative thrown an error if (i < 0) { throw MathRuntimeException.createIllegalArgumentException( "index ({0}) is not positive", i); } // Test the new num elements, check to see if the array needs to be // expanded to accommodate this new number of elements if ((startIndex + i) > internalArray.length) { expandTo(startIndex + i); } // Set the new number of elements to new value numElements = i; }
/** * 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; }