List of usage examples for java.lang IndexOutOfBoundsException IndexOutOfBoundsException
public IndexOutOfBoundsException()
From source file:eu.stratosphere.types.StringValue.java
@Override public char charAt(int index) { if (index < len) { return this.value[index]; } else {/* ww w.j a v a 2 s . co m*/ throw new IndexOutOfBoundsException(); } }
From source file:Base64InputStream.java
@Override public final void write(final byte[] buffer, final int offset, final int length) throws IOException { if (closed)/*ww w.j av a 2 s . c om*/ throw new IOException("Base64OutputStream has been closed"); if (buffer == null) throw new NullPointerException(); if (offset < 0 || length < 0 || offset + length > buffer.length) throw new IndexOutOfBoundsException(); if (length == 0) return; write0(buffer, offset, offset + length); }
From source file:gov.nasa.ensemble.common.CommonUtils.java
public static int readUpToOrEOF(byte b[], int off, int len, InputStream in) throws IOException { if (len < 0) throw new IndexOutOfBoundsException(); int n = 0;//w ww . j ava2 s.c o m while (n < len) { int count = in.read(b, off + n, len - n); if (count < 0) return n; n += count; } return n; }
From source file:edu.umd.cfar.lamp.viper.util.StringHelp.java
/** * Decodes a comma seperated list of quoted strings. * Quotes are encoded by doubling them.//w w w . ja va 2 s . co m * @param list * @return */ public static Iterator decodeDoublequotedList(final String list) { return new Iterator() { String next = null; int cursor = 0; private void cacheNext() { StringBuffer sb = new StringBuffer(); char next = list.charAt(cursor); if (next == '"') { // in a quoted thing while (cursor < list.length()) { next = list.charAt(cursor); if (next == '"') { cursor++; next = list.charAt(cursor); if (next == '"') { sb.append('"'); cursor++; continue; } else { cursor += 2; break; } } sb.append(next); cursor++; } } else { // in a bare string while (cursor < list.length()) { next = list.charAt(cursor); if (next == ',') { cursor++; break; } sb.append(next); cursor++; } } this.next = sb.toString(); } public boolean hasNext() { if (next == null) { cacheNext(); } return cursor < list.length(); } public Object next() { if (!hasNext()) { throw new IndexOutOfBoundsException(); } String r = next; next = null; return r; } public void remove() { throw new UnsupportedOperationException(); } }; }
From source file:io.github.karols.hocr4j.Bounds.java
/** * Divides this bounds vertically into <code>noOfSections</code> sections * of roughly the same width/*from ww w . j a v a 2 s. c o m*/ * and returns the bounds of sections with numbers from range * [<code>startIndex</code>, <code>endIndex</code>). * <br/> * Sections are numbered from the left, starting from 0. * * @param startIndex starting section number * @param endIndex final section number (not included in the result) * @param noOfSections total number of sections * @return bounds of the sections * @throws IllegalArgumentException if <code>noOfSections</code> is not positive * or <code>startIndex</code> > <code>endIndex</code> * @throws IndexOutOfBoundsException if <code>startIndex</code> < 0 * or <code>endIndex</code> < 0 * or <code>startIndex</code> > <code>noOfSections</code> * or <code>endIndex</code> > <code>noOfSections</code> */ public Bounds section(int startIndex, int endIndex, int noOfSections) { if (noOfSections < 1) { throw new IllegalArgumentException("noOfSections"); } if (startIndex < 0 || startIndex > noOfSections) { throw new IndexOutOfBoundsException(); } if (endIndex < 0 || endIndex > noOfSections) { throw new IndexOutOfBoundsException(); } if (endIndex < startIndex) { throw new IllegalArgumentException("startIndex has to be smaller than or equal to startIndex"); } if (noOfSections == 1 && startIndex == 0 && endIndex == 1) { return this; } return new Bounds(left + (startIndex * (right - left) / noOfSections), top, left + (int) Math.ceil(endIndex * (right - left) / (double) noOfSections), bottom); }
From source file:com.meidusa.amoeba.net.poolable.copy.CursorableLinkedList.java
/** * Returns a fail-fast sublist.// ww w.j a v a 2s.co m * @see List#subList(int,int) */ public List subList(int i, int j) { if (i < 0 || j > _size || i > j) { throw new IndexOutOfBoundsException(); } else if (i == 0 && j == _size) { return this; } else { return new CursorableSubList(this, i, j); } }
From source file:CopyOnWriteArrayList.java
/** * Returns a view of the portion of this list between * <tt>fromIndex</tt>, inclusive, and <tt>toIndex</tt>, exclusive. * The returned list is backed by this list, so changes in the * returned list are reflected in this list, and vice-versa. * While mutative operations are supported, they are probably not * very useful for CopyOnWriteArrayLists. * * <p>The semantics of the list returned by this method become * undefined if the backing list (i.e., this list) is * <i>structurally modified</i> in any way other than via the * returned list. (Structural modifications are those that change * the size of the list, or otherwise perturb it in such a fashion * that iterations in progress may yield incorrect results.) * * @param fromIndex low endpoint (inclusive) of the subList * @param toIndex high endpoint (exclusive) of the subList * @return a view of the specified range within this list * @throws IndexOutOfBoundsException {@inheritDoc} *//*from w w w .j av a 2 s . c o m*/ public synchronized List subList(int fromIndex, int toIndex) { Object[] elements = getArray(); int len = elements.length; if (fromIndex < 0 || toIndex > len || fromIndex > toIndex) throw new IndexOutOfBoundsException(); return new COWSubList(this, fromIndex, toIndex); }
From source file:CopyOnWriteArrayList.java
/** * Returns a view of the portion of this List between fromIndex, inclusive, * and toIndex, exclusive. The returned List is backed by this List, so * changes in the returned List are reflected in this List, and vice-versa. * While mutative operations are supported, they are probably not very * useful for CopyOnWriteArrays.//from w w w . ja va 2 s .com * </p> * The semantics of the List returned by this method become undefined if the * backing list (i.e., this List) is <i>structurally modified</i> in any * way other than via the returned List. (Structural modifications are those * that change the size of the List, or otherwise perturb it in such a * fashion that iterations in progress may yield incorrect results.) * * @param fromIndex * low endpoint (inclusive) of the subList. * @param toKey * high endpoint (exclusive) of the subList. * @return a view of the specified range within this List. * @exception IndexOutOfBoundsException * Illegal endpoint index value (fromIndex < 0 || toIndex * > size || fromIndex > toIndex). */ public synchronized List subList(int fromIndex, int toIndex) { // synchronized since sublist ctor depends on it. int len = array_.length; if (fromIndex < 0 || toIndex > len || fromIndex > toIndex) throw new IndexOutOfBoundsException(); return new COWSubList(this, fromIndex, toIndex); }
From source file:edu.oregonstate.eecs.mcplan.util.Fn.java
public static <T> T element(final Iterable<T> iterable, final int index) { assert (index >= 0); final Iterator<T> itr = iterable.iterator(); for (int i = 0; i < index; ++i) { if (!itr.hasNext()) { throw new IndexOutOfBoundsException(); }/* w w w . j ava 2 s .c om*/ itr.next(); } if (!itr.hasNext()) { throw new IndexOutOfBoundsException(); } return itr.next(); }
From source file:com.meidusa.amoeba.net.poolable.copy.CursorableLinkedList.java
CursorableSubList(CursorableLinkedList list, int from, int to) { if (0 > from || list.size() < to) { throw new IndexOutOfBoundsException(); } else if (from > to) { throw new IllegalArgumentException(); }//from w w w . j a v a 2 s . c om _list = list; if (from < list.size()) { _head.setNext(_list.getListableAt(from)); _pre = (null == _head.next()) ? null : _head.next().prev(); } else { _pre = _list.getListableAt(from - 1); } if (from == to) { _head.setNext(null); _head.setPrev(null); if (to < list.size()) { _post = _list.getListableAt(to); } else { _post = null; } } else { _head.setPrev(_list.getListableAt(to - 1)); _post = _head.prev().next(); } _size = to - from; _modCount = _list._modCount; }