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.clustercontrol.plugin.impl.SchedulerPlugin.java

public static void scheduleCronJob(SchedulerType type, String name, String group, long startTime,
        String cronExpression, boolean rstOnRestart, String className, String methodName,
        Class<? extends Serializable>[] argsType, Serializable[] args) throws HinemosUnknown {

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

    // ??/*  w  w  w . j av a 2  s  .  com*/
    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?
    CronTriggerBuilder triggerBuilder = CronTriggerBuilder.newTrigger();
    if (rstOnRestart) {
        log.debug("scheduleCronJob() name=" + name + ", misfireHandlingInstruction=DoNothing");
        triggerBuilder.cronSchedule(cronExpression).withMisfireHandlingInstructionDoNothing();
    } else {
        log.debug("scheduleCronJob() name=" + name + ", misfireHandlingInstruction=IgnoreMisfires");
        triggerBuilder.cronSchedule(cronExpression).withMisfireHandlingInstructionIgnoreMisfires();
    }

    Trigger trigger = triggerBuilder.withIdentity(name, group).startAt(startTime)
            //            .withSchedule(schedulerBuilder)
            .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("scheduleCronJob() : 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("scheduleCronJob() : 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("scheduleCronJob() : " + 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:net.sf.nmedit.jsynth.clavia.nordmodular.NordModular.java

private void checkSlot(int slot) {
    if (!isValidSlot(slot))
        throw new IndexOutOfBoundsException("invalid slot index: " + slot);
}

From source file:org.opencron.common.utils.StringUtils.java

public static String replace(Object obj, int start, int end, String s1) {
    if (CommonUtils.isEmpty(obj))
        return "";
    if (start < 0 || end < 0)
        throw new IndexOutOfBoundsException("replace:startIndex and endIndex error");
    String str = obj.toString();/*  www  . j ava 2 s.  c om*/
    String str1 = str.substring(0, start - 1);
    String str2 = str.substring(start + end - 1);
    String replStr = "";
    for (int j = 0; j < end; j++) {
        replStr += s1;
    }
    return str1 + replStr + str2;
}

From source file:dk.netarkivet.common.utils.FileUtils.java

/**
 * Read an entire file, byte by byte, into a byte array, ignoring any locale
 * issues./*from ww  w  . j a  v  a  2 s  .  c  om*/
 *
 * @param file A file to be read.
 * @return A byte array with the contents of the file.
 * @throws IOFailure on IO trouble reading the file,
 *  or the file does not exist
 * @throws IndexOutOfBoundsException If the file is too large to be 
 * in an array.
 */
public static byte[] readBinaryFile(File file) throws IOFailure, IndexOutOfBoundsException {
    ArgumentNotValid.checkNotNull(file, "File file");
    if (!file.exists()) {
        String errMsg = "File '" + file.getAbsolutePath() + "' does not exist";
        log.warn(errMsg);
        throw new IOFailure(errMsg);
    }

    String errMsg;
    if (file.length() > Integer.MAX_VALUE) {
        errMsg = "File '" + file.getAbsolutePath() + "' of size " + file.length()
                + " (bytes) is too long to fit in an array";
        log.warn(errMsg);
        throw new IndexOutOfBoundsException(errMsg);
    }

    byte[] result = new byte[(int) file.length()];
    FileInputStream in = null;
    try {
        try {
            in = new FileInputStream(file);
            int bytesRead;
            for (int i = 0; i < result.length
                    && (bytesRead = in.read(result, i, result.length - i)) != -1; i += bytesRead) {
            }
        } finally {
            if (in != null) {
                in.close();
            }
        }
    } catch (IOException e) {
        errMsg = "Error reading file '" + file.getAbsolutePath() + "'";
        log.warn(errMsg);
        throw new IOFailure(errMsg, e);
    }

    return result;
}

From source file:com.iyonger.apm.web.util.Preconditions.java

/**
 * Ensures that {@code start} and {@code end} specify a valid <i>positions</i> in an array, list or string of size
 * {@code size}, and are in order. A position index may range from zero to {@code size}, inclusive.
 *
 * @param start a user-supplied index identifying a starting position in an array, list or string
 * @param end   a user-supplied index identifying a ending position in an array, list or string
 * @param size  the size of that array, list or string
 */// www  .j a  va2 s .  c  om
public static void checkPositionIndexes(int start, int end, int size) {
    // Carefully optimized for execution by hotspot (explanatory comment
    // above)
    if (start < 0 || end < start || end > size) {
        throw new IndexOutOfBoundsException(buildBadPositionIndexesMessage(start, end, size));
    }
}

From source file:com.example.ray.firstapp.bottombar.BottomBar.java

/**
 * Map a background color for a Tab, that changes the whole BottomBar
 * background color when the Tab is selected.
 *
 * @param tabPosition zero-based index for the tab.
 * @param color       a hex color for the tab, such as 0xFF00FF00.
 *//* w ww  . j  ava  2  s.  c  om*/
public void mapColorForTab(int tabPosition, int color) {
    if (mItems == null || mItems.length == 0) {
        throw new UnsupportedOperationException("You have no BottomBar Tabs set yet. "
                + "Please set them first before calling the mapColorForTab method.");
    } else if (tabPosition > mItems.length - 1 || tabPosition < 0) {
        throw new IndexOutOfBoundsException("Cant map color for Tab " + "index " + tabPosition
                + ". You have no BottomBar Tabs at that position.");
    }

    if (!mIsShiftingMode || mIsTabletMode)
        return;

    if (mColorMap == null) {
        mColorMap = new HashMap<>();
    }

    if (tabPosition == mCurrentTabPosition && mCurrentBackgroundColor != color) {
        mCurrentBackgroundColor = color;
        mBackgroundView.setBackgroundColor(color);
    }

    mColorMap.put(tabPosition, color);
}

From source file:at.ofai.gate.virtualcorpus.DirectoryCorpus.java

/**
 * Return the document for the given index in the corpus.
 * An IndexOutOfBoundsException is thrown when the index is not contained
 * in the corpus./*from w  w  w. j ava 2 s.  c  o m*/
 * The document will be read from the file only if it is not already loaded.
 * If it is already loaded a reference to that document is returned.
 * 
 * @param index
 * @return 
 */
@Override
public Document get(int index) {
    //System.out.println("DirCorp: called get(index): "+index);
    if (index < 0 || index >= documentNames.size()) {
        throw new IndexOutOfBoundsException(
                "Index " + index + " not in corpus " + this.getName() + " of size " + documentNames.size());
    }
    String docName = documentNames.get(index);
    if (isDocumentLoaded(index)) {
        Document doc = loadedDocuments.get(docName);
        //System.out.println("Returning loaded document "+doc);
        return doc;
    }
    //System.out.println("Document not loaded, reading");
    Document doc = readDocument(docName);
    loadedDocuments.put(docName, doc);
    isLoadeds.set(index, true);
    adoptDocument(doc);
    return doc;
}

From source file:com.eutectoid.dosomething.picker.GraphObjectAdapter.java

SectionAndItem getSectionAndItem(int position) {
    if (sectionKeys.size() == 0) {
        return null;
    }//from w ww.jav a 2  s  .co  m
    String sectionKey = null;
    JSONObject graphObject = null;

    if (!displaySections) {
        sectionKey = sectionKeys.get(0);
        List<JSONObject> section = graphObjectsBySection.get(sectionKey);
        if (position >= 0 && position < section.size()) {
            graphObject = graphObjectsBySection.get(sectionKey).get(position);
        } else {
            // We are off the end; we must be adding an activity circle to indicate more data is coming.
            assert dataNeededListener != null && cursor.areMoreObjectsAvailable();
            // We return null for both to indicate this.
            return new SectionAndItem(null, null);
        }
    } else {
        // Count through the sections; the "0" position in each section is the header. We decrement
        // position each time we skip forward a certain number of elements, including the header.
        for (String key : sectionKeys) {
            // Decrement if we skip over the header
            if (position-- == 0) {
                sectionKey = key;
                break;
            }

            List<JSONObject> section = graphObjectsBySection.get(key);
            if (position < section.size()) {
                // The position is somewhere in this section. Get the corresponding graph object.
                sectionKey = key;
                graphObject = section.get(position);
                break;
            }
            // Decrement by as many items as we skipped over
            position -= section.size();
        }
    }
    if (sectionKey != null) {
        // Note: graphObject will be null if this represents a section header.
        return new SectionAndItem(sectionKey, graphObject);
    } else {
        throw new IndexOutOfBoundsException("position");
    }
}

From source file:com.meidusa.amoeba.net.poolable.copy.CursorableLinkedList.java

/**
 * Returns a fail-fast ListIterator.//from ww w. ja  v  a 2 s.  c  o  m
 * @see List#listIterator(int)
 */
public ListIterator listIterator(int index) {
    if (index < 0 || index > _size) {
        throw new IndexOutOfBoundsException(index + " < 0 or > " + _size);
    }
    return new ListIter(index);
}

From source file:Polygon2D.java

/**
 * Constructs and initializes a <code>Polyline2D</code> from the specified
 * parameters./*w w  w.jav a  2 s .c  om*/
 * @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>Polyline2D</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 Polyline2D(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 + 1]; // make space for one more to close the polyline
    this.ypoints = new float[npoints + 1]; // make space for one more to close the polyline
    System.arraycopy(xpoints, 0, this.xpoints, 0, npoints);
    System.arraycopy(ypoints, 0, this.ypoints, 0, npoints);
    calculatePath();
}