List of usage examples for java.lang IndexOutOfBoundsException IndexOutOfBoundsException
public IndexOutOfBoundsException(int index)
From source file:CopyOnWriteArrayList.java
/** * Check if the given index is in range. If not, throw an appropriate * runtime exception./*from w ww .java2s. c o m*/ * @param index * @param length */ protected void rangeCheck(int index, int length) { if (index >= length || index < 0) throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + length); }
From source file:de.tudarmstadt.ukp.clarin.webanno.crowdflower.NamedEntityTaskManager.java
/** * Helper function for uploadNewNERTask2: Get the string char position of the i-th span from the * HTML token spans that the Crowdflower job task1 uses to display a textfragment. * * @param spans - HTML span string//from w ww.j a v a 2 s . co m * @param spannumber - the span number to extract the position for * @return index in spans string for the n-th occurence of a span * @throws Exception */ private int getSpanPos(String spans, int spannumber) throws IndexOutOfBoundsException { // find all occurrences <span> forward int count = 0; for (int i = -1; (i = spans.indexOf(HTML_OPEN_SPAN, i + 1)) != -1;) { if (spannumber == count) { return i; } count++; } throw new IndexOutOfBoundsException( "Token index not found in getSpanPos:" + spannumber + " in span: " + spans); }
From source file:com.orion.parser.UrT42Parser.java
/** * Return the <tt>Team</tt> matching the given code * /*from w w w . j a va 2 s . c o m*/ * @author Daniele Pantaleone * @param code The <tt>Team</tt> code * @throws IndexOutOfBoundsException If the <tt>Team</tt> code is not mapped * @return The <tt>Team</tt> matching the given code **/ public Team getTeamByCode(Integer code) throws IndexOutOfBoundsException { if (!teamByCode.containsKey(code)) throw new IndexOutOfBoundsException("could not retrieve a Team using the given code: " + code); return teamByCode.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 this list in the order that they are returned by the * specified collection's iterator./* ww w . j ava2 s .c o m*/ * * @param index index at which to insert the first element * from the specified collection * @param c collection containing elements to be added to this list * @return <tt>true</tt> if this list changed as a result of the call * @throws IndexOutOfBoundsException {@inheritDoc} * @throws NullPointerException if the specified collection is null * @see #add(int,Object) */ public boolean addAll(int index, Collection c) { int numNew = c.size(); synchronized (this) { Object[] elements = getArray(); int len = elements.length; if (index > len || index < 0) throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + len); if (numNew == 0) return false; int numMoved = len - index; Object[] newElements; if (numMoved == 0) newElements = copyOf(elements, len + numNew); else { newElements = new Object[len + numNew]; System.arraycopy(elements, 0, newElements, 0, index); System.arraycopy(elements, index, newElements, index + numNew, numMoved); } for (Iterator itr = c.iterator(); itr.hasNext();) { Object e = itr.next(); newElements[index++] = e; } setArray(newElements); return true; } }
From source file:com.orion.parser.UrT42Parser.java
/** * Return the Team by matching the given name. * // w ww .java2s. co m * @author Daniele Pantaleone * @param name The <tt>Team</tt> name * @throws IndexOutOfBoundsException If the <tt>Team</tt> name is not mapped * @return The <tt>Team</tt> matching the given name **/ public Team getTeamByName(String name) throws IndexOutOfBoundsException { name = name.toUpperCase(); switch (name) { case "F": name = "FREE"; break; case "R": name = "RED"; break; case "B": name = "BLUE"; break; case "S": name = "SPECTATOR"; break; case "SPEC": name = "SPECTATOR"; break; } if (!teamByName.containsKey(name)) throw new IndexOutOfBoundsException("could not retrieve a Team using the given name: " + name); return teamByName.get(name); }
From source file:com.meidusa.amoeba.net.poolable.copy.CursorableLinkedList.java
/** * Returns the // ww w. j a v a 2 s . c o m * {@link org.apache.commons.collections.CursorableLinkedList.Listable} * at the specified index. * * @throws IndexOutOfBoundsException if index is less than zero or * greater than or equal to the size of this list. */ protected Listable getListableAt(int index) { if (index < 0 || index >= _size) { throw new IndexOutOfBoundsException( String.valueOf(index) + " < 0 or " + String.valueOf(index) + " >= " + _size); } if (index <= _size / 2) { Listable elt = _head.next(); for (int i = 0; i < index; i++) { elt = elt.next(); } return elt; } else { Listable elt = _head.prev(); for (int i = (_size - 1); i > index; i--) { elt = elt.prev(); } return elt; } }
From source file:com.github.jessemull.microflexbigdecimal.plate.WellSet.java
/** * Returns a view of the portion of this set between the indices. * @param int the first index//from w ww. j av a 2 s. co m * @param int the second index * @param boolean includes the first input well in the returned set * @param boolean includes the second input well in the returned set * @return last well in the set */ public Set<Well> subSet(int index1, boolean inclusive1, int index2, boolean inclusive2) { if (index1 > this.wells.size() - 1 || index2 > this.wells.size() - 1 || index1 < 0 || index2 < 0 || index1 > index2) { throw new IndexOutOfBoundsException("Index is outside of valid range: " + index1 + " " + index2); } int current = 0; Set<Well> subset = new TreeSet<Well>(); Iterator<Well> iter = this.wells.iterator(); while (current < index1) { if (current == index1 && inclusive1) { subset.add(iter.next()); } iter.next(); current++; } while (current < index2) { if (current++ == index2 && inclusive2) { subset.add(iter.next()); break; } subset.add(iter.next()); } return subset; }
From source file:com.github.jessemull.microflex.doubleflex.plate.WellSetDouble.java
/** * Returns a view of the portion of this set between the indices. * @param int the first index//from w w w . ja va 2s. c om * @param int the second index * @param boolean includes the first input well in the returned set * @param boolean includes the second input well in the returned set * @return last well in the set */ public Set<WellDouble> subSet(int index1, boolean inclusive1, int index2, boolean inclusive2) { if (index1 > this.wells.size() - 1 || index2 > this.wells.size() - 1 || index1 < 0 || index2 < 0 || index1 > index2) { throw new IndexOutOfBoundsException("Index is outside of valid range: " + index1 + " " + index2); } int current = 0; Set<WellDouble> subset = new TreeSet<WellDouble>(); Iterator<WellDouble> iter = this.wells.iterator(); while (current < index1) { if (current == index1 && inclusive1) { subset.add(iter.next()); } iter.next(); current++; } while (current < index2) { if (current++ == index2 && inclusive2) { subset.add(iter.next()); break; } subset.add(iter.next()); } return subset; }
From source file:com.github.jessemull.microflex.integerflex.plate.WellSetInteger.java
/** * Returns a view of the portion of this set between the indices. * @param int the first index//from w w w .j a va 2 s.c o m * @param int the second index * @param boolean includes the first input well in the returned set * @param boolean includes the second input well in the returned set * @return last well in the set */ public Set<WellInteger> subSet(int index1, boolean inclusive1, int index2, boolean inclusive2) { if (index1 > this.wells.size() - 1 || index2 > this.wells.size() - 1 || index1 < 0 || index2 < 0 || index1 > index2) { throw new IndexOutOfBoundsException("Index is outside of valid range: " + index1 + " " + index2); } int current = 0; Set<WellInteger> subset = new TreeSet<WellInteger>(); Iterator<WellInteger> iter = this.wells.iterator(); while (current < index1) { if (current == index1 && inclusive1) { subset.add(iter.next()); } iter.next(); current++; } while (current < index2) { if (current++ == index2 && inclusive2) { subset.add(iter.next()); break; } subset.add(iter.next()); } return subset; }
From source file:com.github.jessemull.microflex.bigintegerflex.plate.WellSetBigInteger.java
/** * Returns a view of the portion of this set between the indices. * @param int the first index//from ww w . j a v a2s . c o m * @param int the second index * @param boolean includes the first input well in the returned set * @param boolean includes the second input well in the returned set * @return last well in the set */ public Set<WellBigInteger> subSet(int index1, boolean inclusive1, int index2, boolean inclusive2) { if (index1 > this.wells.size() - 1 || index2 > this.wells.size() - 1 || index1 < 0 || index2 < 0 || index1 > index2) { throw new IndexOutOfBoundsException("Index is outside of valid range: " + index1 + " " + index2); } int current = 0; Set<WellBigInteger> subset = new TreeSet<WellBigInteger>(); Iterator<WellBigInteger> iter = this.wells.iterator(); while (current < index1) { if (current == index1 && inclusive1) { subset.add(iter.next()); } iter.next(); current++; } while (current < index2) { if (current++ == index2 && inclusive2) { subset.add(iter.next()); break; } subset.add(iter.next()); } return subset; }