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:com.meidusa.amoeba.net.poolable.copy.CursorableLinkedList.java

/**
 * Inserts the specified element at the specified position in this list.
 * Shifts the element currently at that position (if any) and any subsequent
 *  elements to the right (adds one to their indices).
 *
 * @param index index at which the specified element is to be inserted.
 * @param element element to be inserted.
 *
 * @throws ClassCastException if the class of the specified element
 *         prevents it from being added to this list.
 * @throws IllegalArgumentException if some aspect of the specified
 *           element prevents it from being added to this list.
 * @throws IndexOutOfBoundsException if the index is out of range
 *           (index < 0 || index > size()).
 *///  ww w .ja  va2s  .  c  o m
public void add(int index, Object element) {
    if (index == _size) {
        add(element);
    } else {
        if (index < 0 || index > _size) {
            throw new IndexOutOfBoundsException(
                    String.valueOf(index) + " < 0 or " + String.valueOf(index) + " > " + _size);
        }
        Listable succ = (isEmpty() ? null : getListableAt(index));
        Listable pred = (null == succ ? null : succ.prev());
        insertListable(pred, succ, element);
    }
}

From source file:org.jfree.data.category.CategoryToPieDataset.java

/**
 * Returns a value from the dataset.//from  w  ww . ja  va  2s .c  o  m
 *
 * @param item  the item index (zero-based).
 *
 * @return The value (possibly <code>null</code>).
 *
 * @throws IndexOutOfBoundsException if <code>item</code> is not in the
 *     range <code>0</code> to <code>getItemCount() - 1</code>.
 */
@Override
public Number getValue(int item) {
    Number result = null;
    if (item < 0 || item >= getItemCount()) {
        // this will include the case where the underlying dataset is null
        throw new IndexOutOfBoundsException("The 'item' index is out of bounds.");
    }
    if (this.extract == TableOrder.BY_ROW) {
        result = this.source.getValue(this.index, item);
    } else if (this.extract == TableOrder.BY_COLUMN) {
        result = this.source.getValue(item, this.index);
    }
    return result;
}

From source file:org.apache.taverna.scufl2.api.common.Scufl2Tools.java

/**
 * Returns the {@link Configuration} for a {@link Configurable} in the given
 * {@link Profile}.//from  w ww .  j av  a 2 s.  c o  m
 * 
 * @param configurable
 *            the <code>Configurable</code> to find a
 *            <code>Configuration</code> for
 * @param profile
 *            the <code>Profile</code> to look for the
 *            <code>Configuration</code> in
 * @return the <code>Configuration</code> for a <code>Configurable</code> in
 *         the given <code>Profile</code>
 */
public Configuration configurationFor(Configurable configurable, Profile profile) {
    List<Configuration> configurations = configurationsFor(configurable, profile);
    if (configurations.isEmpty())
        throw new IndexOutOfBoundsException("Could not find configuration for " + configurable);
    if (configurations.size() > 1)
        throw new IllegalStateException("More than one configuration for " + configurable);
    return configurations.get(0);
}

From source file:LazyList.java

public Object set(int index, Object element) {
    if (index >= 0 && index < m_size) {
        Object item = m_array[index];
        m_array[index] = element;//w ww  . ja  v a 2  s.c  o  m
        return item;
    } else {
        throw new IndexOutOfBoundsException("Index " + index + " is out of valid range 0-" + (m_size - 1));
    }
}

From source file:net.sf.nmedit.nomad.core.menulayout.MLEntry.java

public MLEntry getEntryAt(int index) {
    if (entryList == null)
        throw new IndexOutOfBoundsException("invalid index: " + index);
    return entryList.get(index);
}

From source file:ru.jts_dev.authserver.util.Encoder.java

@Transformer
public byte[] decrypt(byte[] data, @Header(CONNECTION_ID) String connectionId) throws IOException {
    if (data.length % BLOWFISH_BLOCK_SIZE != 0)
        throw new IndexOutOfBoundsException("data.length must be multiply of " + BLOWFISH_BLOCK_SIZE);

    AuthSession gameSession = authSessionService.getSessionBy(connectionId);

    BlowfishEngine blowfishEngine = new BlowfishEngine();
    blowfishEngine.init(gameSession.getBlowfishKey());

    for (int i = 0; i < data.length; i += BLOWFISH_BLOCK_SIZE) {
        blowfishEngine.decryptBlock(data, i, data, i);
    }/*ww w. j  a v a 2  s  .  co  m*/

    return data;
}

From source file:IntArrayList.java

/**
 * Check if the given index is in range.
 * If not, throw an appropriate runtime exception.
 *///from w  w w .j a v a2 s .co m

private void rangeCheck(int index) {
    if (index < 0 || index >= size)
        throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
}

From source file:cross.datastructures.fragments.CachedList.java

@Override
public Array get(final int arg0) {
    final int arg = arg0;
    if ((arg < 0) || (arg < offset) || (arg > this.size - 1)) {
        throw new IndexOutOfBoundsException("Index out of bounds: " + arg0);
    }/*from  w  ww.j  a va 2  s.c o m*/
    final Integer key = arg;
    Array a = null;
    // Lookup SoftReference to array in hashmap
    final SRefA aref = this.cache.get(key);
    // Reference for key exists
    if (aref != null) {
        this.cacheHit++;
        // retrieve referenced array
        a = aref.get();
        if (a == null) {
            this.cacheGCed++;
            // SoftReference was last reference to array. Array was
            // garbage collected
            this.cache.remove(key);
            a = load(arg);
            addToCache(key, a);
        }
    } else {
        this.cacheMiss++;
        if (this.prefetchOnMiss) {
            final int upperBound = Math.min(this.size, this.cacheSize);
            log.info("Prefetching: from {} to {}", arg0, arg0 + upperBound);
            final List<Array> l = load(arg0, Math.max(arg0, Math.min(arg0 + upperBound - 1, this.size - 1)));
            for (int i = 0; i < l.size(); i++) {
                addToCache(arg0 + i, l.get(i));
            }
            a = l.get(0);
        } else {
            a = load(arg);
            addToCache(key, a);
        }
    }
    updateQueue();
    log.debug("CACHE ACCESS: HITS=" + this.cacheHit + " MISSES=" + this.cacheMiss + " GCED=" + this.cacheGCed
            + " LRUED=" + this.cacheLRU + " LRUPURGED=" + this.cacheLRUPURGELAST);
    return a;
}

From source file:LineGraphDrawable.java

/**
 * Computes the scale factor to scale the given numeric data into the target
 * height.//from w ww. ja  v a 2  s  . c o  m
 * 
 * @param data
 *          the numeric data.
 * @param height
 *          the target height of the graph.
 * @return the scale factor.
 */
public static float getDivisor(final Number[] data, final int height) {
    if (data == null) {
        throw new NullPointerException("Data array must not be null.");
    }

    if (height < 1) {
        throw new IndexOutOfBoundsException("Height must be greater or equal to 1");
    }

    float max = Float.MIN_VALUE;
    float min = Float.MAX_VALUE;

    for (int index = 0; index < data.length; index++) {
        Number i = data[index];
        if (i == null) {
            continue;
        }

        final float numValue = i.floatValue();
        if (numValue < min) {
            min = numValue;
        }
        if (numValue > max) {
            max = numValue;
        }
    }

    if (max <= min) {
        return 1.0f;
    }
    if (height == 1) {
        return 0;
    }
    return (max - min) / (height - 1);
}

From source file:Main.java

/**
 * Ensures an index is not negative.//from   w  w  w . j  a va 2 s.  c  om
 * @param index the index to check.
 * @throws IndexOutOfBoundsException if the index is negative.
 */
private static void checkIndexBounds(final int index) {
    if (index < 0) {
        throw new IndexOutOfBoundsException("Index cannot be negative: " + index);
    }
}