List of usage examples for java.lang IndexOutOfBoundsException IndexOutOfBoundsException
public IndexOutOfBoundsException()
From source file:Main.java
static public int max(int[] values) { if (values.length < 2) throw new IndexOutOfBoundsException(); int max = values[0]; for (int i = 1; i < values.length; i++) if (values[i] > max) max = values[i];/*from w ww . ja v a2s .com*/ return max; }
From source file:Main.java
public static <E> E getElementAtIndex(Collection<E> set, int idx) { if (idx >= set.size() || idx < 0) { throw new IndexOutOfBoundsException(); }//from www . j av a2 s . c om Iterator<E> it = set.iterator(); for (int i = 0; i < idx; ++i) { it.next(); } return it.next(); }
From source file:Main.java
public static Object[] getLine(IDocument document, int offset) { String text = document.get(); if (offset > text.length()) { throw new IndexOutOfBoundsException(); }//w w w . ja v a 2 s . co m int start = offset, end = offset; while (start > 0 && text.charAt(start) != '\n') { start--; } while (end < text.length() && text.charAt(end) != '\n') { end++; } try { return new Object[] { text.substring(start > 0 ? start + 1 : 0, end), start > 0 ? start + 1 : 0 }; } catch (StringIndexOutOfBoundsException e) { String msg = "exception from getLine(" + offset + "). start=" + start + "; end=" + end + "; text=" + text; throw new RuntimeException(msg, e); } }
From source file:Main.java
public static int readInputStream(InputStream input, byte[] buffer, int offset, int length) throws Exception { int n, o;/*from w w w . j a v a 2s. c o m*/ if (buffer == null) throw new NullPointerException(); if (offset < 0 || length < 0 || offset + length > buffer.length) throw new IndexOutOfBoundsException(); if (length == 0) return 0; if ((n = input.read(buffer, offset++, 1)) < 0) return -1; if (--length > 0 && (o = input.available()) > 0) { n += input.read(buffer, offset, o > length ? length : o); } return n; }
From source file:fi.uta.infim.usaproxyreportgenerator.App.java
/** * Entry point./*from w w w . j a v a2 s.co m*/ * @param args command line arguments */ public static void main(String[] args) { printLicense(); System.out.println(); try { // Command line arguments cli = parser.parse(cliOptions, args); } catch (org.apache.commons.cli.ParseException e) { System.err.println(e.getMessage()); printHelp(); return; } File outputDir; // Use CWD if output dir is not supplied outputDir = new File(cli.getOptionValue("outputDir", ".")); // Set up the browsing data provider that mines the log entries for // visualizable data. setupDataProvider(); // Output CLI options, so that the user sees what is happening System.out.println("Output directory: " + outputDir.getAbsolutePath()); System.out.println("Data provider class: " + dataProviderClass.getCanonicalName()); UsaProxyLogParser parser = new UsaProxyLogParser(); UsaProxyLog log; try { String filenames[] = cli.getArgs(); if (filenames.length == 0) { throw new IndexOutOfBoundsException(); } // Interpret remaining cli args as file names System.out.print("Parsing log file... "); log = parser.parseFilesByName(Arrays.asList(filenames)); System.out.println("done."); } catch (IOException ioe) { System.err.println("Error opening log file: " + ioe.getMessage()); printHelp(); return; } catch (ParseException pe) { System.err.println("Error parsing log file."); printHelp(); return; } catch (IndexOutOfBoundsException e) { System.err.println("Please supply a file name."); printHelp(); return; } catch (NoSuchElementException e) { System.err.println("Error opening log file: " + e.getMessage()); printHelp(); return; } setupJsonConfig(); // Set up JSON processors // Iterate over sessions and generate a report for each one. for (UsaProxySession s : log.getSessions()) { System.out.print("Generating report for session " + s.getSessionID() + "... "); try { generateHTMLReport(s, outputDir); System.out.println("done."); } catch (IOException e) { System.err.println( "I/O error generating report for session id " + s.getSessionID() + ": " + e.getMessage()); System.err.println("Skipping."); } catch (TemplateException e) { System.err.println( "Error populating template for session id " + s.getSessionID() + ": " + e.getMessage()); System.err.println("Skipping."); } } }
From source file:Main.java
public static void readFully(InputStream in, byte b[], int off, int len) throws IOException { if (off < 0 || len < 0 || off + len > b.length) throw new IndexOutOfBoundsException(); while (len > 0) { int count = in.read(b, off, len); if (count < 0) throw new EOFException(); off += count;// w w w. j a va 2s . co m len -= count; } }
From source file:com.github.pemapmodder.pocketminegui.utils.Ring.java
public T get(int offset) { if (offset >= size) { throw new IndexOutOfBoundsException(); }/* www . j ava2s . c o m*/ return array[internalOffset(offset)]; }
From source file:ArrayUtils.java
public static Object[] removeFromArray(Object[] array, int i) { if (i < 0 || i >= array.length) { throw new IndexOutOfBoundsException(); }//from w w w.ja va 2s .co m Object[] newArray = (Object[]) Array.newInstance(array.getClass().getComponentType(), array.length - 1); System.arraycopy(array, 0, newArray, 0, i); System.arraycopy(array, i + 1, newArray, i, array.length - i - 1); return newArray; }
From source file:com.galenframework.parser.CommandLineReader.java
public boolean isNextArgument() { if (hasNext()) { String next = it.next();//from www . j a v a 2 s . com it.previous(); return (next != null && next.startsWith("--")); } else throw new IndexOutOfBoundsException(); }
From source file:api.util.JsonArrayList.java
@Override public T get(int index) { try {/*from w w w . j a v a 2 s. c o m*/ Object val = array.get(index); if (val == JSONObject.NULL) return null; return read(val); } catch (JSONException e) { throw new IndexOutOfBoundsException(); } }