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.chingo247.structureapi.blockstore.BlockStore.java

@Override
public IBlockStoreRegion getRegion(int x, int z) {
    if (x < 0) {
        throw new IndexOutOfBoundsException("x < 0, x was " + x);
    }//from  ww  w .j av  a2 s.co  m
    if (z < 0) {
        throw new IndexOutOfBoundsException("z < 0, z was " + z);
    }
    if (width != -1 && x > width) {
        throw new IndexOutOfBoundsException("x > " + width + " (=width), x was " + x);
    }
    if (length != -1 && z > length) {
        throw new IndexOutOfBoundsException("z > " + length + " (=length), z was " + z);
    }

    String key = getRegionKey(x, z);
    IBlockStoreRegion region = loadedRegions.get(key);

    if (region == null) {
        File regionFile = new File(directory, key + ".blockstore");
        if (regionFile.exists()) {
            try {
                region = readRegion(regionFile);
            } catch (IOException ex) {
                throw new RuntimeException("Failed to read region file '" + regionFile.getAbsolutePath() + "'",
                        ex);
            }
        } else {
            int chunkX = x >> 4;
            int chunkZ = z >> 4;

            int regionX = (chunkX >> 5) * REGION_SIZE;
            int regionZ = (chunkZ >> 5) * REGION_SIZE;

            int regionWidth = (regionX + REGION_SIZE) > width ? width - regionX : REGION_SIZE;
            int regionHeight = height;
            int regionLength = (regionZ + REGION_SIZE) > length ? length - regionZ : REGION_SIZE;
            region = newRegion(regionFile, new HashMap<String, Tag>(), regionWidth, regionHeight, regionLength);

        }

        if (region == null) {
            throw new RuntimeException("Failed to create region, region was null");
        }

        loadedRegions.put(key, region);
    }

    return region;
}

From source file:com.silverwrist.util.Base64EncodeInputStream.java

public synchronized int read(byte[] b, int off, int len) throws IOException {
    if (b == null)
        throw new NullPointerException("null array");
    if (off < 0)
        throw new IndexOutOfBoundsException("negative offset");
    if (len < 0)
        throw new IndexOutOfBoundsException("negative length");
    if ((off + len) > b.length)
        throw new IndexOutOfBoundsException("off right end of array");
    if (len == 0)
        return 0;
    int rc = 0;//from ww w.j a  v  a 2 s  . c  om
    while (len > 0) { // force a backfill before copying
        if (backfill())
            break; // end of the underlying file
        int ncpy = Math.min(len, m_coded_data.length - m_ptr);
        System.arraycopy(m_coded_data, m_ptr, b, off, ncpy);
        m_ptr += ncpy;
        off += ncpy;
        rc += ncpy;
        len -= ncpy;

    } // end while

    if (rc == 0)
        rc = -1; // EOF
    return rc;

}

From source file:com.linkedin.pinot.core.indexsegment.utils.GenericRowColumnDataFileReader.java

/**
 * Computes the offset where the actual column data can be read
 * @param row/*from w  w  w .j  av a2  s  . c  o m*/
 * @param col
 * @return
 */
private int computeOffset(int row, int col) {
    if (row >= rows || col >= cols) {
        String message = String.format("Input (%d,%d) is not with in expected range (%d,%d)", row, col, rows,
                cols);
        throw new IndexOutOfBoundsException(message);
    }
    int offset = row * rowSize + colOffSets[col];
    return offset;
}

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

public ByteBuf encWithXor(ByteBuf buf) {
    if (buf.readableBytes() % 4 != 0) {
        throw new IndexOutOfBoundsException("ByteBuf size must be multiply of 4");
    }// w  ww .  j  a va  2 s.  co  m
    int edx;
    int ecx = 0; // Initial xor key

    buf.writeLong(random.nextLong()); // 8 bytes padding

    for (int pos = 4; pos < buf.readableBytes(); pos += 4) {
        edx = buf.getInt(pos);

        ecx += edx;
        edx ^= ecx;

        buf.setInt(pos, edx);
    }
    buf.writeInt(ecx);

    buf.writeInt(random.nextInt()); // 4 bytes for blowfish block

    return buf;
}

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

/**
 * Method getUuid./*www .ja  v  a  2s. com*/
 * 
 * @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 getUuid(final int index) throws java.lang.IndexOutOfBoundsException {
    // check bounds for index
    if (index < 0 || index >= this._uuidList.size()) {
        throw new IndexOutOfBoundsException(
                "getUuid: Index value '" + index + "' not in range [0.." + (this._uuidList.size() - 1) + "]");
    }

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

From source file:net.librec.recommender.AbstractRecommender.java

/**
 * setup/* w  ww. j a  v a2  s  .c om*/
 *
 * @throws LibrecException if error occurs during setup
 */
protected void setup() throws LibrecException {
    conf = context.getConf();
    isRanking = conf.getBoolean("rec.recommender.isranking");
    if (isRanking) {
        topN = conf.getInt("rec.recommender.ranking.topn", 10);
        if (this.topN <= 0) {
            throw new IndexOutOfBoundsException("rec.recommender.ranking.topn should be more than 0!");
        }
    }
    earlyStop = conf.getBoolean("rec.recommender.earlystop", false);
    verbose = conf.getBoolean("rec.recommender.verbose", true);

    trainMatrix = (SparseMatrix) getDataModel().getTrainDataSet();
    testMatrix = (SparseMatrix) getDataModel().getTestDataSet();
    validMatrix = (SparseMatrix) getDataModel().getValidDataSet();
    userMappingData = getDataModel().getUserMappingData();
    itemMappingData = getDataModel().getItemMappingData();

    numUsers = trainMatrix.numRows();
    numItems = trainMatrix.numColumns();
    numRates = trainMatrix.size();
    ratingScale = new ArrayList<>(trainMatrix.getValueSet());
    Collections.sort(ratingScale);
    maxRate = Collections.max(trainMatrix.getValueSet());
    minRate = Collections.min(trainMatrix.getValueSet());
    globalMean = trainMatrix.mean();

    int[] numDroppedItemsArray = new int[numUsers]; // for AUCEvaluator
    int maxNumTestItemsByUser = 0; //for idcg
    for (int userIdx = 0; userIdx < numUsers; ++userIdx) {
        numDroppedItemsArray[userIdx] = numItems - trainMatrix.rowSize(userIdx);
        int numTestItemsByUser = testMatrix.rowSize(userIdx);
        maxNumTestItemsByUser = maxNumTestItemsByUser < numTestItemsByUser ? numTestItemsByUser
                : maxNumTestItemsByUser;
    }
    conf.setInts("rec.eval.auc.dropped.num", numDroppedItemsArray);
    conf.setInt("rec.eval.item.test.maxnum", maxNumTestItemsByUser);
}

From source file:Polygon2D.java

/**
 * Constructs and initializes a <code>Polygon2D</code> from the specified
 * Polygon./*from  w  w  w  .  jav a 2 s. co  m*/
 * @param pol the Polygon
 * @exception  NullPointerException pol is <code>null</code>.
 */
public Polygon2D(Polygon pol) {
    if (pol == null) {
        throw new IndexOutOfBoundsException("null Polygon");
    }
    this.npoints = pol.npoints;
    this.xpoints = new float[pol.npoints];
    this.ypoints = new float[pol.npoints];
    for (int i = 0; i < pol.npoints; i++) {
        xpoints[i] = pol.xpoints[i];
        ypoints[i] = pol.ypoints[i];
    }
    calculatePath();
}

From source file:Main.java

/**
 * Check if the expected character exist at the given offset of the
 *
 * @param value    the string to check at the specified offset
 * @param offset   the offset to look for the expected character
 * @param expected the expected character
 * @throws IndexOutOfBoundsException if the expected character is not found
 *//*from   w ww.  ja  v a2 s.c o  m*/
private static void checkOffset(String value, int offset, char expected) throws IndexOutOfBoundsException {
    char found = value.charAt(offset);
    if (found != expected) {
        throw new IndexOutOfBoundsException("Expected '" + expected + "' character but found '" + found + "'");
    }
}

From source file:LazyList.java

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

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

/**
 * Method getParm./* ww w  .j a  va2  s . co m*/
 * 
 * @param index
 * @throws java.lang.IndexOutOfBoundsException if the index
 * given is outside the bounds of the collection
 * @return the value of the com.netxforge.oss2.core.xml.event.Parm
 * at the given index
 */
public com.netxforge.oss2.xml.event.Parm getParm(final int index) throws java.lang.IndexOutOfBoundsException {
    // check bounds for index
    if (index < 0 || index >= this._parmList.size()) {
        throw new IndexOutOfBoundsException(
                "getParm: Index value '" + index + "' not in range [0.." + (this._parmList.size() - 1) + "]");
    }

    return (com.netxforge.oss2.xml.event.Parm) _parmList.get(index);
}