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:Polygon2D.java

/**
 * Constructs and initializes a <code>Polygon2D</code> from the specified
 * parameters.//from   www  .ja v  a  2 s  .  c o  m
 * @param xpoints an array of <i>x</i> coordinates
 * @param ypoints an array of <i>y</i> coordinates
 * @param npoints the total number of points in the <code>Polygon2D</code>
 * @exception  NegativeArraySizeException if the value of
 *                       <code>npoints</code> is negative.
 * @exception  IndexOutOfBoundsException if <code>npoints</code> is
 *             greater than the length of <code>xpoints</code>
 *             or the length of <code>ypoints</code>.
 * @exception  NullPointerException if <code>xpoints</code> or
 *             <code>ypoints</code> is <code>null</code>.
 */
public Polygon2D(float[] xpoints, float[] ypoints, int npoints) {
    if (npoints > xpoints.length || npoints > ypoints.length) {
        throw new IndexOutOfBoundsException("npoints > xpoints.length || npoints > ypoints.length");
    }
    this.npoints = npoints;
    this.xpoints = new float[npoints];
    this.ypoints = new float[npoints];
    System.arraycopy(xpoints, 0, this.xpoints, 0, npoints);
    System.arraycopy(ypoints, 0, this.ypoints, 0, npoints);
    calculatePath();
}

From source file:edu.chalmers.dat255.audiobookplayer.model.Track.java

public void removeTagAt(int tagIndex) {
    if (!isLegalTagIndex(tagIndex)) {
        throw new IndexOutOfBoundsException(TAG + " removeTagAt" + TAG_INDEX_ILLEGAL);
    }/*from   w  ww .j  a v  a2s  .  c o m*/

    this.tags.remove(tagIndex);
}

From source file:de.huberlin.wbi.cfjava.data.Alist.java

@SuppressWarnings("unused")
public T nth(int i) {
    throw new IndexOutOfBoundsException("Index out of bounds.");
}

From source file:org.apache.mina.util.CircularQueue.java

private void checkIndex(int idx) {
        if (idx < 0 || idx >= size()) {
            throw new IndexOutOfBoundsException(String.valueOf(idx));
        }/*from   w  w w. j ava  2s.  co m*/
    }

From source file:me.cybermaxke.merchants.v16r3.SMerchant.java

@Override
public void insetOfferAt(int index, MerchantOffer offer) {
    checkNotNull(offer, "offer");

    if (index < 0 || index >= this.offers.size()) {
        throw new IndexOutOfBoundsException(
                "index (" + index + ") out of bounds min (0) and max (" + this.offers.size() + ")");
    }//  w w  w  . j  a v  a2 s. co  m

    this.offers.add(index, offer);
}

From source file:delfos.rs.contentbased.vsm.booleanvsm.BooleanFeaturesTransformation.java

protected FeatureValue getFeatureValue(long index) {
    for (Feature f : featureValuesIndexes.keySet()) {
        if (featureValuesIndexes.get(f).containsValue(index)) {
            for (Map.Entry<Object, Long> entry : featureValuesIndexes.get(f).entrySet()) {
                if (entry.getValue().equals(index)) {
                    return new FeatureValue(f, entry.getKey());
                }//from w  w  w.j  a va2 s  .  c o m
            }
        }
    }

    throw new IndexOutOfBoundsException("The index " + index + " is not defined");
}

From source file:LazyList.java

public Object remove(int index) {
    if (index >= 0 && index < m_size) {
        Object item = m_array[index];
        int start = index + 1;
        System.arraycopy(m_array, start, m_array, index, m_size - start);
        m_array[--m_size] = null;/*  w w w .  j a v a  2  s. c  o m*/
        modCount++;
        return item;
    } else {
        throw new IndexOutOfBoundsException("Index " + index + " is out of valid range 0-" + (m_size - 1));
    }
}

From source file:com.jpeterson.littles3.bo.Acp.java

/**
 * Grant a <code>permission</code> to the <code>grantee</code>.
 * /*  ww  w .  j av  a 2s  . c o m*/
 * @param grantee
 *            The grantee being granted the permission.
 * @param permission
 *            The permission to grant to the grantee. Should be one of the
 *            available ResourcePermission "actions".
 * @throws IndexOutOfBoundsException
 *             Thrown if too many grants are made.
 * @see ResourcePermission#ACTION_READ
 * @see ResourcePermission#ACTION_WRITE
 * @see ResourcePermission#ACTION_READ_ACP
 * @see ResourcePermission#ACTION_WRITE_ACP
 * @see ResourcePermission#ACTION_FULL_CONTROL
 */
public void grant(Grantee grantee, String permission) throws IndexOutOfBoundsException {
    if (grantCount >= MAX_GRANT_COUNT) {
        throw new IndexOutOfBoundsException("Maximum number of grants reached: " + MAX_GRANT_COUNT);
    }

    Permission perm;
    perm = new ResourcePermission(grantee, permission);
    permissions.add(perm);

    ++grantCount;
}

From source file:com.netxforge.oss2.xml.event.Correlation.java

/**
 * Method getCuei.// ww  w.  j av a2s  .  c om
 * 
 * @param index
 * @throws java.lang.IndexOutOfBoundsException if the index
 * given is outside the bounds of the collection
 * @return the value of the java.lang.String at the given index
 */
public java.lang.String getCuei(final int index) throws java.lang.IndexOutOfBoundsException {
    // check bounds for index
    if (index < 0 || index >= this._cueiList.size()) {
        throw new IndexOutOfBoundsException(
                "getCuei: Index value '" + index + "' not in range [0.." + (this._cueiList.size() - 1) + "]");
    }

    return (java.lang.String) _cueiList.get(index);
}

From source file:Main.java

/**
 * Returns the <code>index</code>-th value in <code>object</code>, throwing
 * <code>IndexOutOfBoundsException</code> if there is no such element or 
 * <code>IllegalArgumentException</code> if <code>object</code> is not an 
 * instance of one of the supported types.
 * <p>//from w  w  w  .  j  av a  2 s. c  o  m
 * The supported types, and associated semantics are:
 * <ul>
 * <li> Map -- the value returned is the <code>Map.Entry</code> in position 
 *      <code>index</code> in the map's <code>entrySet</code> iterator, 
 *      if there is such an entry.</li>
 * <li> List -- this method is equivalent to the list's get method.</li>
 * <li> Array -- the <code>index</code>-th array entry is returned, 
 *      if there is such an entry; otherwise an <code>IndexOutOfBoundsException</code>
 *      is thrown.</li>
 * <li> Collection -- the value returned is the <code>index</code>-th object 
 *      returned by the collection's default iterator, if there is such an element.</li>
 * <li> Iterator or Enumeration -- the value returned is the
 *      <code>index</code>-th object in the Iterator/Enumeration, if there
 *      is such an element.  The Iterator/Enumeration is advanced to 
 *      <code>index</code> (or to the end, if <code>index</code> exceeds the 
 *      number of entries) as a side effect of this method.</li>
 * </ul>
 *
 * @param object  the object to get a value from
 * @param index  the index to get
 * @return the object at the specified index
 * @throws IndexOutOfBoundsException if the index is invalid
 * @throws IllegalArgumentException if the object type is invalid
 */
public static Object get(Object object, int index) {
    if (index < 0) {
        throw new IndexOutOfBoundsException("Index cannot be negative: " + index);
    }
    if (object instanceof Map) {
        Map map = (Map) object;
        Iterator iterator = map.entrySet().iterator();
        return get(iterator, index);
    } else if (object instanceof List) {
        return ((List) object).get(index);
    } else if (object instanceof Object[]) {
        return ((Object[]) object)[index];
    } else if (object instanceof Iterator) {
        Iterator it = (Iterator) object;
        while (it.hasNext()) {
            index--;
            if (index == -1) {
                return it.next();
            } else {
                it.next();
            }
        }
        throw new IndexOutOfBoundsException("Entry does not exist: " + index);
    } else if (object instanceof Collection) {
        Iterator iterator = ((Collection) object).iterator();
        return get(iterator, index);
    } else if (object instanceof Enumeration) {
        Enumeration it = (Enumeration) object;
        while (it.hasMoreElements()) {
            index--;
            if (index == -1) {
                return it.nextElement();
            } else {
                it.nextElement();
            }
        }
        throw new IndexOutOfBoundsException("Entry does not exist: " + index);
    } else if (object == null) {
        throw new IllegalArgumentException("Unsupported object type: null");
    } else {
        try {
            return Array.get(object, index);
        } catch (IllegalArgumentException ex) {
            throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName());
        }
    }
}