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

public void add(int index, Object element) {
    if (index >= 0 && index <= m_size) {
        makeSpace(1);// ww  w. ja  v a2s .  co m
        if (index < m_size) {
            System.arraycopy(m_array, index, m_array, index + 1, m_size - index);
        }
        m_array[index] = element;
        m_size++;
        modCount++;
    } else {
        throw new IndexOutOfBoundsException("Index " + index + " is out of valid range 0-" + m_size);
    }
}

From source file:com.nofuturecorp.www.connector.DataSet.java

/**
 * Return row of rowIndex//from w  w  w  .  ja v a2  s.  co  m
 * @param rowIndex
 * @return ColumnSet with row data or null
 */
public ColumnSet getRow(int rowIndex) {
    try {
        if (rowIndex < 0) {
            throw new IndexOutOfBoundsException("rowIndex cannot be negative");
        }
        if (dataSet.size() - 1 > rowIndex) {
            throw new IndexOutOfBoundsException("rowIndex exceed last row index");
        }
        if (dataSet.size() == 0) {
            return null;
        }
        return dataSet.get(rowIndex);
    } catch (Exception e) {
        return null;
    }
}

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

@Transformer
public byte[] encrypt(byte[] data, @Header(CONNECTION_ID) String connectionId,
        // TODO: 08.12.15 spring integration bug with ignoring defaultValue in header
        @Header(value = STATIC_KEY_HEADER, required = false) String static_key) throws IOException {
    if (data.length % BLOWFISH_BLOCK_SIZE != 0)
        throw new IndexOutOfBoundsException("data.length must be multiply of " + BLOWFISH_BLOCK_SIZE);

    BlowfishEngine blowfishEngine = new BlowfishEngine();
    if (static_key != null && static_key.equals("true")) {
        blowfishEngine.init(STATIC_BLOWFISH_KEY);
    } else {//w  ww .j a  v a2s . co  m
        AuthSession gameSession = authSessionService.getSessionBy(connectionId);

        // perform null check
        Objects.requireNonNull(gameSession, "gameSession is null for " + connectionId);

        blowfishEngine.init(gameSession.getBlowfishKey());
    }
    if (log.isTraceEnabled() && data.length > 0) {
        final StringBuilder leftStr = new StringBuilder("[");
        for (byte b : data) {
            leftStr.append(" ");
            leftStr.append(String.format("%02X", b));
        }
        leftStr.append(" ]");

        log.trace("Raw bytes before encrypt: " + leftStr);
    }

    for (int i = 0; i < data.length; i += BLOWFISH_BLOCK_SIZE) {
        blowfishEngine.encryptBlock(data, i, data, i);
    }

    return data;
}

From source file:Main.java

/**
 * <p>Returns padding using the specified delimiter repeated
 * to a given length.</p>/*w ww  .j a v a  2  s.  c  o m*/
 *
 * <pre>
 * StringUtils.padding(0, 'e')  = ""
 * StringUtils.padding(3, 'e')  = "eee"
 * StringUtils.padding(-2, 'e') = IndexOutOfBoundsException
 * </pre>
 *
 * <p>Note: this method doesn't not support padding with
 * <a href="http://www.unicode.org/glossary/#supplementary_character">Unicode Supplementary Characters</a>
 * as they require a pair of <code>char</code>s to be represented.
 * If you are needing to support full I18N of your applications
 * consider using {@link #repeat(String, int)} instead. 
 * </p>
 *
 * @param repeat  number of times to repeat delim
 * @param padChar  character to repeat
 * @return String with repeated character
 * @throws IndexOutOfBoundsException if <code>repeat &lt; 0</code>
 * @see #repeat(String, int)
 */
private static String padding(int repeat, char padChar) throws IndexOutOfBoundsException {
    if (repeat < 0) {
        throw new IndexOutOfBoundsException("Cannot pad a negative amount: " + repeat);
    }
    final char[] buf = new char[repeat];
    for (int i = 0; i < buf.length; i++) {
        buf[i] = padChar;
    }
    return new String(buf);
}

From source file:bulat.diet.helper_couch.common.data.ExampleExpandableDataProvider.java

@Override
public ChildData getChildItem(int groupPosition, int childPosition) {
    if (groupPosition < 0 || groupPosition >= getGroupCount()) {
        throw new IndexOutOfBoundsException("groupPosition = " + groupPosition);
    }//from w w  w . j av  a2  s  .  c o  m

    final List<DishItemData> children = mData.get(groupPosition).second;

    if (childPosition < 0 || childPosition >= children.size()) {
        throw new IndexOutOfBoundsException("childPosition = " + childPosition);
    }

    return children.get(childPosition);
}

From source file:com.sirma.itt.emf.time.ISO8601DateFormat.java

/**
 * Parse date from ISO formatted string.
 * //from w w  w  .  j  a va  2s. com
 * @param isoDate
 *            ISO string to parse
 * @return the date
 */
public static Date parse(String isoDate) {
    if (StringUtils.isBlank(isoDate)) {
        return null;
    }
    Date parsed = null;

    try {
        int offset = 0;

        // extract year
        int year = Integer.parseInt(isoDate.substring(offset, offset += 4));
        if (isoDate.charAt(offset) != '-') {
            throw new IndexOutOfBoundsException("Expected - character but found " + isoDate.charAt(offset));
        }

        // extract month
        int month = Integer.parseInt(isoDate.substring(offset += 1, offset += 2));
        if (isoDate.charAt(offset) != '-') {
            throw new IndexOutOfBoundsException("Expected - character but found " + isoDate.charAt(offset));
        }

        // extract day
        int day = Integer.parseInt(isoDate.substring(offset += 1, offset += 2));
        if (isoDate.charAt(offset) != 'T') {
            throw new IndexOutOfBoundsException("Expected T character but found " + isoDate.charAt(offset));
        }

        // extract hours, minutes, seconds and milliseconds
        int hour = Integer.parseInt(isoDate.substring(offset += 1, offset += 2));
        if (isoDate.charAt(offset) != ':') {
            throw new IndexOutOfBoundsException("Expected : character but found " + isoDate.charAt(offset));
        }
        int minutes = Integer.parseInt(isoDate.substring(offset += 1, offset += 2));
        if (isoDate.charAt(offset) != ':') {
            throw new IndexOutOfBoundsException("Expected : character but found " + isoDate.charAt(offset));
        }
        int seconds = Integer.parseInt(isoDate.substring(offset += 1, offset += 2));
        int milliseconds = 0;
        if (isoDate.charAt(offset) == '.') {
            // ALF-3803 bug fix, milliseconds are optional
            milliseconds = Integer.parseInt(isoDate.substring(offset += 1, offset += 3));
        }

        // extract timezone
        String timezoneId;
        char timezoneIndicator = isoDate.charAt(offset);
        if ((timezoneIndicator == '+') || (timezoneIndicator == '-')) {
            timezoneId = "GMT" + isoDate.substring(offset);
        } else if (timezoneIndicator == 'Z') {
            timezoneId = "GMT";
        } else {
            throw new IndexOutOfBoundsException("Invalid time zone indicator " + timezoneIndicator);
        }

        // Get the timezone
        Map<String, TimeZone> timezoneMap = timezones.get();
        if (timezoneMap == null) {
            timezoneMap = new HashMap<>(3);
            timezones.set(timezoneMap);
        }
        TimeZone timezone = timezoneMap.get(timezoneId);
        if (timezone == null) {
            timezone = TimeZone.getTimeZone(timezoneId);
            timezoneMap.put(timezoneId, timezone);
        }
        if (!timezone.getID().equals(timezoneId)) {
            throw new IndexOutOfBoundsException();
        }

        // initialize Calendar object#
        // Note: always de-serialise from Gregorian Calendar
        Calendar calendar = new GregorianCalendar(timezone);
        calendar.setLenient(false);
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, month - 1);
        calendar.set(Calendar.DAY_OF_MONTH, day);
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, minutes);
        calendar.set(Calendar.SECOND, seconds);
        calendar.set(Calendar.MILLISECOND, milliseconds);

        // extract the date
        parsed = calendar.getTime();
    } catch (IndexOutOfBoundsException e) {
        throw new EmfRuntimeException("Failed to parse date " + isoDate, e);
    } catch (NumberFormatException e) {
        throw new EmfRuntimeException("Failed to parse date " + isoDate, e);
    } catch (IllegalArgumentException e) {
        throw new EmfRuntimeException("Failed to parse date " + isoDate, e);
    }

    return parsed;
}

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

@Override
public void setOfferAt(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() + ")");
    }//from ww  w.  j av  a2s.  com

    SMerchantOffer old = (SMerchantOffer) this.offers.set(index, offer);
    old.remove(this);

    // Send the new offer list
    this.sendUpdate();
}

From source file:es.uvigo.ei.sing.adops.datatypes.BatchProjectOutput.java

public Project getProject(int projectIndex) throws IllegalArgumentException, IOException {
    if (projectIndex < 0 || projectIndex > this.numProjects())
        throw new IndexOutOfBoundsException("Illegal project index: " + projectIndex);

    synchronized (this.projects) {
        final File fastaFile = this.project.getFastaFiles()[projectIndex];

        if (!this.projects.containsKey(fastaFile)) {
            final File projectDir = this.project.getProjectDirectories()[projectIndex];

            try {
                final Project project = new Project(this.project.getConfiguration(), projectDir, fastaFile,
                        true);//from w  w  w .j a  v a  2s  . c  o  m
                this.projects.put(fastaFile, project);
                project.addObserver(this);
            } catch (Exception e) {
                final Project project = new Project(this.project.getConfiguration(), projectDir, fastaFile,
                        true, false);
                this.projects.put(fastaFile, project);
                this.projectErrors.put(project, e);
            }

            this.store();
        }

        return this.projects.get(fastaFile);
    }
}

From source file:io.lightlink.dao.LightLinkDAO.java

public Map<String, Object> queryForSingleRow(Object params) {
    try {//from  w ww .j av  a 2  s .c om
        Map<String, Object> data = doExecute(params);

        Object resultSet = data.get("resultSet");
        if (resultSet != null) {
            return ((List<Map<String, Object>>) data.get("resultSet")).get(0);
        } else
            throw new IndexOutOfBoundsException("No resultSet returned");

    } catch (Exception e) {
        LOG.error(e.toString(), e);
        throw new RuntimeException(e.toString(), e);
    }
}

From source file:cc.kune.core.server.manager.file.ImageUtilsDefault.java

/**
 * Creates the thumb./*from  w w w  .  j  a v  a  2s. c  o  m*/
 * 
 * @param fileOrig
 *          the file orig
 * @param fileDest
 *          the file dest
 * @param thumbDimension
 *          the thumb dimension
 * @param cropDimension
 *          the crop dimension
 * @throws MagickException
 *           the magick exception
 * @throws FileNotFoundException
 *           the file not found exception
 */
public static void createThumb(final String fileOrig, final String fileDest, final int thumbDimension,
        final int cropDimension) throws MagickException, FileNotFoundException {
    checkExist(fileOrig);
    if (thumbDimension < cropDimension) {
        throw new IndexOutOfBoundsException("Thumb dimension must be bigger than crop dimension");
    }
    final MagickImage imageOrig = readImage(fileOrig);
    final Dimension origDimension = imageOrig.getDimension();
    final int origHeight = origDimension.height;
    final int origWidth = origDimension.width;
    final Dimension proportionalDim = calculatePropDim(origWidth, origHeight, thumbDimension, true);
    final MagickImage scaled = scaleImage(imageOrig, proportionalDim.width, proportionalDim.height);
    final int x = calculateCenteredCoordinate(proportionalDim.width, cropDimension);
    final int y = calculateCenteredCoordinate(proportionalDim.height, cropDimension);
    cropImage(scaled, fileDest, x, y, cropDimension, cropDimension);
}