/** * Runs the test using the specified harness. * * @param harness the test harness (<code>null</code> not permitted). */ public void test(TestHarness harness) { IndexOutOfBoundsException object1 = new IndexOutOfBoundsException(); harness.check(object1 != null); harness.check(object1.toString(), "java.lang.IndexOutOfBoundsException"); IndexOutOfBoundsException object2 = new IndexOutOfBoundsException("nothing happens"); harness.check(object2 != null); harness.check(object2.toString(), "java.lang.IndexOutOfBoundsException: nothing happens"); IndexOutOfBoundsException object3 = new IndexOutOfBoundsException(null); harness.check(object3 != null); harness.check(object3.toString(), "java.lang.IndexOutOfBoundsException"); }
private static void checkIndexOutOfBoundsException(String val, int start, int end, int radix) { int n = 0; try { n = Integer.parseInt(val, start, end, radix); System.err.println("parseInt(" + val + ", " + start + ", " + end + ", " + radix + ") incorrectly returned " + n); throw new RuntimeException(); } catch (IndexOutOfBoundsException ioob) { ; // Expected } }
/** * Get the long val at given index value. * @return long * @param index int */ public long longAt(int index) { if (index < 0 || index > size()) { throw new IndexOutOfBoundsException(); } int pageNum = (index >> exp); // int offset = index % r; int offset = index &r; return ((long[]) bufferArrayList.get(pageNum))[offset]; }
/** * Get the lower 32 bit of the integer at the given index. * @return int * @param index int */ public int lower32At(int index) { if (index < 0 || index > size()) { throw new IndexOutOfBoundsException(); } int pageNum = (index >> exp); // int offset = index % pageSize; int offset = index & r; return (int) ((long[]) bufferArrayList.get(pageNum))[offset]; }
/** * Modify the value at the index to a new val. * @param index int * @param newValue long */ public void modifyEntry(int index, long newValue) { if (index < 0 || index > size + 1) { throw new IndexOutOfBoundsException(); } //((long[]) bufferArrayList.get((int) (index / pageSize)))[index % pageSize] = ((long[]) bufferArrayList.get(index >> exp))[index & r] = newValue; }
/** * Return the upper 32 bit of the long at the index. * @return int * @param index int */ public int upper32At(int index) { if (index < 0 || index >= size()) { throw new IndexOutOfBoundsException(); } int pageNum = (index >>exp); int offset = index & r; return (int) ((((long[]) bufferArrayList.get(pageNum))[offset] & (0xffffffffL << 32)) >> 32); }
/** * Get the int at the location specified by index. * @return int * @param index int */ public int intAt(int index) { if (index < 0 || index > size()-1) { throw new IndexOutOfBoundsException(); } // int pageNum = (int) index / pageSize; int pageNum = index>>exp; //System.out.println("page Number is "+pageNum); // int offset = index % pageSize; int offset = index & r; return ((int[]) bufferArrayList.get(pageNum))[offset]; }
/** * Assigns a new int value to location index of the buffer instance. * @param index int * @param newValue int */ public void modifyEntry(int index, int newValue) { if (index < 0 || index > size - 1) { throw new IndexOutOfBoundsException(); } // ((int[]) bufferArrayList.get((int) (index / pageSize)))[index % pageSize] = ((int[]) bufferArrayList.get((index >> exp)))[index & r] = newValue; }
/** * @brief Connects two vertices on a given graph * * @param connections * The connections on the graph * @param vertex1 * The first vertex * @param vertex2 * The second vertex * * @throws IndexOutOfBoundsException * If at least one of the vertices given is less than zero of greater of equal to * the number of vertices. */ public static void connect (boolean[][] connections, int vertex1, int vertex2) throws IndexOutOfBoundsException { if (vertex1 < 0 || vertex1 >= connections.length || vertex2 < 0 || vertex2 >= connections.length) { throw new IndexOutOfBoundsException(); } else { connections[vertex1][vertex2] = true; if (vertex1 != vertex2) { connections[vertex2][vertex1] = true; } } }
/** * Runs the test using the specified harness. * * @param harness the test harness (<code>null</code> not permitted). */ public void test(TestHarness harness) { // flag that is set when exception is caught boolean caught = false; try { throw new IndexOutOfBoundsException("IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException e) { // correct exception was caught caught = true; } harness.check(caught); }
private final TagAttribute getAttribute(int index) { if (m_tagAttributes==null) { throw new IndexOutOfBoundsException("Attributes are not available."); } if (index>=m_tagAttributes.length) { throw new IndexOutOfBoundsException("Invalid attribute index ("+index+")."); } return m_tagAttributes[index]; }
public StarSystem getSystem (HexID xy) { if (systems == null) return null; StarSystem s; try { s = systems.get(systems.indexOf(xy)); return s; } catch (IndexOutOfBoundsException e) { return null; } }
public void scaleData(int index, double scaleAmt) throws Exception { if ((index < 0) || (index >= _data.size())) throw new IndexOutOfBoundsException("Index " + index + " out of bounds (" + 0 + " - " + (_data.size() - 1) + ")"); WordFrequencyData oldData = _data.get(index); _data.set(index, new WordFrequencyData(oldData.getWord(), oldData.getData() * scaleAmt)); }
/** * Return a selected chuck of long buffer as a long array. * @return long[] * @param startingOffset int * @param len int */ public long[] getLongArray(int startingOffset, int len) { if (size <= 0 || startingOffset < 0) { throw (new IllegalArgumentException()); } if ((startingOffset + len) > size) { throw (new IndexOutOfBoundsException()); } long[] result = new long[len]; // allocate result array int first_index = (startingOffset >> exp); int last_index = ((startingOffset + len) >>exp); //if ((startingOffset + len) % pageSize == 0) { if (((startingOffset + len) & r) == 0) { last_index--; } if (first_index == last_index) { // to see if there is a need to go across buffer boundry System.arraycopy( (long[]) (bufferArrayList.oa[first_index]), // startingOffset % pageSize, startingOffset & r, result, 0, len); } else { int long_array_offset = 0; for (int i = first_index; i <= last_index; i++) { long[] currentChunk = (long[]) bufferArrayList.oa[i]; if (i == first_index) // first section { System.arraycopy( currentChunk, // startingOffset % pageSize, startingOffset & r, result, 0, // pageSize - (startingOffset % r)); pageSize - (startingOffset & r)); long_array_offset += pageSize - (startingOffset & r); } else if (i == last_index) // last sections { System.arraycopy( currentChunk, 0, result, long_array_offset, len - long_array_offset); } else { System.arraycopy(currentChunk, 0, result, long_array_offset, pageSize); long_array_offset += pageSize; } } } return result; }
/** * Returns a single int array representing every int in this buffer instance * @return int[] (null if there isn't anything left in the buffer * @param startingOffset int * @param len int * @return int[] */ public int[] getIntArray(int startingOffset, int len) { if (size <= 0 || startingOffset < 0) { throw (new IllegalArgumentException()); } if ((startingOffset + len) > size) { throw (new IndexOutOfBoundsException()); } int[] result = new int[len]; // allocate result array // int first_index = (int) (startingOffset / pageSize); // int last_index = (int) ((startingOffset + len) / pageSize); // if ((startingOffset + len) % pageSize == 0) { // last_index--; // } int first_index = startingOffset >> exp; int last_index = (startingOffset + len)>> exp; if (((startingOffset + len) & r) == 0) { last_index--; } if (first_index == last_index) { // to see if there is a need to go across buffer boundry System.arraycopy( (int[]) (bufferArrayList.get(first_index)), // startingOffset % pageSize, startingOffset & r, result, 0, len); } else { int int_array_offset = 0; for (int i = first_index; i <= last_index; i++) { int[] currentChunk = (int[]) bufferArrayList.get(i); if (i == first_index) // first section { System.arraycopy( currentChunk, // startingOffset % pageSize, startingOffset & r, result, 0, // pageSize - (startingOffset % pageSize)); pageSize - (startingOffset & r)); // int_array_offset += pageSize - (startingOffset) % pageSize; int_array_offset += pageSize - (startingOffset & r); } else if (i == last_index) // last sections { System.arraycopy( currentChunk, 0, result, int_array_offset, len - int_array_offset); } else { System.arraycopy(currentChunk, 0, result, int_array_offset, pageSize); int_array_offset += pageSize; } } } return result; }
/** * Return a selected chuck of long buffer as a long array. * @return long[] * @param startingOffset int * @param len int */ public long[] getLongArray(int startingOffset, int len) { if (size <= 0 || startingOffset < 0) { throw (new IllegalArgumentException()); } if ((startingOffset + len) > size()) { throw (new IndexOutOfBoundsException()); } long[] result = new long[len]; // allocate result array int first_index = (startingOffset >> exp); int last_index = ((startingOffset + len) >>exp); //if ((startingOffset + len) % pageSize == 0) { if (((startingOffset + len) & r) == 0) { last_index--; } if (first_index == last_index) { // to see if there is a need to go across buffer boundry System.arraycopy( (long[]) (bufferArrayList.get(first_index)), // startingOffset % pageSize, startingOffset & r, result, 0, len); } else { int long_array_offset = 0; for (int i = first_index; i <= last_index; i++) { long[] currentChunk = (long[]) bufferArrayList.get(i); if (i == first_index) // first section { System.arraycopy( currentChunk, // startingOffset % pageSize, startingOffset & r, result, 0, // pageSize - (startingOffset % r)); pageSize - (startingOffset & r)); long_array_offset += pageSize - (startingOffset & r); } else if (i == last_index) // last sections { System.arraycopy( currentChunk, 0, result, long_array_offset, len - long_array_offset); } else { System.arraycopy(currentChunk, 0, result, long_array_offset, pageSize); long_array_offset += pageSize; } } } return result; }
/** * Returns a single int array representing every int in this buffer instance * @return int[] (null if there isn't anything left in the buffer * @param startingOffset int * @param len int * @return int[] */ public int[] getIntArray(int startingOffset, int len) { if (size <= 0 || startingOffset < 0) { throw (new IllegalArgumentException()); } if ((startingOffset + len) > size()) { throw (new IndexOutOfBoundsException()); } int[] result = new int[len]; // allocate result array // int first_index = (int) (startingOffset / pageSize); // int last_index = (int) ((startingOffset + len) / pageSize); // if ((startingOffset + len) % pageSize == 0) { // last_index--; // } int first_index = startingOffset >> exp; int last_index = (startingOffset + len)>> exp; if (((startingOffset + len) & r) == 0) { last_index--; } if (first_index == last_index) { // to see if there is a need to go across buffer boundry System.arraycopy( (int[]) (bufferArrayList.get(first_index)), // startingOffset % pageSize, startingOffset & r, result, 0, len); } else { int int_array_offset = 0; for (int i = first_index; i <= last_index; i++) { int[] currentChunk = (int[]) bufferArrayList.get(i); if (i == first_index) // first section { System.arraycopy( currentChunk, // startingOffset % pageSize, startingOffset & r, result, 0, // pageSize - (startingOffset % pageSize)); pageSize - (startingOffset & r)); // int_array_offset += pageSize - (startingOffset) % pageSize; int_array_offset += pageSize - (startingOffset & r); } else if (i == last_index) // last sections { System.arraycopy( currentChunk, 0, result, int_array_offset, len - int_array_offset); } else { System.arraycopy(currentChunk, 0, result, int_array_offset, pageSize); int_array_offset += pageSize; } } } return result; }