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.ojcoleman.ahni.util.DoubleVector.java

private final void checkRangeIncludingEndpoint(int index) {
    if (index < 0 || index > _size) {
        throw new IndexOutOfBoundsException("Should be at least 0 and at most " + _size + ", found " + index);
    }//  w ww. ja v a  2 s  . co  m
}

From source file:com.slytechs.utils.region.FlexRegion.java

public final RegionSegment<T> getSegment(final long global, final int start) {

    int i = 0;/*from w ww  .java2s. c  o  m*/
    final Iterator<RegionSegment<T>> l = this.segments.listIterator(start);
    while (l.hasNext()) {
        final RegionSegment<T> ds = l.next();
        if (ds.checkBoundsGlobal(global)) {
            return ds;
        }

        i++;
    }

    throw new IndexOutOfBoundsException("Position out of bounds [" + global + "]");
}

From source file:ivorius.ivtoolkit.models.utils.ArrayMap.java

/**
 * Removes and returns the key/values pair at the specified index.
 *///from   w  w w.  ja  v  a  2 s .  c  o m
public void removeIndex(int index) {
    if (index >= size)
        throw new IndexOutOfBoundsException(String.valueOf(index));
    Object[] keys = this.keys;
    size--;
    if (ordered) {
        System.arraycopy(keys, index + 1, keys, index, size - index);
        System.arraycopy(values, index + 1, values, index, size - index);
    } else {
        keys[index] = keys[size];
        values[index] = values[size];
    }
    keys[size] = null;
    values[size] = null;
}

From source file:org.kew.rmf.reconciliation.ws.GeneralReconciliationServiceStepdefs.java

@Then("^I receive the following result file:$")
public void i_receive_the_following_result_file(String expectedFile) throws Throwable {
    String fileName = result.getResponse().getHeader("X-File-Download");

    result = mockMvc.perform(get("/download/" + fileName)).andExpect(status().is(200)).andReturn();

    String actualFile = result.getResponse().getContentAsString();
    log.info("File received is\n{}", actualFile);

    String[] expectedFileLines = expectedFile.split("\r?\n|\r");
    String[] actualFileLines = actualFile.split("\r?\n|\r");

    for (int i = 0; i < expectedFileLines.length; i++) {
        String expectedLine = expectedFileLines[i];
        String actualLine = actualFileLines[i];
        try {/* w w  w  .j a va2s. c o m*/
            log.debug("Expecting line {}, got {}", expectedLine, actualLine);
            assertThat(actualLine, is(expectedLine));
        } catch (IndexOutOfBoundsException e) {
            throw new IndexOutOfBoundsException(
                    String.format(" line %s not found in match output.", expectedLine));
        }
    }
    assertThat(actualFileLines.length, is(expectedFileLines.length));
}

From source file:io.horizondb.io.buffers.CompositeBuffer.java

/**
 * Adds the bytes of the specified buffer to this composite at the specified position.
 *
 * @param position the position where the bytes must be added
 * @param buffer the buffer containing the bytes to add
 * @return this <code>CompositeBuffer</code>
 * @throws IOException if an I/O problem occurs
 */// ww  w  .  j av a  2  s . c  o m
public CompositeBuffer addBytes(int position, ReadableBuffer buffer) throws IOException {

    if (position < 0 || position > this.capacity) {

        @SuppressWarnings("boxing")
        String msg = format("capacity: %d specified position: %d", this.capacity, position);
        throw new IndexOutOfBoundsException(msg);
    }

    if (position == this.capacity) {
        return addBytes(buffer);
    }

    ReadableBuffer duplicate = buffer.duplicate();

    int bufferOffset = 0;

    for (int i = 0, m = this.buffers.size(); i < m; i++) {

        if (bufferOffset == position) {
            this.buffers.add(i, duplicate);
            break;
        }

        ReadableBuffer oldBuffer = this.buffers.get(i);
        int readableBytes = oldBuffer.readableBytes();

        if (position < bufferOffset + readableBytes) {
            this.buffers.remove(i);
            int length = position - bufferOffset;
            ReadableBuffer newBuffer = oldBuffer.slice(0, length).duplicate();
            this.buffers.add(i, newBuffer);
            this.buffers.add(++i, duplicate);
            newBuffer = oldBuffer.slice(length, readableBytes - length).duplicate();
            this.buffers.add(++i, newBuffer);
            break;
        }

        bufferOffset += readableBytes;
    }

    if (this.readerIndex > position) {
        this.readerIndex += duplicate.readableBytes();
    }

    this.current = this.buffers.get(0);
    this.bufferIndex = 0;
    this.bufferOffset = 0;
    this.capacity += duplicate.readableBytes();
    return this;
}

From source file:org.hexlogic.CooptoPluginFactory.java

@Override
public List<?> findChildrenInRelation(InventoryRef parent, String relationName) {
    log.debug("running findChildrenInRelation() with parent=" + parent + " and relationName=" + relationName
            + ".");

    if (parent.isOfType(CooptoModuleBuilder.ROOT)) {
        log.debug("parent is of type " + CooptoModuleBuilder.ROOT);
        if (relationName.equals(CooptoModuleBuilder.NODERELATION)) {
            log.debug("relation is " + CooptoModuleBuilder.NODERELATION);
            return findAll(DockerNode.TYPE, null).getElements();
        } else {/*from  w w w  .  ja v  a2s.c  o  m*/
            throw new IndexOutOfBoundsException("Unknown relation name: " + relationName);
        }
    } else if (parent.isOfType(DockerNode.TYPE)) {
        log.debug("parent is of type " + DockerNode.TYPE + ". Searching...");

        try {
            // try to find in cache - must be in synchronized block
            synchronized (nodes) {
                Iterator<DockerNode> itr = nodes.iterator();
                while (itr.hasNext()) {
                    DockerNode node = itr.next();
                    if (node.getId().equals(parent.getId())) {
                        log.debug("Found parent " + DockerNode.TYPE + " with id " + parent.getId());
                        if (relationName.equals(DockerNode.IMAGERELATION)) {
                            log.debug("Relation is " + DockerNode.IMAGERELATION);
                            if (node != null) {
                                return node.getImages();
                            }
                        } else if (relationName.equals(DockerNode.CONTAINERRELATION)) {
                            log.debug("Relation is " + DockerNode.CONTAINERRELATION);
                            if (node != null) {
                                return node.getContainers();
                            }
                        } else {
                            throw new IndexOutOfBoundsException("Unknown relation name: " + relationName);
                        }
                    }
                }
            }
        } catch (Exception e) {
            final StringWriter sw = new StringWriter();
            final PrintWriter pw = new PrintWriter(sw, true);
            e.printStackTrace(pw);
            log.error("Error: " + sw.getBuffer().toString());
        }
    }
    log.warn("Warning: no such parent object or relation was found");
    return Collections.emptyList();
}

From source file:com.microsoft.tfs.core.util.TSWAHyperlinkBuilder.java

/**
 * Gets a changeset URL.//from w ww  . ja va2  s .c  o  m
 *
 * @param changesetId
 *        A changeset id.
 * @param accessMappingMoniker
 *        A moniker for the desired access mapping.
 * @return a changeset URL
 */
public URI getChangesetURL(final int changesetId, final String accessMappingMoniker) {
    if (changesetId < 1) {
        throw new IndexOutOfBoundsException(
                MessageFormat.format("The value {0} is outside of the allowed range.", //$NON-NLS-1$
                        Integer.toString(changesetId)));
    }

    return buildURL(ServiceInterfaceNames.TSWA_VIEW_CHANGESET_DETAILS, accessMappingMoniker, "changesetId", //$NON-NLS-1$
            Integer.toString(changesetId), null);
}

From source file:com.clustercontrol.plugin.impl.SchedulerPlugin.java

/**
 * <pre>/* w  w w  .ja  v a2 s  .  c o m*/
 * ??????????<br/>
 * ???????cron?????????<br/>
 * </pre>
 *
 * @param type ???
 * @param name ????
 * @param group ???
 * @param startTime 
 * @param intervalSec [sec]
 * @param rstOnRestart JVM?????true(Misfire?????????????????
 * @param className ?????
 * @param methodName ?????
 * @param argsType ??
 * @param args ??
 * @throws HinemosUnknown
 */
public static void scheduleSimpleJob(SchedulerType type, String name, String group, long startTimeMillis,
        int intervalSec, boolean rstOnRestart, String className, String methodName,
        Class<? extends Serializable>[] argsType, Serializable[] args) throws HinemosUnknown {

    log.debug("scheduleSimpleJob() name=" + name + ", group=" + group + ", startTime=" + startTimeMillis
            + ", rstOnRestart=" + rstOnRestart + ", className=" + className + ", methodName=" + methodName);

    // ??
    JobDetail job = JobBuilder.newJob(ReflectionInvokerJob.class).withIdentity(name, group).storeDurably(true) // ??????
            //            .requestRecovery(false)   // ??????????(JVM?????????)
            .usingJobData(ReflectionInvokerJob.KEY_CLASS_NAME, className) // ???????
            .usingJobData(ReflectionInvokerJob.KEY_METHOD_NAME, methodName) // ?????
            .usingJobData(ReflectionInvokerJob.KEY_RESET_ON_RESTART, rstOnRestart) // ??trigger()???????
            .build();

    // [WARNING] job.getJobDataMap()??????"trigger".getJobDataMap()??????????
    // Quartz (JBoss EAP 5.1 Bundle) Bug??java.lang.StackOverflowError?????

    // ???0-length????)
    if (args == null) {
        throw new NullPointerException("args must not be null. if not args, set 0-length list.");
    }
    if (argsType == null) {
        throw new NullPointerException("argsType must not be null. if not args, set 0-length list.");
    }
    if (args.length != argsType.length) {
        throw new IndexOutOfBoundsException("list's length is not same between args and argsType.");
    }
    if (args.length > 15) {
        throw new IndexOutOfBoundsException("list's length is out of bounds.");
    }
    job.getJobDataMap().put(ReflectionInvokerJob.KEY_ARGS_TYPE, argsType);
    job.getJobDataMap().put(ReflectionInvokerJob.KEY_ARGS, args);

    // ??trigger?
    SimpleTriggerBuilder triggerBuilder = SimpleTriggerBuilder.newTrigger().withIdentity(name, group);
    if (rstOnRestart) {
        log.debug("scheduleSimpleJob() name=" + name + ", misfireHandlingInstruction=DoNothing");
        triggerBuilder.setPeriod(intervalSec * 1000).withMisfireHandlingInstructionDoNothing();
    } else {
        log.debug("scheduleSimpleJob() name=" + name + ", misfireHandlingInstruction=IgnoreMisfires");
        triggerBuilder.setPeriod(intervalSec * 1000).withMisfireHandlingInstructionIgnoreMisfires();
    }

    Trigger trigger = triggerBuilder.startAt(startTimeMillis)
            //            .withSchedule(scheduleBuilder)
            .build();

    if (type == SchedulerPlugin.SchedulerType.DBMS) {
        // DBMS??????DB??????
        // ????/?1????????
        try {
            ModifyDbmsScheduler dbms = new ModifyDbmsScheduler();
            if (_scheduler.get(type).checkExists(new JobKey(name, group))) {
                // ?????DB????
                log.trace("scheduleSimpleJob() : modifyDbmsScheduler() call.");
                dbms.modifyDbmsScheduler(job, trigger);

                synchronized (_schedulerLock) {
                    // rescheduleJob()??Trigger??????????RAM??????
                    _scheduler.get(type).deleteJob(new JobKey(name, group));
                    log.debug("scheduleJob() name=" + name + ", group=" + group);
                    _scheduler.get(type).scheduleJob(job, trigger);
                }
            } else {
                // ????DB??
                log.trace("scheduleSimpleJob() : addDbmsScheduler() call.");
                dbms.addDbmsScheduler(job, trigger);

                synchronized (_schedulerLock) {
                    log.debug("scheduleJob() name=" + name + ", group=" + group);
                    _scheduler.get(type).scheduleJob(job, trigger);
                }
            }
        } catch (Exception e) {
            log.error("scheduleSimpleJob() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
            throw new HinemosUnknown("failed scheduling DBMS job. (name = " + name + ", group = " + group + ")",
                    e);
        }
    } else {
        // RAM?????????
        deleteJob(type, name, group);
        // ?
        try {
            synchronized (_schedulerLock) {
                log.debug("scheduleJob() name=" + name + ", group=" + group);
                _scheduler.get(type).scheduleJob(job, trigger);
            }
        } catch (SchedulerException e) {
            throw new HinemosUnknown("failed scheduling job. (name = " + name + ", group = " + group + ")", e);
        }
    }
}

From source file:aldenjava.opticalmapping.data.data.DataNode.java

/**
 * Returns the length of the molecule within start and stop segment, excluding the flanking signals
 * //w w  w. ja va 2 s  .  c o m
 * @param start
 *            The start segment, inclusive
 * @param end
 *            The stop segment, inclusive
 * @return the specified length
 */
public long length(int start, int end) {
    if (start < 0 || start > refp.length || end < 0 || end > refp.length)
        throw new IndexOutOfBoundsException("Index range is out of bound");
    return ((end == refp.length ? (size + 1) : refp[end]) - (start == 0 ? 0 : refp[start - 1]) - 1);
}

From source file:com.example.jonas.materialmockups.activities.ExhibitDetailsActivity.java

/** Displays the previous exhibit page (for currentPageIndex > 0) */
public void displayPreviousExhibitPage() {
    currentPageIndex--;//from  w  w  w . j av  a2s .  com
    if (currentPageIndex < 0)
        throw new IndexOutOfBoundsException("currentPageIndex < 0");

    displayCurrentExhibitPage();
}