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() 

Source Link

Document

Constructs an IndexOutOfBoundsException with no detail message.

Usage

From source file:MultiMap.java

/** Get item from the list 
 * @param list  A LazyList returned from LazyList.add(Object) or null
 * @param i int index//  w  w  w.  java 2  s  .  c om
 * @return the item from the list.
 */
public static Object get(Object list, int i) {
    if (list == null)
        throw new IndexOutOfBoundsException();

    if (list instanceof List)
        return ((List) list).get(i);

    if (i == 0)
        return list;

    throw new IndexOutOfBoundsException();
}

From source file:fr.inria.atlanmod.neoemf.graph.blueprints.datastore.estores.impl.DirectWriteBlueprintsResourceEStoreImpl.java

protected Object remove(InternalEObject object, EAttribute eAttribute, int index) {
    Vertex vertex = graph.getVertex(object);
    Integer size = getSize(vertex, eAttribute);
    Object returnValue = null;//from  w  w  w  .  ja v a2 s .  com
    if (index < 0 || index > size) {
        throw new IndexOutOfBoundsException();
    } else {
        returnValue = parseProperty(eAttribute, vertex.getProperty(eAttribute.getName() + SEPARATOR + index));
        int newSize = size - 1;
        for (int i = newSize; i > index; i--) {
            Object movingProperty = vertex.getProperty(eAttribute.getName() + SEPARATOR + i);
            vertex.setProperty(eAttribute.getName() + SEPARATOR + (i - 1), movingProperty);
        }
        setSize(vertex, eAttribute, newSize);
    }
    return returnValue;
}

From source file:fr.inria.atlanmod.neoemf.graph.blueprints.datastore.estores.impl.DirectWriteBlueprintsResourceEStoreImpl.java

protected Object remove(InternalEObject object, EReference eReference, int index) {
    Vertex vertex = graph.getVertex(object);
    String referenceName = eReference.getName();
    Integer size = getSize(vertex, eReference);
    Object returnValue = null;/*from   w ww . jav a2 s .c  o  m*/
    if (index < 0 || index > size) {
        throw new IndexOutOfBoundsException();
    } else {
        Iterator<Edge> iterator = vertex.query().labels(referenceName).direction(Direction.OUT)
                .interval(POSITION, index, size).edges().iterator();
        while (iterator.hasNext()) {
            Edge edge = iterator.next();
            int position = edge.getProperty(POSITION);
            if (position == index) {
                Vertex referencedVertex = edge.getVertex(Direction.IN);
                returnValue = reifyVertex(referencedVertex);
                edge.remove();
            } else {
                edge.setProperty(POSITION, position - 1);
            }
        }
    }
    setSize(vertex, eReference, size - 1); // Update size
    return returnValue;
}

From source file:com.sawyer.advadapters.widget.JSONAdapter.java

@Override
public Object getItem(int position) {
    Object object = mObjects.opt(position);
    if (object == null) {
        //A pain but can't add throws to this overridden method
        if (position < 0 || position >= mObjects.length()) {
            throw new IndexOutOfBoundsException();
        } else {//w ww .  ja  v a 2  s . c  om
            throw new NullPointerException();
        }
    }
    return object;
}

From source file:de.escidoc.core.common.util.security.helper.InvocationParser.java

/**
 * Gets the {@link StringAttribute} for the provided values.
 *
 * @param arguments         The arguments of the method call.
 * @param isArray           Flag that indicates that the given arguments parameter is an array (<code>true</code>)
 *                          or not (<code>false</code>).
 * @param index             The index of the current object.
 * @param invocationMapping The {@link InvocationMapping} to get the value for.
 * @return Returns a {@link StringAttribute} with the value for the invocation mapping.
 * @throws MissingMethodParameterException
 *                                  Thrown if a mandatory method parameter is not provided.
 * @throws WebserverSystemException Thrown in case of an internal error.
 * @throws de.escidoc.core.common.exceptions.application.invalid.XmlCorruptedException
 *//*from  w w  w.  j ava  2 s .co m*/
private StringAttribute getValueForInvocationMapping(final Object arguments, final boolean isArray,
        final int index, final InvocationMapping invocationMapping)
        throws WebserverSystemException, MissingMethodParameterException, XmlCorruptedException {

    // set the value
    final StringAttribute value;
    if (invocationMapping.getMappingType() == InvocationMapping.VALUE_MAPPING) {
        // fetch the value from inside the invocation mapping
        value = new StringAttribute(invocationMapping.getValue());
    } else {
        // Get the current object addressed by the invocation mapping
        final Object currentObject;
        if (isArray) {
            currentObject = ((Object[]) arguments)[invocationMapping.getPosition()];
        } else {
            if (invocationMapping.getPosition() != 0) {
                throw new WebserverSystemException("Invocation mapping error. Position "
                        + invocationMapping.getPosition() + " invalid for single argument, must be 0. [id="
                        + invocationMapping.getId() + ']');
            }
            currentObject = arguments;
        }

        // assert the addressed object has been provided
        if (currentObject == null) {
            throw new MissingMethodParameterException("The parameter at specified "
                    + "position must be provided" + (invocationMapping.getPosition() + 1));
        }
        if (invocationMapping.getMappingType() == InvocationMapping.SIMPLE_ATTRIBUTE_MAPPING) {
            value = new StringAttribute(currentObject.toString());
        } else if (invocationMapping.getMappingType() == InvocationMapping.XML_ATTRIBUTE_MAPPING
                || invocationMapping.getMappingType() == InvocationMapping.OPTIONAL_XML_ATTRIBUTE_MAPPING) {
            // fetch the value from XML document
            final Document document;
            try {
                document = documentCache.retrieveDocument(currentObject);
            } catch (final SAXException e) {
                throw new XmlCorruptedException(
                        StringUtility.format("Parsing of provided XML data failed. ", e.getMessage()), e);
            } catch (final Exception e) {
                throw new WebserverSystemException("Internal error. Parsing of XML failed.", e);
            }

            String path = invocationMapping.getPath();
            boolean extractObjidNeeded = false;
            if (path.startsWith("extractObjid:")) {
                path = path.substring("extractObjid:".length());
                extractObjidNeeded = true;
            }
            final String xpath = PATTERN_INDEXED.matcher(path).replaceAll("[" + (index + 1) + ']');
            final NodeList nodeList;
            try {
                nodeList = XPathAPI.selectNodeList(document, xpath);
            } catch (final TransformerException e) {
                throw new WebserverSystemException(
                        StringUtility.format("Invocation mapping error. Xpath invalid?", xpath, index,
                                invocationMapping.getId()),
                        e);
            }

            if (nodeList == null || nodeList.getLength() == 0) {
                if (index > 0) {
                    throw new IndexOutOfBoundsException();
                } else if (invocationMapping.getMappingType() == InvocationMapping.XML_ATTRIBUTE_MAPPING) {
                    throw new XmlCorruptedException(
                            StringUtility.format("Expected value not found " + "in provided XML data ", xpath));
                } else {
                    // skip undefined optional attribute by setting
                    // the value to null.
                    value = null;
                }
            } else {
                int length = 1;
                if (invocationMapping.isMultiValue()) {
                    length = nodeList.getLength();
                }
                final Collection<String> values = new HashSet<String>();
                for (int i = 0; i < length; i++) {
                    final Node node = nodeList.item(i);
                    String tmpValue = null;
                    if (node.getFirstChild() != null) {
                        tmpValue = node.getFirstChild().getNodeValue();
                    } else {
                        tmpValue = "";
                    }
                    if (tmpValue != null) {
                        if (extractObjidNeeded) {
                            tmpValue = XmlUtility.getIdFromURI(tmpValue);
                        }
                        values.add(tmpValue.trim());
                    }
                }
                if (values.isEmpty()) {
                    value = null;
                } else {
                    final StringBuilder valueBuf = new StringBuilder("");
                    for (final String val : values) {
                        if (!val.isEmpty()) {
                            if (valueBuf.length() > 0) {
                                valueBuf.append(' ');
                            }
                            valueBuf.append(val);
                        }
                    }
                    value = new StringAttribute(valueBuf.toString());
                }
            }
        } else {
            throw new WebserverSystemException(StringUtility.format("Unsupported invocation mapping type",
                    invocationMapping.getMappingType(), invocationMapping.getId()));
        }
    }
    return value;
}

From source file:eu.stratosphere.pact.runtime.task.AbstractPactTask.java

@SuppressWarnings("unchecked")
protected <X> MutableObjectIterator<X> getInput(int index) {
    if (index < 0 || index > getNumberOfInputs()) {
        throw new IndexOutOfBoundsException();
    }// ww  w.ja  v  a2 s.  co  m
    return (MutableObjectIterator<X>) this.inputs[index];
}

From source file:CopyOnWriteArrayList.java

/**
 * Removes from this list all of the elements whose index is between
 * <tt>fromIndex</tt>, inclusive, and <tt>toIndex</tt>, exclusive.
 * Shifts any succeeding elements to the left (reduces their index).
 * This call shortens the list by <tt>(toIndex - fromIndex)</tt> elements.
 * (If <tt>toIndex==fromIndex</tt>, this operation has no effect.)
 *
 * @param fromIndex index of first element to be removed
 * @param toIndex index after last element to be removed
 * @throws IndexOutOfBoundsException if fromIndex or toIndex out of
 *              range (fromIndex &lt; 0 || fromIndex &gt;= size() || toIndex
 *              &gt; size() || toIndex &lt; fromIndex)
 *//*from   w  w w  .  j a v a2 s.c o m*/
private synchronized void removeRange(int fromIndex, int toIndex) {
    Object[] elements = getArray();
    int len = elements.length;

    if (fromIndex < 0 || fromIndex >= len || toIndex > len || toIndex < fromIndex)
        throw new IndexOutOfBoundsException();
    int newlen = len - (toIndex - fromIndex);
    int numMoved = len - toIndex;
    if (numMoved == 0)
        setArray(copyOf(elements, newlen));
    else {
        Object[] newElements = new Object[newlen];
        System.arraycopy(elements, 0, newElements, 0, fromIndex);
        System.arraycopy(elements, toIndex, newElements, fromIndex, numMoved);
        setArray(newElements);
    }
}

From source file:eu.stratosphere.pact.runtime.task.AbstractPactTask.java

@SuppressWarnings("unchecked")
protected <X> TypeSerializer<X> getInputSerializer(int index) {
    if (index < 0 || index > getNumberOfInputs()) {
        throw new IndexOutOfBoundsException();
    }//from  w w w .j  ava2 s  .c om
    return (TypeSerializer<X>) this.inputSerializers[index];
}

From source file:CopyOnWriteArrayList.java

/**
 * Removes from this List all of the elements whose index is between
 * fromIndex, inclusive and toIndex, exclusive. Shifts any succeeding
 * elements to the left (reduces their index). This call shortens the List
 * by (toIndex - fromIndex) elements. (If toIndex==fromIndex, this operation
 * has no effect.)//from  w  w w  .j  a  va 2s . c  o  m
 * 
 * @param fromIndex
 *            index of first element to be removed.
 * @param toIndex
 *            index after last element to be removed.
 * @exception IndexOutOfBoundsException
 *                fromIndex or toIndex out of range (fromIndex &lt; 0 ||
 *                fromIndex &gt;= size() || toIndex &gt; size() || toIndex
 *                &lt; fromIndex).
 */
public synchronized void removeRange(int fromIndex, int toIndex) {
    int len = array_.length;

    if (fromIndex < 0 || fromIndex >= len || toIndex > len || toIndex < fromIndex)
        throw new IndexOutOfBoundsException();

    int numMoved = len - toIndex;
    int newlen = len - (toIndex - fromIndex);
    Object[] newArray = new Object[newlen];
    System.arraycopy(array_, 0, newArray, 0, fromIndex);
    System.arraycopy(array_, toIndex, newArray, fromIndex, numMoved);
    array_ = newArray;
}

From source file:eu.stratosphere.pact.runtime.task.AbstractPactTask.java

@SuppressWarnings("unchecked")
protected <X> TypeComparator<X> getInputComparator(int index) {
    if (index < 0 || index > getNumberOfInputs()) {
        throw new IndexOutOfBoundsException();
    }//ww  w. j a v  a  2  s. c  o m
    return (TypeComparator<X>) this.inputComparators[index];
}