Example usage for java.lang ArrayIndexOutOfBoundsException ArrayIndexOutOfBoundsException

List of usage examples for java.lang ArrayIndexOutOfBoundsException ArrayIndexOutOfBoundsException

Introduction

In this page you can find the example usage for java.lang ArrayIndexOutOfBoundsException ArrayIndexOutOfBoundsException.

Prototype

public ArrayIndexOutOfBoundsException(int index) 

Source Link

Document

Constructs a new ArrayIndexOutOfBoundsException class with an argument indicating the illegal index.

Usage

From source file:org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.java

/**
 * Prefix for adding with identifier and namespace, when it is a java keyword or starting with digits.
 *
 * @param conflictResolver object of YANG to java naming conflict util
 * @return prefix which needs to be added
 *//*from   w ww  .java2  s .com*/
public static String getPrefixForIdentifier(YangToJavaNamingConflictUtil conflictResolver) {

    String prefixForIdentifier = null;
    if (conflictResolver != null) {
        prefixForIdentifier = conflictResolver.getPrefixForIdentifier();
    }
    if (prefixForIdentifier != null) {
        prefixForIdentifier = prefixForIdentifier.replaceAll(REGEX_WITH_ALL_SPECIAL_CHAR, COLON);
        String[] strArray = prefixForIdentifier.split(COLON);
        try {
            if (strArray[0].isEmpty()) {
                List<String> stringArrangement = new ArrayList<>();
                stringArrangement.addAll(Arrays.asList(strArray).subList(1, strArray.length));
                strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
            }
            prefixForIdentifier = strArray[0];
            for (int j = 1; j < strArray.length; j++) {
                prefixForIdentifier = prefixForIdentifier + strArray[j].substring(0, 1).toUpperCase()
                        + strArray[j].substring(1);
            }
        } catch (ArrayIndexOutOfBoundsException outOfBoundsException) {
            throw new ArrayIndexOutOfBoundsException("The given prefix in pom.xml is invalid.");
        }
    } else {
        prefixForIdentifier = YANG_AUTO_PREFIX;
    }
    return prefixForIdentifier;
}

From source file:com.luseen.spacenavigation.SpaceNavigationView.java

/**
 * Show badge at index/*www.j ava2s .c om*/
 *
 * @param itemIndex index
 * @param badgeText badge count text
 */
public void showBadgeAtIndex(int itemIndex, int badgeText, @ColorInt int badgeColor) {
    if (itemIndex < 0 || itemIndex > spaceItems.size()) {
        throw new ArrayIndexOutOfBoundsException("Your item index can't be 0 or greater than space item size,"
                + " your items size is " + spaceItems.size() + ", your current index is :" + itemIndex);
    } else {
        RelativeLayout badgeView = badgeList.get(itemIndex);

        /**
         * Set circle background to badge view
         */
        badgeView.setBackground(BadgeHelper.makeShapeDrawable(badgeColor));

        BadgeItem badgeItem = new BadgeItem(itemIndex, badgeText, badgeColor);
        BadgeHelper.showBadge(badgeView, badgeItem);
        badgeSaveInstanceHashMap.put(itemIndex, badgeItem);
    }
}

From source file:SequencedHashMap.java

/**
 * Returns the Map.Entry at the specified index
 *
 * @throws ArrayIndexOutOfBoundsException if the specified index is <code>&lt; 0</code> or <code>&gt;</code> the
 *                                        size of the map.
 *//*from w  w w.  j  a  v a  2s.  c o  m*/
private Map.Entry getEntry(int index) {
    Entry pos = sentinel;
    if (index < 0) {
        throw new ArrayIndexOutOfBoundsException(index + " < 0");
    }

    // loop to one before the position
    int i = -1;
    while ((i < (index - 1)) && (pos.next != sentinel)) {
        i++;
        pos = pos.next;
    }

    // pos.next is the requested position
    // if sentinel is next, past end of list
    if (pos.next == sentinel) {
        throw new ArrayIndexOutOfBoundsException(index + " >= " + (i + 1));
    }
    return pos.next;
}

From source file:com.idylwood.utils.MathUtils.java

public static final Matrix matrixMultiply(final Matrix first, final Matrix second) {
    if (first.cols() != second.rows())
        throw new ArrayIndexOutOfBoundsException("Trying to multiply matrices of different dimensions?!");
    final Matrix ret = new Matrix(first.rows(), second.cols());
    for (int i = 0; i < second.cols(); i++) {
        // extract the column beforehand to improve cache hits
        // TODO think about extracting on fly to save cost of read
        final double vector[] = second.extractColumn(i);
        for (int j = 0; j < first.rows(); j++) {
            final double val = linearCombination(first.data(), vector, j * first.cols(), 0, first.cols());
            ret.set(j, i, val);
        }/* w  ww  .ja  v a2 s.  c om*/
    }
    return ret;
}

From source file:com.idylwood.utils.MathUtils.java

public static final Matrix matrixMultiplyFast(final Matrix first, final Matrix second) {
    if (first.cols() != second.rows())
        throw new ArrayIndexOutOfBoundsException("Trying to multiply matrices of different dimensions?!");
    final Matrix ret = new Matrix(first.rows(), second.cols());
    for (int i = 0; i < second.cols(); i++) {
        // extract the column beforehand to improve cache hits
        // TODO think about extracting on fly to save cost of read
        final double vector[] = second.extractColumn(i);
        for (int j = 0; j < first.rows(); j++) {
            final double val = linearCombinationFast(first.data(), vector, j * first.cols(), 0, first.cols());
            ret.set(j, i, val);
        }/*from  w  w  w .  j  a v a  2 s .  com*/
    }
    return ret;
}

From source file:com.almalence.util.Util.java

public static String logMatrix(final float[] transform, final int width, final int height) {
    if (width * height < transform.length) {
        throw new ArrayIndexOutOfBoundsException(
                String.format("width(%d) * height(%d) > transform(%d)", width, height, transform));
    }//from w  w  w  .ja v a 2s .co  m

    String format = "";
    final Object[] args = new Object[width * height];
    int cursor = 0;

    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            format += "% #6.2f  ";
            args[cursor] = transform[cursor];
            cursor++;
        }

        format += "\n";
    }

    return String.format(format, args);
}

From source file:com.idylwood.utils.MathUtils.java

public static final double[][] matrixMultiply(final double[][] first, final double[][] second) {
    // i,j,k/*from  w w  w.  j av  a2s  . c o  m*/
    final int firstRows = first.length;
    final int firstCols = first[0].length;
    final int secondRows = second.length;
    final int secondCols = second[0].length;
    if (firstCols != secondRows)
        throw new ArrayIndexOutOfBoundsException("Trying to multiply matrices of different dimensions?!");
    final double ret[][] = new double[firstRows][secondCols];
    for (int i = 0; i < secondCols; i++)
    // iterate over columns so we can maintain cache locality!
    {
        // TODO think about extracting column on the fly
        final double[] vector = extractColumn(second, i);
        for (int k = 0; k < firstRows; k++) {
            ret[k][i] = linearCombination(first[k], vector);
        }
    }
    return ret;
}

From source file:com.idylwood.utils.MathUtils.java

public static final double[][] matrixMultiplyTwo(final double[][] first, final double[][] second) {
    final int firstRows = first.length;
    final int firstCols = first[0].length;
    final int secondRows = second.length;
    final int secondCols = second[0].length;
    if (firstCols != secondRows)
        throw new ArrayIndexOutOfBoundsException("Trying to multiply matrices of different dimensions?!");
    final double ret[][] = new double[firstRows][secondCols];
    final double err[][] = new double[firstRows][secondCols];

    final int unroll = 3;
    final int len = secondCols - secondCols % unroll;

    for (int j = 0; j < firstRows; j++) {
        for (int i = 0; i < secondCols; i++) {
            Arrays.fill(ret[j], 0);
            Arrays.fill(err[j], 0);
            for (int k = 0; k < firstCols; k++) {
                final double prod = first[j][k] * second[k][i];
                final double sum = ret[j][i];
                final double hi = sum + prod;
                ret[j][i] = hi;/* ww w  .  j a  va 2  s.c  o  m*/
                err[j][i] += hi - sum - prod;
            }
        }
    }

    for (int i = 0; i < firstRows; i++)
        for (int j = 0; j < secondCols; j++)
            ret[i][j] -= err[i][j];
    return ret;
}

From source file:org.diorite.command.Arguments.java

@Override
public Iterator<String> iterator() {
    return new Iterator<String>() {
        private int index = 0;

        @Override/*  www. j av a 2 s.com*/
        public boolean hasNext() {
            return this.index < Arguments.this.args.length;
        }

        @Override
        public String next() {
            if (Arguments.this.args.length <= this.index) {
                throw new ArrayIndexOutOfBoundsException(
                        "Out of range, length: " + Arguments.this.args.length + ", index: " + this.index);
            }
            return Arguments.this.args[this.index++];
        }
    };
}

From source file:com.microsoft.tfs.jni.internal.ntlm.JavaNTLM.java

/**
 * Adds the given byte to the response.//  w  ww .j a v a 2s  .  c  om
 *
 * @params buf buffer to add bytes to
 * @params pos position to add bytes
 * @param b
 *        the byte to add.
 */
private static void addByte(final byte[] buf, int pos, final byte b) {
    if (pos < 0 || buf.length < pos + 1) {
        throw new ArrayIndexOutOfBoundsException(
                MessageFormat.format("Attempt to add one byte at position {0} to array of length {1}", //$NON-NLS-1$
                        pos, buf.length));
    }

    buf[pos++] = b;
}