List of usage examples for java.lang IndexOutOfBoundsException IndexOutOfBoundsException
public IndexOutOfBoundsException(int index)
From source file:CopyOnWriteArrayList.java
/** * Inserts the specified element at the specified position in this list. * Shifts the element currently at that position (if any) and any subsequent * elements to the right (adds one to their indices). * // w w w . j ava 2 s . c o m * @param index * index at which the specified element is to be inserted. * @param element * element to be inserted. * @exception IndexOutOfBoundsException * index is out of range (index < 0 || index > size()). */ public synchronized void add(int index, Object element) { int len = array_.length; if (index > len || index < 0) throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + len); Object[] newArray = new Object[len + 1]; System.arraycopy(array_, 0, newArray, 0, index); newArray[index] = element; System.arraycopy(array_, index, newArray, index + 1, len - index); array_ = newArray; }
From source file:com.facebook.GraphObjectAdapter.java
SectionAndItem<T> getSectionAndItem(int position) { if (sectionKeys.size() == 0) { return null; }//from ww w . jav a 2 s. c o m String sectionKey = null; T graphObject = null; if (!displaySections) { sectionKey = sectionKeys.get(0); List<T> section = graphObjectsBySection.get(sectionKey); if (position >= 0 && position < section.size()) { graphObject = graphObjectsBySection.get(sectionKey).get(position); } else { // We are off the end; we must be adding an activity circle to indicate more data is coming. assert dataNeededListener != null && cursor.areMoreObjectsAvailable(); // We return null for both to indicate this. return new SectionAndItem<T>(null, null); } } else { // Count through the sections; the "0" position in each section is the header. We decrement // position each time we skip forward a certain number of elements, including the header. for (String key : sectionKeys) { // Decrement if we skip over the header if (position-- == 0) { sectionKey = key; break; } List<T> section = graphObjectsBySection.get(key); if (position < section.size()) { // The position is somewhere in this section. Get the corresponding graph object. sectionKey = key; graphObject = section.get(position); break; } // Decrement by as many items as we skipped over position -= section.size(); } } if (sectionKey != null) { // Note: graphObject will be null if this represents a section header. return new SectionAndItem<T>(sectionKey, graphObject); } else { throw new IndexOutOfBoundsException("position"); } }
From source file:de.codesourcery.jasm16.ast.ASTNode.java
/** * Replaces a child node at a specific position. * /*from www. ja v a2 s . c o m*/ * @param index * @param newChild */ public final void setChild(int index, ASTNode newChild) { if (newChild == null) { throw new IllegalArgumentException("newChild must not be NULL"); } if (index < 0 || index >= children.size()) { throw new IndexOutOfBoundsException( "Invalid index " + index + " ( must be >= 0 and < " + children.size() + ")"); } assertSupportsChildNodes(); children.set(index, newChild); newChild.setParent(this); }
From source file:at.ofai.gate.virtualcorpus.JDBCCorpus.java
/** * Return the document for the given index in the corpus. * An IndexOutOfBoundsException is thrown when the index is not contained * in the corpus./* w ww .j a va 2s. co m*/ * The document will be read from the file only if it is not already loaded. * If it is already loaded a reference to that document is returned. * * @param index * @return */ public Document get(int index) { //System.out.println("DirCorp: called get(index): "+index); if (index < 0 || index >= documentNames.size()) { throw new IndexOutOfBoundsException( "Index " + index + " not in corpus " + this.getName() + " of size " + documentNames.size()); } String docName = documentNames.get(index); if (isDocumentLoaded(index)) { Document doc = loadedDocuments.get(docName); //System.out.println("Returning loaded document "+doc); return doc; } //System.out.println("Document not loaded, reading"); Document doc; try { doc = readDocument(docName); } catch (Exception ex) { throw new GateRuntimeException("Problem retrieving document data for " + docName, ex); } loadedDocuments.put(docName, doc); isLoadeds.set(index, true); adoptDocument(doc); return doc; }
From source file:org.opencron.common.utils.StringUtils.java
public static String toLowerCase(String str, int index, int len) { if (CommonUtils.isEmpty(str)) throw new NullPointerException("str can not be empty??"); if (index <= 0 || (index + len - 1) > str.length()) { throw new IndexOutOfBoundsException( "Position must be greater than 0 and not less than the length of the string to be processed"); }/*from ww w . j a v a 2s. c o m*/ if (index == 1) {//?? return str.substring(0, len).toLowerCase() + str.substring(len); } return str.substring(0, index - 1) + str.substring(index - 1, len + 1).toLowerCase() + str.substring(index + len - 1); }
From source file:de.codesourcery.jasm16.ast.ASTNode.java
/** * Returns the Nth child.//from w w w . ja va 2 s . c o m * * @param index * @return * @throws IndexOutOfBoundsException if the index is either less than zero or larger than {@link #getChildCount()} -1 */ public final ASTNode child(int index) { if (index < 0 || index >= children.size()) { throw new IndexOutOfBoundsException( "Invalid index " + index + " , node " + this + " has only " + children.size() + " children"); } return children.get(index); }
From source file:com.iyonger.apm.web.util.Preconditions.java
/** * Ensures that {@code index} specifies a valid <i>position</i> in an array, list or string of size {@code size}. A * position index may range from zero to {@code size}, inclusive. * * @param index a user-supplied index identifying a position in an array, list or string * @param size the size of that array, list or string * @param desc the text to use to describe this index in an error message * @return the value of {@code index}/* ww w . j a va 2 s. c o m*/ */ public static int checkPositionIndex(int index, int size, @Nullable String desc) { // Carefully optimized for execution by hotspot (explanatory comment // above) if (index < 0 || index > size) { throw new IndexOutOfBoundsException(buildBadPositionIndexMessage(index, size, desc)); } return index; }
From source file:net.grinder.util.Preconditions.java
/** * Ensures that {@code start} and {@code end} specify a valid <i>positions</i> in an array, list * or string of size {@code size}, and are in order. A position index may range from zero to * {@code size}, inclusive.//from w w w .ja va2s . com * * @param start * a user-supplied index identifying a starting position in an array, list or string * @param end * a user-supplied index identifying a ending position in an array, list or string * @param size * the size of that array, list or string */ public static void checkPositionIndexes(int start, int end, int size) { // Carefully optimized for execution by hotspot (explanatory comment // above) if (start < 0 || end < start || end > size) { throw new IndexOutOfBoundsException(badPositionIndexes(start, end, size)); } }
From source file:com.slytechs.utils.region.FlexRegion.java
/** * @param start//from www . j av a 2 s . c o m * global start * @param oldLength * number of elements to be replaced * @param newLength * number of elements to replace the old segment * @param data * data associated with this replacement * @return TODO */ public final RegionSegment[] replace(final long start, final long oldLength, final long newLength, final T data) { this.throwIfReadonly(); if ((oldLength == 0) && (newLength == 0)) { return null; // Nothing to do } this.modifiedAtLeastOnce = true; this.support.fireReplace(start, oldLength, newLength, data); this.changeHappened(); final int i = this.getSegmentIndex(start); final RegionSegment<T> first = this.segments.get(i); if ((first.checkBoundsGlobal(start) == false) || (first.checkBoundsGlobal(start, oldLength) == false)) { throw new IndexOutOfBoundsException("Replacement request [" + start + "] falls outside the segment's [" + first.toString() + "] boundaries"); } final long startLocal = first.mapGlobalToLocal(start); final long firstEndLocal = first.getEndLocal(); final long endLocal = startLocal + oldLength; final RegionSegment[] newSegment; if (startLocal == 0) { newSegment = new RegionSegment[1]; newSegment[0] = this.replaceFront(first, start, oldLength, newLength, data); } else if (endLocal == firstEndLocal) { newSegment = new RegionSegment[1]; newSegment[0] = this.replaceBack(first, start, oldLength, newLength, data); } else { newSegment = this.replaceMiddle(first, i, start, oldLength, newLength, data); } this.support.fireLinkSegment(newSegment); if (logger.isTraceEnabled()) { logger.trace("start" + start + ", old=" + oldLength + ", new=" + newLength + ", data=" + data + " AFTER:" + toString()); } return newSegment; }
From source file:com.netxforge.oss2.xml.event.Event.java
/** * Method getForward./*from www .j ava 2 s . com*/ * * @param index * @throws IndexOutOfBoundsException * if the index given is outside the bounds of the collection * @return the value of the Forward at the * given index */ public Forward getForward(final int index) throws IndexOutOfBoundsException { // check bounds for index if (index < 0 || index >= _forwardList.size()) { throw new IndexOutOfBoundsException( "getForward: Index value '" + index + "' not in range [0.." + (_forwardList.size() - 1) + "]"); } return _forwardList.get(index); }