List of usage examples for java.lang IndexOutOfBoundsException IndexOutOfBoundsException
public IndexOutOfBoundsException()
From source file:ffx.potential.extended.ExtUtils.java
/** * Element-wise sum over a list of 1D double arrays. * This implementation benchmarks faster than the equivalent Java8 stream() API. *//*from w ww . j ava 2 s .co m*/ private static double[] eleSum1DArrays(List<double[]> terms, int numESVs) { double[] termSum = new double[terms.size()]; for (int iTerm = 0; iTerm < terms.size(); iTerm++) { double[] currentTerm = terms.get(iTerm); if (currentTerm.length != numESVs) { logger.warning(format("iTerm %d length: %d, numESVs: %d", iTerm, terms.get(iTerm).length, numESVs)); throw new IndexOutOfBoundsException(); } for (int iESV = 0; iESV < numESVs; iESV++) { termSum[iESV] += currentTerm[iESV]; } } return termSum; }
From source file:com.ponysdk.ui.server.basic.PListBox.java
private void checkIndex(final int index) { if (index >= getItemCount()) throw new IndexOutOfBoundsException(); }
From source file:ffx.potential.extended.ExtUtils.java
/** * Element-wise sum over a list of 2D double arrays. *//* w ww . ja v a 2 s .c o m*/ private static double[][] eleSum2DArrays(List<double[][]> terms, int numESVs, int nVars) { if (terms == null || terms.isEmpty()) { throw new NullPointerException("Summing an empty or null terms list."); } double[][] termSum = new double[numESVs][nVars]; for (int iTerm = 0; iTerm < terms.size(); iTerm++) { double[][] currentTerm = terms.get(iTerm); if (currentTerm.length != numESVs) { throw new IndexOutOfBoundsException(); } for (int iESV = 0; iESV < numESVs; iESV++) { if (currentTerm[iESV].length != nVars) { throw new IndexOutOfBoundsException(); } for (int iAtom = 0; iAtom < nVars; iAtom++) { termSum[iESV][iAtom] += currentTerm[iESV][iAtom]; } } } return termSum; }
From source file:de.fhg.iais.cortex.rest.resources.BinaryResourceTest.java
private void createMocks() { this.headers = mock(HttpHeaders.class); this.mockAccessService = mock(IAccessService.class); stub(this.mockAccessService.getBinary("1", "test.txt")).toReturn( new Binary(new ByteArrayInputStream("TestBinary".getBytes()), "TestBinary".getBytes().length)); stub(this.mockAccessService.getBinary("3", "test.txt")).toReturn( new Binary(new ByteArrayInputStream("TestBinary".getBytes()), "TestBinary".getBytes().length)); stub(this.mockAccessService.getBinary("4", "test.txt")).toReturn( new Binary(new ByteArrayInputStream("TestBinary".getBytes()), "TestBinary".getBytes().length)); stub(this.mockAccessService.getBinary("2", "fail.xml")) .toThrow(new ItemNotFoundException("Item: 2 / fail.xml not found: Binary not found")); stub(this.mockAccessService.getBinary("3", "fail.xml")).toThrow(new IndexOutOfBoundsException()); stub(this.mockAccessService.getAip(Matchers.anyString())).toReturn(new AipObject()); this.mockRoleProvider = mock(RoleProvider.class); this.mockSearchService = mock(ISearchService.class); }
From source file:com.opendoorlogistics.studio.components.geocoder.SearchResultsPanel.java
private void setTableModel() { final NumberFormat formatter = DecimalFormat.getInstance(); formatter.setMaximumFractionDigits(4); // update table table.setModel(new AbstractTableModel() { @Override//from w w w .j av a2s .c om public String getColumnName(int column) { switch (column) { case 0: return "Rank"; case 1: return "Address"; case 2: return "Latitude"; case 3: return "Longitude"; case 4: return "Class"; case 5: return "Type"; } throw new IndexOutOfBoundsException(); } public Class<?> getColumnClass(int columnIndex) { return String.class; } @Override public Object getValueAt(int rowIndex, int column) { SearchResultPoint pnt = model.getSearchResults().get(rowIndex); switch (column) { case 0: return Integer.toString(rowIndex + 1); case 1: return pnt.getAddress(); case 2: return formatter.format(pnt.getLatitude()); case 3: return formatter.format(pnt.getLongitude()); case 4: return pnt.getCls(); case 5: return pnt.getType(); } throw new IndexOutOfBoundsException(); } @Override public int getRowCount() { return model.getSearchResults() != null ? model.getSearchResults().size() : 0; } @Override public int getColumnCount() { return 6; } }); PackTableColumn.packAll(table, 6); if (table.getModel().getRowCount() > 0) { table.getSelectionModel().setSelectionInterval(0, 0); } readSelectedIntoModel(); }
From source file:FastBufferedInputStream.java
/** * Reads bytes from this byte-input stream into the specified byte array, * starting at the given offset./*ww w . j a va 2 s . c o m*/ * * <p> This method implements the general contract of the corresponding * <code>{@link InputStream#read(byte[], int, int) read}</code> method of * the <code>{@link InputStream}</code> class. As an additional * convenience, it attempts to read as many bytes as possible by repeatedly * invoking the <code>read</code> method of the underlying stream. This * iterated <code>read</code> continues until one of the following * conditions becomes true: <ul> * * <li> The specified number of bytes have been read, * * <li> The <code>read</code> method of the underlying stream returns * <code>-1</code>, indicating end-of-file, or * * <li> The <code>available</code> method of the underlying stream * returns zero, indicating that further input requests would block. * * </ul> If the first <code>read</code> on the underlying stream returns * <code>-1</code> to indicate end-of-file then this method returns * <code>-1</code>. Otherwise this method returns the number of bytes * actually read. * * <p> Subclasses of this class are encouraged, but not required, to * attempt to read as many bytes as possible in the same fashion. * * @param b destination buffer. * @param off offset at which to start storing bytes. * @param len maximum number of bytes to read. * @return the number of bytes read, or <code>-1</code> if the end of * the stream has been reached. * @exception IOException if this input stream has been closed by * invoking its {@link #close()} method, * or an I/O error occurs. */ public int read(byte b[], int off, int len) throws IOException { getBufIfOpen(); // Check for closed stream if ((off | len | (off + len) | (b.length - (off + len))) < 0) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } int n = 0; for (;;) { int nread = read1(b, off + n, len - n); if (nread <= 0) return (n == 0) ? nread : n; n += nread; if (n >= len) return n; // if not closed but no bytes available, return InputStream input = in; if (input != null && input.available() <= 0) return n; } }
From source file:fr.inria.atlanmod.neoemf.graph.blueprints.datastore.estores.impl.DirectWriteBlueprintsResourceEStoreImpl.java
protected void add(InternalEObject object, EAttribute eAttribute, int index, Object value) { Vertex vertex = graph.getOrCreateVertex(object); Integer size = getSize(vertex, eAttribute); size++;/*w w w.j av a 2 s . com*/ setSize(vertex, eAttribute, size); if (index < 0 || index > size) { throw new IndexOutOfBoundsException(); } else { for (int i = size - 1; i > index; i--) { Object movingProperty = vertex.getProperty(eAttribute.getName() + SEPARATOR + (i - 1)); vertex.setProperty(eAttribute.getName() + SEPARATOR + i, movingProperty); } vertex.setProperty(eAttribute.getName() + SEPARATOR + index, serializeToProperty(eAttribute, value)); } }
From source file:fr.gael.dhus.network.RegulatedInputStream.java
/** * Reads bytes from this byte-input stream into the specified byte array, * starting at the given offset.//w w w .ja v a2 s . c o m * <p> * This method implements the general contract of the corresponding * <code>{@link InputStream#read(byte[], int, int) read}</code> method of the * <code>{@link InputStream}</code> class. As an additional convenience, it * attempts to read as many bytes as possible by repeatedly invoking the * <code>read</code> method of the underlying stream. This iterated * <code>read</code> continues until one of the following conditions becomes * true: * <ul> * <li>The specified number of bytes have been read, * <li>The <code>read</code> method of the underlying stream returns * <code>-1</code>, indicating end-of-file, or * <li>The <code>available</code> method of the underlying stream returns * zero, indicating that further input requests would block. * </ul> * If the first <code>read</code> on the underlying stream returns * <code>-1</code> to indicate end-of-file then this method returns * <code>-1</code>. Otherwise this method returns the number of bytes * actually read. * <p> * Subclasses of this class are encouraged, but not required, to attempt to * read as many bytes as possible in the same fashion. * * @param b destination buffer. * @param off offset at which to start storing bytes. * @param len maximum number of bytes to read. * @return the number of bytes read, or <code>-1</code> if the end of the * stream has been reached. * @exception IOException if this input stream has been closed by invoking * its {@link #close()} method, or an I/O error occurs. */ public synchronized int read(byte b[], int off, int len) throws IOException { getBufIfOpen(); // Check for closed stream if ((off | len | (off + len) | (b.length - (off + len))) < 0) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } int n = 0; int total_nread = 0; for (;;) { int nread = read1(b, off + n, len - n); if (nread <= 0) { total_nread = (n == 0) ? nread : n; break; } n += nread; if (n >= len) { total_nread = n; break; } // if not closed but no bytes available, return InputStream input = in; if (input != null && input.available() <= 0) { total_nread = n; break; } } // Acquire from regulated flow if ((this.flow != null) && (total_nread > 0)) { try { this.flow.acquire(total_nread); } catch (InterruptedException exception) { logger.error(exception); this.close(); throw new IOException(exception); } catch (RegulationException exception) { logger.error(exception); this.close(); throw exception; } } if (listener != null) listener.bytesTransferred(this.flow.getTransferedSize(), total_nread, this.connectionParameters.getStreamSize()); // Return total read number return total_nread; }
From source file:fr.inria.atlanmod.neoemf.graph.blueprints.datastore.estores.impl.DirectWriteBlueprintsResourceEStoreImpl.java
protected void add(InternalEObject object, EReference eReference, int index, EObject value) { Vertex vertex = graph.getOrCreateVertex(object); Vertex referencedVertex = graph.getOrCreateVertex(value); // Update the containment reference if needed if (eReference.isContainment()) { updateContainment(eReference, vertex, referencedVertex); }/* w w w. j a v a 2 s .com*/ Integer size = getSize(vertex, eReference); int newSize = size + 1; if (index < 0 || index > newSize) { throw new IndexOutOfBoundsException(); } else { if (index != size) { // Avoid unnecessary database access Iterator<Edge> iterator = vertex.query().labels(eReference.getName()).direction(Direction.OUT) .interval(POSITION, index, newSize).edges().iterator(); while (iterator.hasNext()) { Edge edge = iterator.next(); int position = edge.getProperty(POSITION); edge.setProperty(POSITION, position + 1); } } Edge edge = vertex.addEdge(eReference.getName(), referencedVertex); edge.setProperty(POSITION, index); } setSize(vertex, eReference, newSize); }
From source file:com.datumbox.common.dataobjects.Dataset.java
/** * Sets the record in a particular position in the dataset, WITHOUT updating * the internal meta-info. This method is similar to set() and it allows quick updates * on the dataset. Nevertheless it is not advised to use this method because * unless you explicitly call the recalculateMeta() method, the meta data * will be corrupted. If you do use this method, MAKE sure you perform the * recalculation after you are done with the updates. * //from ww w.j av a 2 s.com * @param rId * @param r */ public void _set(Integer rId, Record r) { if (recordList.containsKey(rId) == false) { throw new IndexOutOfBoundsException(); //ensure that the record has already be set with add() } recordList.put(rId, r); }