List of usage examples for java.lang IndexOutOfBoundsException IndexOutOfBoundsException
public IndexOutOfBoundsException(int index)
From source file:com.orion.parser.UrT42Parser.java
/** * Return the <tt>Hitlocation</tt> matching the given code * /*from w ww .j a v a 2 s . c om*/ * @author Daniele Pantaleone * @param code The <tt>Hitlocation</tt> code * @throws IndexOutOfBoundsException If the <tt>Hitlocation</tt> code is not mapped * @return The <tt>Hitlocation</tt> matching the given code **/ public Hitlocation getHitlocationByCode(Integer code) throws IndexOutOfBoundsException { if (!hitlocationByCode.containsKey(code)) throw new IndexOutOfBoundsException("could not retrieve a Hitlocation using the given code: " + code); return hitlocationByCode.get(code); }
From source file:Main.java
/** * Underlying implementation of add(array, index, element) methods. * The last parameter is the class, which may not equal element.getClass * for primitives.//w ww . j a va2 s . c o m * * @param array the array to add the element to, may be {@code null} * @param index the position of the new object * @param element the object to add * @param clss the type of the element being added * @return A new array containing the existing elements and the new element */ private static Object add(Object array, int index, Object element, Class<?> clss) { if (array == null) { if (index != 0) { throw new IndexOutOfBoundsException("Index: " + index + ", Length: 0"); } Object joinedArray = Array.newInstance(clss, 1); Array.set(joinedArray, 0, element); return joinedArray; } int length = Array.getLength(array); if (index > length || index < 0) { throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length); } Object result = Array.newInstance(clss, length + 1); System.arraycopy(array, 0, result, 0, index); Array.set(result, index, element); if (index < length) { System.arraycopy(array, index, result, index + 1, length - index); } return result; }
From source file:Main.java
/** * Underlying implementation of add(array, index, element) methods. * The last parameter is the class, which may not equal element.getClass * for primitives./* w w w .j a v a 2s . c o m*/ * * @param array the array to add the element to, may be {@code null} * @param index the position of the new object * @param element the object to add * @param clss the type of the element being added * @return A new array containing the existing elements and the new element */ private static Object add(final Object array, final int index, final Object element, final Class<?> clss) { if (array == null) { if (index != 0) { throw new IndexOutOfBoundsException("Index: " + index + ", Length: 0"); } final Object joinedArray = Array.newInstance(clss, 1); Array.set(joinedArray, 0, element); return joinedArray; } final int length = Array.getLength(array); if (index > length || index < 0) { throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length); } final Object result = Array.newInstance(clss, length + 1); System.arraycopy(array, 0, result, 0, index); Array.set(result, index, element); if (index < length) { System.arraycopy(array, index, result, index + 1, length - index); } return result; }
From source file:com.orion.parser.UrT42Parser.java
/** * Return the <tt>Item</tt> matching the given gear code * /*ww w . ja v a 2 s . co m*/ * @author Daniele Pantaleone * @param code The <tt>Item</tt> gear code * @throws IndexOutOfBoundsException If the <tt>Item</tt> gear code is not mapped * @return The <tt>Item</tt> matching the given gear code **/ public Item getItemByCode(Character code) throws IndexOutOfBoundsException { if (!itemByCode.containsKey(code)) throw new IndexOutOfBoundsException("could not retrieve an Item using the given code: " + code); return itemByCode.get(code); }
From source file:gov.jgi.meta.MetaUtils.java
/** * replace the i'th character of string s with character c * @param s the string//from w w w . j av a2 s . c o m * @param i the index of the string to replace * @param c the character to replace * @return the new string * @throws IndexOutOfBoundsException if necessary */ public static String stringReplaceIth(String s, int i, char c) throws IndexOutOfBoundsException { if (i >= s.length()) { throw new IndexOutOfBoundsException("index " + i + " greater than length of " + s); } return (s.substring(0, i) + c + s.substring(i + 1)); }
From source file:com.orion.parser.UrT42Parser.java
/** * Return the <tt>Item</tt> matching the given name * //from w ww .j a v a 2 s. co m * @author Daniele Pantaleone * @param name The <tt>Item</tt> name * @throws IndexOutOfBoundsException If the <tt>Item</tt> name is not mapped * @return The <tt>Item</tt> matching the given name **/ public Item getItemByName(String name) throws IndexOutOfBoundsException { if (!itemByName.containsKey(name)) throw new IndexOutOfBoundsException("could not retrieve an Item using the given name: " + name); return itemByName.get(name); }
From source file:com.netxforge.oss2.xml.event.Event.java
/** * Method getScript./*from w w w . j a v a 2 s.c o m*/ * * @param index * @throws IndexOutOfBoundsException * if the index given is outside the bounds of the collection * @return the value of the Script at the given index */ public Script getScript(final int index) throws IndexOutOfBoundsException { // check bounds for index if (index < 0 || index >= _scriptList.size()) { throw new IndexOutOfBoundsException( "getScript: Index value '" + index + "' not in range [0.." + (_scriptList.size() - 1) + "]"); } return _scriptList.get(index); }
From source file:com.orion.parser.UrT42Parser.java
/** * Return the <tt>Mod</tt> matching the given kill code * /* w w w. jav a 2s. co m*/ * @author Daniele Pantaleone * @param killcode The <tt>Mod</tt> kill code * @throws IndexOutOfBoundsException If the <tt>Mod</tt> kill code is not mapped * @return The <tt>Mod</tt> matching the given kill code **/ public Mod getModByKillCode(int code) throws IndexOutOfBoundsException { if (!modByKillCode.containsKey(code)) throw new IndexOutOfBoundsException("could not retrieve a Mod using the given kill code: " + code); return modByKillCode.get(code); }
From source file:CopyOnWriteArrayList.java
/** * Inserts all of the elements in the specified Collection into this list, * starting at the specified position. Shifts the element currently at that * position (if any) and any subsequent elements to the right (increases * their indices). The new elements will appear in the list in the order * that they are returned by the specified Collection's iterator. * //from w ww .j a v a 2s . c om * @param index * index at which to insert first element from the specified * collection. * @param c * elements to be inserted into this list. * @exception IndexOutOfBoundsException * index out of range (index < 0 || index > size()). */ public synchronized boolean addAll(int index, Collection c) { int len = array_.length; if (index > len || index < 0) throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + len); int numNew = c.size(); if (numNew == 0) return false; Object[] newArray = new Object[len + numNew]; System.arraycopy(array_, 0, newArray, 0, len); int numMoved = len - index; if (numMoved > 0) System.arraycopy(array_, index, newArray, index + numNew, numMoved); Iterator e = c.iterator(); for (int i = 0; i < numNew; i++) newArray[index++] = e.next(); array_ = newArray; return true; }
From source file:com.orion.parser.UrT42Parser.java
/** * Return the <tt>Mod</tt> matching the given hit code * //from w ww. java2 s . c o m * @author Daniele Pantaleone * @param hitcode The <tt>Mod</tt> hit code * @throws IndexOutOfBoundsException If the <tt>Mod</tt> hit code code is not mapped * @return The <tt>Mod</tt> matching the given hit code **/ public Mod getModByHitCode(int code) throws IndexOutOfBoundsException { if (!modByHitCode.containsKey(code)) throw new IndexOutOfBoundsException("could not retrieve a Mod using the given hit code: " + code); return modByHitCode.get(code); }