Example usage for java.lang IndexOutOfBoundsException IndexOutOfBoundsException

List of usage examples for java.lang IndexOutOfBoundsException IndexOutOfBoundsException

Introduction

In this page you can find the example usage for java.lang IndexOutOfBoundsException IndexOutOfBoundsException.

Prototype

public IndexOutOfBoundsException(int index) 

Source Link

Document

Constructs a new IndexOutOfBoundsException class with an argument indicating the illegal index.

Usage

From source file:DynamicLongArray.java

public long get(int index) {
    if (index >= _length) {
        throw new IndexOutOfBoundsException("Index " + index + " is outside of 0.." + (_length - 1));
    }//  w  w  w  . j a  v a  2 s  .  c o  m
    int i = index / _chunkSize;
    int j = index % _chunkSize;
    if (_data[i] == null) {
        return 0;
    } else {
        return _data[i][j];
    }
}

From source file:Main.java

public static <T> T[] remove(final T[] array, final int from, final int to) {
    assert (to >= from) : to + " - " + from;
    int length = getLength(array);
    if (from < 0 || to >= length) {
        throw new IndexOutOfBoundsException("from: " + from + ", to: " + to + ", Length: " + length);
    }/*from  w  w w  . ja  v a  2  s  . co  m*/
    int remsize = to - from + 1;
    Object result = Array.newInstance(array.getClass().getComponentType(), length - remsize);
    System.arraycopy(array, 0, result, 0, from);
    if (to < length - 1) {
        System.arraycopy(array, to + 1, result, from, length - to - 1);
    }
    return (T[]) result;
}

From source file:de.cosmocode.json.JsonArrayList.java

@Override
public Object get(int index) {
    if (index < 0 || index >= size())
        throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size());
    final Object value = array.opt(index);
    if (value instanceof JSONObject) {
        final JSONObject json = JSONObject.class.cast(value);
        return JSON.asMap(json);
    } else if (value instanceof JSONArray) {
        final JSONArray json = JSONArray.class.cast(value);
        return JSON.asList(json);
    } else if (value == null || value.equals(NULL)) {
        return null;
    } else {/*from www  .jav  a  2 s  .co m*/
        return value;
    }
}

From source file:ThreadSafeIntList.java

public synchronized int get(int index) {
    if (index < 0 || index >= size) // Check that argument is legitimate
        throw new IndexOutOfBoundsException(String.valueOf(index));
    return data[index];
}

From source file:com.github.haixing_hu.csl.util.Argument.java

/**
 * Checks the current bounds.//from   w  w w. j  av  a2  s . c  o m
 * <p>
 * Note that the checking is non-trivial, since we have to consider the
 * integer overflows.
 * </p>
 *
 * @param off
 *          the offset.
 * @param n
 *          the number of elements.
 * @param length
 *          the length of the sequence.
 * @throws IndexOutOfBoundsException
 *           If the current is out of bounds.
 */
public static void checkBounds(final int off, final int n, final int length) {
    if ((off < 0) || (n < 0) || (off > (length - n))) {
        throw new IndexOutOfBoundsException("off: " + off + " n: " + n + " length: " + length);
    }
}

From source file:ru.jts_dev.gameserver.packets.in.RequestProtocolVersion.java

@Override
public void run() {
    GameSession session = sessionService.getSessionBy(getConnectionId());

    byte[] key = session.getDecryptKey().copy(0, 8).array();
    if (key.length != 8)
        throw new IndexOutOfBoundsException("client part of key must be 8 byte");

    // TODO: 13.12.15 check protocol version compatibility
    broadcastService.send(session, new VersionCheck(key, gameServerConfig.getServerId()));
}

From source file:com.evolveum.midpoint.prism.xjc.PrismReferenceArrayList.java

private void testIndex(int i) {
    if (i < 0 || i >= getReference().getValues().size()) {
        throw new IndexOutOfBoundsException(
                "Can't get index '" + i + "', values size is '" + getReference().getValues().size() + "'.");
    }//from  w  w  w  .  ja v  a  2s. c om
}

From source file:com.letv.mobile.core.rpc.http.util.ParserCursor.java

public ParserCursor(int lowerBound, int upperBound) {
    super();/*from  www.ja v  a2 s  . c o m*/
    if (lowerBound < 0) {
        throw new IndexOutOfBoundsException("Lower bound cannot be negative");
    }
    if (lowerBound > upperBound) {
        throw new IndexOutOfBoundsException("Lower bound cannot be greater then upper bound");
    }
    this.lowerBound = lowerBound;
    this.upperBound = upperBound;
    this.pos = lowerBound;
}

From source file:ru.jts_dev.common.packets.IncomingMessageWrapper.java

public final byte readByte() {
    if (payload.readableBytes() < Byte.BYTES)
        throw new IndexOutOfBoundsException("At least 1 byte1 must be readable in payload");

    return payload.readByte();
}

From source file:com.galenframework.parser.CommandLineReader.java

public Pair<String, String> readArgument() {
    if (hasNext()) {
        String argumentName = convertArgumentName(readNext());
        if (hasNext()) {
            String argumentValue = readNext();
            return new ImmutablePair<>(argumentName, argumentValue);
        } else {/*from  w w w .  j a  v a2s . c o m*/
            throw new IndexOutOfBoundsException("Argument '" + argumentName + "' doesn't have a value");
        }

    } else {
        throw new IndexOutOfBoundsException();
    }
}