List of usage examples for java.lang IndexOutOfBoundsException IndexOutOfBoundsException
public IndexOutOfBoundsException(int index)
From source file:com.clust4j.utils.MatUtils.java
/** * Retrieve a column from a uniform matrix * @param data/*from w w w . j av a2 s . c o m*/ * @param idx * @throws NonUniformMatrixException if the matrix is not uniform * @throws IndexOutOfBoundsException if the idx is * less than 0 or >= the length of the matrix * @return the column at the idx */ public static double[] getColumn(final double[][] data, final int idx) { checkDimsForUniformity(data); final int m = data.length, n = data[0].length; if (idx >= n || idx < 0) throw new IndexOutOfBoundsException(idx + ""); final double[] col = new double[m]; for (int i = 0; i < m; i++) col[i] = data[i][idx]; return col; }
From source file:com.github.jessemull.microflex.bigdecimalflex.plate.WellSetBigDecimal.java
/** * Returns a view of the portion of this set between the indices. * @param int the first index//from w w w. j ava 2s . c o m * @param int the second index * @param boolean includes the first input well in the returned set * @param boolean includes the second input well in the returned set * @return last well in the set */ public Set<WellBigDecimal> subSet(int index1, boolean inclusive1, int index2, boolean inclusive2) { if (index1 > this.wells.size() - 1 || index2 > this.wells.size() - 1 || index1 < 0 || index2 < 0 || index1 > index2) { throw new IndexOutOfBoundsException("Index is outside of valid range: " + index1 + " " + index2); } int current = 0; Set<WellBigDecimal> subset = new TreeSet<WellBigDecimal>(); Iterator<WellBigDecimal> iter = this.wells.iterator(); while (current < index1) { if (current == index1 && inclusive1) { subset.add(iter.next()); } iter.next(); current++; } while (current < index2) { if (current++ == index2 && inclusive2) { subset.add(iter.next()); break; } subset.add(iter.next()); } return subset; }
From source file:com.github.jessemull.microflexbigdecimal.plate.WellSet.java
/** * Returns a view of the portion of this set between the indices. * @param int the first index//from ww w . j a v a2 s .c o m * @param int the second index * @return the subset */ public Set<Well> subSet(int index1, int index2) { if (index1 > this.wells.size() - 1 || index2 > this.wells.size() - 1 || index1 < 0 || index2 < 0 || index1 > index2) { throw new IndexOutOfBoundsException( "Index is outside of valid range: " + index1 + " " + index2 + " " + this.wells.size()); } int current = 0; Set<Well> subset = new TreeSet<Well>(); Iterator<Well> iter = this.wells.iterator(); while (current < index1) { iter.next(); current++; } while (current < index2) { subset.add(iter.next()); current++; } return subset; }
From source file:com.github.jessemull.microflex.doubleflex.plate.WellSetDouble.java
/** * Returns a view of the portion of this set between the indices. * @param int the first index//from ww w . j a va 2s . c om * @param int the second index * @return the subset */ public Set<WellDouble> subSet(int index1, int index2) { if (index1 > this.wells.size() - 1 || index2 > this.wells.size() - 1 || index1 < 0 || index2 < 0 || index1 > index2) { throw new IndexOutOfBoundsException( "Index is outside of valid range: " + index1 + " " + index2 + " " + this.wells.size()); } int current = 0; Set<WellDouble> subset = new TreeSet<WellDouble>(); Iterator<WellDouble> iter = this.wells.iterator(); while (current < index1) { iter.next(); current++; } while (current < index2) { subset.add(iter.next()); current++; } return subset; }
From source file:com.github.jessemull.microflex.integerflex.plate.WellSetInteger.java
/** * Returns a view of the portion of this set between the indices. * @param int the first index//from w ww. j a va 2s . c om * @param int the second index * @return the subset */ public Set<WellInteger> subSet(int index1, int index2) { if (index1 > this.wells.size() - 1 || index2 > this.wells.size() - 1 || index1 < 0 || index2 < 0 || index1 > index2) { throw new IndexOutOfBoundsException( "Index is outside of valid range: " + index1 + " " + index2 + " " + this.wells.size()); } int current = 0; Set<WellInteger> subset = new TreeSet<WellInteger>(); Iterator<WellInteger> iter = this.wells.iterator(); while (current < index1) { iter.next(); current++; } while (current < index2) { subset.add(iter.next()); current++; } return subset; }
From source file:com.clust4j.utils.MatUtils.java
/** * Retrieve a column from a uniform matrix * @param data//from ww w . j a va2s . c om * @param idx * @throws NonUniformMatrixException if the matrix is not uniform * @throws IndexOutOfBoundsException if the idx is * less than 0 or >= the length of the matrix * @return the column at the idx */ public static int[] getColumn(final int[][] data, final int idx) { checkDimsForUniformity(data); final int m = data.length, n = data[0].length; if (idx >= n || idx < 0) throw new IndexOutOfBoundsException(idx + ""); final int[] col = new int[m]; for (int i = 0; i < m; i++) col[i] = data[i][idx]; return col; }
From source file:com.github.jessemull.microflex.bigintegerflex.plate.WellSetBigInteger.java
/** * Returns a view of the portion of this set between the indices. * @param int the first index// w w w .j av a 2s.com * @param int the second index * @return the subset */ public Set<WellBigInteger> subSet(int index1, int index2) { if (index1 > this.wells.size() - 1 || index2 > this.wells.size() - 1 || index1 < 0 || index2 < 0 || index1 > index2) { throw new IndexOutOfBoundsException( "Index is outside of valid range: " + index1 + " " + index2 + " " + this.wells.size()); } int current = 0; Set<WellBigInteger> subset = new TreeSet<WellBigInteger>(); Iterator<WellBigInteger> iter = this.wells.iterator(); while (current < index1) { iter.next(); current++; } while (current < index2) { subset.add(iter.next()); current++; } return subset; }
From source file:com.github.jessemull.microflex.bigdecimalflex.plate.WellSetBigDecimal.java
/** * Returns a view of the portion of this set between the indices. * @param int the first index/*from ww w. ja v a2 s . c o m*/ * @param int the second index * @return the subset */ public Set<WellBigDecimal> subSet(int index1, int index2) { if (index1 > this.wells.size() - 1 || index2 > this.wells.size() - 1 || index1 < 0 || index2 < 0 || index1 > index2) { throw new IndexOutOfBoundsException( "Index is outside of valid range: " + index1 + " " + index2 + " " + this.wells.size()); } int current = 0; Set<WellBigDecimal> subset = new TreeSet<WellBigDecimal>(); Iterator<WellBigDecimal> iter = this.wells.iterator(); while (current < index1) { iter.next(); current++; } while (current < index2) { subset.add(iter.next()); current++; } return subset; }
From source file:com.clust4j.utils.MatUtils.java
/** * Retrieve a set of columns from a uniform matrix * @param data/*from w w w .j a v a2s. c o m*/ * @param idx * @throws IllegalArgumentException if the rows are empty * @throws NonUniformMatrixException if the matrix is not uniform * @throws IndexOutOfBoundsException if the idx is * less than 0 or >= the length of the matrix * @return the new matrix */ public static double[][] getColumns(final double[][] data, final int[] idcs) { checkDimsForUniformity(data); final double[][] out = new double[data.length][idcs.length]; int idx = 0; for (int col : idcs) { if (col < 0 || col >= data[0].length) throw new IndexOutOfBoundsException(col + ""); for (int i = 0; i < data.length; i++) out[i][idx] = data[i][col]; idx++; } return out; }
From source file:CopyOnWriteArrayList.java
/** * {@inheritDoc}//from ww w.j av a 2 s . c o m * * <p>The list iterator returned by this implementation will throw an * <tt>UnsupportedOperationException</tt> in its <tt>remove</tt>, * <tt>set</tt> and <tt>add</tt> methods. * * @throws IndexOutOfBoundsException {@inheritDoc} */ public ListIterator listIterator(final int index) { Object[] elements = getArray(); int len = elements.length; if (index < 0 || index > len) throw new IndexOutOfBoundsException("Index: " + index); return new COWIterator(getArray(), index); }