List of usage examples for java.lang IndexOutOfBoundsException IndexOutOfBoundsException
public IndexOutOfBoundsException(int index)
From source file:IntArrayList.java
/** * Inserts the specified element at the specified position in this * list.//from w w w .j ava 2 s. c o m * Shifts the element currently at that position (if any) and any subsequent * elements to the right (adds one to their indices). * * @param index * Index at which the specified element is to be inserted. * @param element * Element to be inserted. * * @exception IndexOutOfBoundsException * If index is out of range <tt>(index < 0 || index > size())</tt>. */ public void add(int index, int element) { if (index < 0 || index > size) throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size); ensureCapacity(size + 1); System.arraycopy(elements, index, elements, index + 1, size - index); elements[index] = element; ++size; }
From source file:BooleanArrayList.java
private void checkRange(int index) { if (index < 0 || index >= size) { throw new IndexOutOfBoundsException( "Index should be at least 0 and less than " + size + ", found " + index); }//w ww. java 2 s . c o m }
From source file:com.example.jonas.materialmockups.activities.ExhibitDetailsActivity.java
/** Displays the current exhibit page */ public void displayCurrentExhibitPage() { if (currentPageIndex >= exhibitPages.size()) throw new IndexOutOfBoundsException("currentPageIndex >= exhibitPages.size() !"); // collapse bottom sheet first bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); // set previous & next button if (currentPageIndex == 0) btnPreviousPage.setVisibility(View.GONE); else/*www .j a va 2 s .c o m*/ btnPreviousPage.setVisibility(View.VISIBLE); if (currentPageIndex >= exhibitPages.size() - 1) btnNextPage.setVisibility(View.GONE); else btnNextPage.setVisibility(View.VISIBLE); // get ExhibitPageFragment for Page Page page = exhibitPages.get(currentPageIndex); ExhibitPageFragment pageFragment = ExhibitPageFragmentFactory.getFragmentForExhibitPage(page); if (pageFragment == null) throw new NullPointerException("pageFragment is null!"); pageFragment.setArguments(extras); // remove old fragment and display new fragment if (findViewById(R.id.content_fragment_container) != null) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); // remove current fragment (if present) Fragment currentFragment = getSupportFragmentManager().findFragmentByTag(TAG_CURRENT_FRAGMENT); if (currentFragment != null) transaction.remove(currentFragment); // add new fragment transaction.add(R.id.content_fragment_container, pageFragment, TAG_CURRENT_FRAGMENT); transaction.commit(); } // configure bottom sheet BottomSheetConfig config = pageFragment.getBottomSheetConfig(); if (config == null) throw new RuntimeException("BottomSheetConfig cannot be null!"); if (config.displayBottomSheet) { BottomSheetFragment sheetFragment = config.bottomSheetFragment; if (sheetFragment == null) throw new NullPointerException("sheetFragment is null!"); // remove old fragment and display new fragment if (findViewById(R.id.bottom_sheet_fragment_container) != null) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); // remove current fragment (if present) Fragment currentFragment = getSupportFragmentManager() .findFragmentByTag(TAG_CURRENT_BOTTOMSHEET_FRAGMENT); if (currentFragment != null) transaction.remove(currentFragment); // add new fragment transaction.add(R.id.bottom_sheet_fragment_container, sheetFragment, TAG_CURRENT_BOTTOMSHEET_FRAGMENT); transaction.commit(); } // configure FAB setFabAction(config.fabAction); // configure peek height and max height int peekHeightInPixels = (int) PixelDpConversion.convertDpToPixel(config.peekHeight); bottomSheetBehavior.setPeekHeight(peekHeightInPixels); int maxHeightInPixels = (int) PixelDpConversion.convertDpToPixel(config.maxHeight); ViewGroup.LayoutParams params = bottomSheet.getLayoutParams(); params.height = maxHeightInPixels; bottomSheet.setLayoutParams(params); } else { // config.displayBottomSheet == false bottomSheet.setVisibility(View.GONE); } }
From source file:com.redhat.rhn.frontend.nav.NavNode.java
/** * get the "best" most "proper" URL for this node * @return "best" most "proper" URL for this node *///w ww. j a va2 s . c o m public String getPrimaryURL() { if (urls != null && urls.size() > 0) { return urls.get(0); } throw new IndexOutOfBoundsException( "attempt to ask for primary URL of " + this.getName() + " node with no URLs associated"); }
From source file:BooleanArrayList.java
private void checkRangeIncludingEndpoint(int index) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException( "Index should be at least 0 and at most " + size + ", found " + index); }/*from w ww . j a v a 2 s . c om*/ }
From source file:com.mani.cucumber.ReflectionUtils.java
private static Object digInList(List<Object> target, String field) { int index = field.indexOf(':'); if (index == -1) { throw new IllegalStateException( "Invalid path expression: cannot " + "evaluate '" + field + "' on a List"); }//w ww. j av a 2 s . c o m String offset = field.substring(0, index); String type = field.substring(index + 1); if (offset.equals("*")) { throw new UnsupportedOperationException("What does this even mean?"); } int intOffset = Integer.parseInt(offset); if (intOffset < 0) { // Offset from the end of the list intOffset += target.size(); if (intOffset < 0) { throw new IndexOutOfBoundsException(Integer.toString(intOffset)); } } if (intOffset < target.size()) { return target.get(intOffset); } // Extend with default instances if need be. while (intOffset > target.size()) { target.add(createDefaultInstance(type)); } Object result = createDefaultInstance(type); target.add(result); return result; }
From source file:com.yahoo.glimmer.indexing.RDFDocumentFactory.java
public void ensureFieldIndex(final int index) { if (fields == null) { throw new IllegalStateException("Fields not loaded."); }/* w ww.j a v a 2 s.c om*/ if (index < 0 || index >= fields.length) { throw new IndexOutOfBoundsException( "For field index " + index + ". There are only " + fields.length + " fields."); } }
From source file:com.framework.utils.error.PreConditions.java
/** * Ensures that {@code index} specifies a valid <i>element</i> in an array, list or string of size * {@code size}. An element index may range from zero, inclusive, to {@code size}, exclusive. * * @param index a user-supplied index identifying an element of an array, list or string * @param size the size of that array, list or string * @param desc the text to use to describe this index in an error message * * @return the value of {@code index}/*from w w w. ja va 2 s .com*/ * * @throws IndexOutOfBoundsException if {@code index} is negative or is not less than {@code size} * @throws IllegalArgumentException if {@code size} is negative */ public static int checkElementIndex(int index, int size, String desc) { // Carefully optimized for execution by hotspot (explanatory comment above) if (index < 0 || index >= size) { throw new PreConditionException(new IndexOutOfBoundsException(badElementIndex(index, size, desc))); } return index; }
From source file:com.examples.with.different.packagename.idnaming.ReaderInputStream.java
/** * Read the specified number of bytes into an array. * //from ww w . j a v a 2s .c o m * @param b the byte array to read into * @param off the offset to start reading bytes into * @param len the number of bytes to read * @return the number of bytes read or <code>-1</code> * if the end of the stream has been reached * @throws IOException if an I/O error occurs */ @Override public int read(byte[] b, int off, int len) throws IOException { if (b == null) { throw new NullPointerException("Byte array must not be null"); } if (len < 0 || off < 0 || (off + len) > b.length) { throw new IndexOutOfBoundsException("Array Size=" + b.length + ", offset=" + off + ", length=" + len); } int read = 0; if (len == 0) { return 0; // Always return 0 if len == 0 } while (len > 0) { if (encoderOut.hasRemaining()) { int c = Math.min(encoderOut.remaining(), len); encoderOut.get(b, off, c); off += c; len -= c; read += c; } else { fillBuffer(); if (endOfInput && !encoderOut.hasRemaining()) { break; } } } return read == 0 && endOfInput ? -1 : read; }
From source file:io.horizondb.io.buffers.AbstractBuffer.java
/** * {@inheritDoc}//from w ww . j a v a2 s .c o m */ @Override public Buffer writerIndex(int writerIndex) { if (writerIndex < this.readerIndex || writerIndex > capacity()) { @SuppressWarnings("boxing") String msg = String.format( "writerIndex: %d " + "(expected: readerIndex(%d) <= writerIndex <= capacity(%d))", writerIndex, this.readerIndex, capacity()); throw new IndexOutOfBoundsException(msg); } this.writerIndex = writerIndex; return this; }