List of usage examples for java.lang IndexOutOfBoundsException IndexOutOfBoundsException
public IndexOutOfBoundsException()
From source file:com.hadoop.compression.lzo.LzopOutputStream.java
@Override public void write(byte[] b, int off, int len) throws IOException { // TODO: LzopOutputStream used to inherit from BlockCompressorStream // but had a bug due to this inheritance chain. In order to fix the // bug we pulled down the implementation of the superclass, which // is overly general. Thus this function is not quite as succint // as it could be, now that it's LZOP-specific. // See: http://github.com/toddlipcon/hadoop-lzo/commit/5fe6dd4736a73fa33b86656ce8aeb011e7f2046c // Sanity checks if (compressor.finished()) { throw new IOException("write beyond end of stream"); }/* w w w . ja v a2 s . c o m*/ if (b == null) { throw new NullPointerException(); } else if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return; } long limlen = compressor.getBytesRead(); if (len + limlen > MAX_INPUT_SIZE && limlen > 0) { // Adding this segment would exceed the maximum size. // Flush data if we have it. finish(); compressor.reset(); } if (len > MAX_INPUT_SIZE) { // The data we're given exceeds the maximum size. Any data // we had have been flushed, so we write out this chunk in segments // not exceeding the maximum size until it is exhausted. do { int bufLen = Math.min(len, MAX_INPUT_SIZE); compressor.setInput(b, off, bufLen); finish(); compressor.reset(); off += bufLen; len -= bufLen; } while (len > 0); return; } // Give data to the compressor compressor.setInput(b, off, len); if (!compressor.needsInput()) { // compressor buffer size might be smaller than the maximum // size, so we permit it to flush if required. do { compress(); } while (!compressor.needsInput()); } }
From source file:com.opengamma.util.timeseries.fast.integer.object.FastMapIntObjectTimeSeries.java
@Override public T getValueAtFast(final int index) { if (index >= _map.size()) { throw new IndexOutOfBoundsException(); }/*from w w w . j a v a 2s . c o m*/ final IntBidirectionalIterator iterator = _map.keySet().iterator(); iterator.skip(index); return _map.get(iterator.nextInt()); }
From source file:com.opengamma.util.timeseries.fast.longint.object.FastMapLongObjectTimeSeries.java
@Override public T getValueAtFast(final int index) { if (index >= _map.size() || index < 0) { throw new IndexOutOfBoundsException(); }// www .ja va 2s. c o m final LongBidirectionalIterator iterator = _map.keySet().iterator(); iterator.skip(index); return _map.get(iterator.nextLong()); }
From source file:FastStack.java
/** * Returns the item at the specified slot in the stack. * /*from w w w .ja va 2 s . co m*/ * @param index * the index. * * @return The item. */ public Object get(final int index) { if (index >= this.size) { throw new IndexOutOfBoundsException(); } return this.contents[index]; }
From source file:com.google.api.client.util.ArrayMap.java
/** * Sets the key/value mapping at the given index, overriding any existing key/value mapping. * <p>/* w w w . j av a 2 s . co m*/ * There is no checking done to ensure that the key does not already exist. Therefore, this method * is dangerous to call unless the caller can be certain the key does not already exist in the * map. * * @return previous value or {@code null} for none * @throws IndexOutOfBoundsException if index is negative */ public final V set(int index, K key, V value) { if (index < 0) { throw new IndexOutOfBoundsException(); } int minSize = index + 1; ensureCapacity(minSize); int dataIndex = index << 1; V result = valueAtDataIndex(dataIndex + 1); setData(dataIndex, key, value); if (minSize > this.size) { this.size = minSize; } return result; }
From source file:com.github.rvesse.airline.restrictions.options.MutuallyExclusiveRestriction.java
@Override public String[] getContentBlock(int blockNumber) { if (blockNumber != 0) throw new IndexOutOfBoundsException(); return new String[] { String.format( "This option is part of the group '%s' from which only one option may be specified", this.tag) }; }
From source file:com.evolveum.midpoint.prism.xjc.AnyArrayList.java
@Override public Object remove(int index) { if (isSchemaless()) { return containerValue.getRawElements().remove(index); } else {/*from w w w. j a v a 2s .c o m*/ for (Item<?, ?> item : containerValue.getItems()) { if (index < item.getValues().size()) { item.remove(index); } else { index -= item.getValues().size(); } } throw new IndexOutOfBoundsException(); } }
From source file:name.martingeisse.stackd.common.cubes.RawCubes.java
/** * /*from w w w . ja v a2 s. c om*/ */ final int getRelativeCubeIndex(final ClusterSize clusterSize, final int x, final int y, final int z) { final int size = clusterSize.getSize(); if (x < 0 || y < 0 || z < 0 || x >= size || y >= size || z >= size) { throw new IndexOutOfBoundsException(); } return (x * size + y) * size + z; }
From source file:org.nabucco.alfresco.enhScriptEnv.common.script.aop.ListLikeMapAdapterInterceptor.java
/** * {@inheritDoc}/*w w w .j av a 2 s. c o m*/ */ @Override public Object invoke(final MethodInvocation invocation) throws Throwable { final Object result; final Method method = invocation.getMethod(); final Class<?> declaringClass = method.getDeclaringClass(); final Object this1 = invocation.getThis(); if ((List.class.equals(declaringClass) || Collection.class.equals(declaringClass)) && !(this1 instanceof List<?>)) { if (invocation instanceof ProxyMethodInvocation && ((ProxyMethodInvocation) invocation).getProxy() instanceof Map<?, ?>) { final Map<?, ?> map = (Map<?, ?>) ((ProxyMethodInvocation) invocation).getProxy(); final String methodName = method.getName(); boolean proceedInvocation = false; Object adaptedResult = null; final Object[] arguments = invocation.getArguments(); final Class<?>[] parameterTypes = method.getParameterTypes(); // String-switch not supported in Java < 8 switch (ListMethodName.methodLiteralOf(methodName)) { case SIZE: adaptedResult = Integer.valueOf(map.size()); break; case ISEMPTY: adaptedResult = Boolean.valueOf(map.isEmpty()); break; case CONTAINS: adaptedResult = Boolean.valueOf(map.containsValue(arguments[0])); break; case ITERATOR: adaptedResult = map.values().iterator(); break; case TOARRAY: adaptedResult = arguments.length == 1 ? map.values().toArray((Object[]) arguments[0]) : map.values().toArray(); break; case CONTAINSALL: adaptedResult = Boolean.valueOf(map.values().containsAll((Collection<?>) arguments[0])); break; case REMOVEALL: adaptedResult = Boolean.valueOf(map.values().removeAll((Collection<?>) arguments[0])); break; case INDEXOF: { int idx = 0; int foundIdx = -1; final Iterator<?> valueIterator = map.values().iterator(); while (valueIterator.hasNext()) { final Object el = valueIterator.next(); if (el == arguments[0] || (arguments[0] != null && arguments[0].equals(el))) { foundIdx = idx; break; } idx++; } adaptedResult = Integer.valueOf(foundIdx); } break; case LASTINDEXOF: { int idx = 0; int foundIdx = -1; final Iterator<?> valueIterator = map.values().iterator(); while (valueIterator.hasNext()) { final Object el = valueIterator.next(); if (el == arguments[0] || (arguments[0] != null && arguments[0].equals(el))) { foundIdx = idx; } idx++; } adaptedResult = Integer.valueOf(foundIdx); } break; case GET: { final int targetIdx = ((Integer) arguments[0]).intValue(); if (targetIdx < 0 || targetIdx >= map.size()) { throw new IndexOutOfBoundsException(); } int idx = 0; Object found = null; final Iterator<?> valueIterator = map.values().iterator(); while (valueIterator.hasNext()) { final Object el = valueIterator.next(); if (idx == targetIdx) { found = el; break; } idx++; } adaptedResult = found; } break; case REMOVE: { if (arguments[0] instanceof Integer && int.class.equals(parameterTypes[0])) { final int targetIdx = ((Integer) arguments[0]).intValue(); if (targetIdx < 0 || targetIdx >= map.size()) { throw new IndexOutOfBoundsException(); } int idx = 0; final Iterator<?> keyIterator = map.keySet().iterator(); Object keyToRemove = null; while (keyIterator.hasNext()) { final Object el = keyIterator.next(); if (idx == targetIdx) { keyToRemove = el; break; } idx++; } adaptedResult = keyToRemove != null ? map.remove(keyToRemove) : null; } else { adaptedResult = Boolean.valueOf(map.values().remove(arguments[0])); } } break; case RETAINALL: adaptedResult = Boolean.valueOf(map.values().retainAll((Collection<?>) arguments[0])); break; case CLEAR: map.clear(); break; case LISTITERATOR: // fallthrough case SUBLIST: // fallthrough case SET:// fallthrough case ADD:// fallthrough case ADDALL: // not supported throw new UnsupportedOperationException(); default: proceedInvocation = true; } if (proceedInvocation) { // may fail (if we have forgotten to map a specific operation or a new operation may have been introduced) result = invocation.proceed(); } else { result = adaptedResult; } } else { // may fail when other interceptors / target do not support List result = invocation.proceed(); } } else { // may fail when List was declaring class but type of "this" does not support this interceptor result = invocation.proceed(); } return result; }
From source file:ByteArrayOutputStream.java
/** * @see java.io.OutputStream#write(byte[], int, int) *//*from www . j a va 2s .co m*/ public void write(byte[] b, int off, int len) { if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return; } synchronized (this) { int newcount = count + len; int remaining = len; int inBufferPos = count - filledBufferSum; while (remaining > 0) { int part = Math.min(remaining, currentBuffer.length - inBufferPos); System.arraycopy(b, off + len - remaining, currentBuffer, inBufferPos, part); remaining -= part; if (remaining > 0) { needNewBuffer(newcount); inBufferPos = 0; } } count = newcount; } }