public static <T extends Number> ArrayList<ArrayList<T>> mulMatrixes( ArrayList<ArrayList<T>> a, ArrayList<ArrayList<T>> b, Class<T> type) { ArrayList<ArrayList<T>> result = new ArrayList<ArrayList<T>>(); try { if (a == null || b == null) { throw new NullPointerException(); } int rows = a.size(); int columns = b.get(0).size(); int common = a.get(0).size(); for (int i = 0; i < rows; i++) { ArrayList<T> row = new ArrayList<>(); for (int j = 0; j < columns; j++) { T elem = getNeutralSumElem(type); for (int k = 0; k < common; k++) { elem = sumElements(elem, mulElements(a.get(i).get(k), b.get(k).get(j), type), type); } row.add(elem); } result.add(row); } } catch (NullPointerException e) { Logger.getGlobal().log(Level.SEVERE, "cannot multiply null matrixes"); e.printStackTrace(); return null; } catch (IndexOutOfBoundsException e) { Logger.getGlobal().log(Level.SEVERE, "check your indexes when multiplying matrixes"); e.printStackTrace(); return null; } return result; }
/** Rimuove tutti i link collegati all'oggetto preso in input. */ public void removeAllLink(ElementoSeqLink seq) { ElementoConstraint con; int i = 0; if (lista == null) return; try { while (i < lista.size()) { con = (ElementoConstraint) lista.get(i); if (con != null) { if ((ElementoSeqLink) con.getLink() == seq) { lista.remove(i); i = 0; continue; } } i++; } } catch (IndexOutOfBoundsException e) { String s = "Indice fuori dai limiti ammessi \n dentro la classe ListaCanale$removeAllLink().\n" + e.toString(); JOptionPane.showMessageDialog(null, s, "Condizione di errore!", JOptionPane.WARNING_MESSAGE); return; } }
private static int getJpegSize(ByteBuffer data) { if (data.get(0) != (byte) 0xff || data.get(1) != (byte) 0xd8) throw new VisionException("invalid image"); int pos = 2; while (true) { try { byte b = data.get(pos); if (b != (byte) 0xff) throw new VisionException("invalid image at pos " + pos + " (" + data.get(pos) + ")"); b = data.get(pos + 1); if (b == (byte) 0x01 || (b >= (byte) 0xd0 && b <= (byte) 0xd7)) // various pos += 2; else if (b == (byte) 0xd9) // EOI return pos + 2; else if (b == (byte) 0xd8) // SOI throw new VisionException("invalid image"); else if (b == (byte) 0xda) { // SOS int len = ((data.get(pos + 2) & 0xff) << 8) | (data.get(pos + 3) & 0xff); pos += len + 2; // Find next marker. Skip over escaped and RST markers. while (data.get(pos) != (byte) 0xff || data.get(pos + 1) == (byte) 0x00 || (data.get(pos + 1) >= (byte) 0xd0 && data.get(pos + 1) <= (byte) 0xd7)) pos += 1; } else { // various int len = ((data.get(pos + 2) & 0xff) << 8) | (data.get(pos + 3) & 0xff); pos += len + 2; } } catch (IndexOutOfBoundsException ex) { throw new VisionException("invalid image: could not find jpeg end " + ex.getMessage()); } } }
public static List<String[]> readExcel(Context ctx, String fileName, Object targetSheet) { List<String[]> rowList = new ArrayList<String[]>(); try { InputStream mInputStream = ctx.getResources().getAssets().open(fileName); Workbook wb = Workbook.getWorkbook(mInputStream); Sheet mSheet = null; if (targetSheet instanceof Integer) { mSheet = wb.getSheet((Integer) targetSheet); } else { mSheet = wb.getSheet((String) targetSheet); } int row = getRowCount(mSheet); int columns = getColCount(mSheet); Log.d("W", "Total Row: " + row + ", Total Columns: " + columns); String[] colArray = new String[columns]; for (int i = 1; i < row; i++) { for (int j = 0; j < columns; j++) { Cell temp = mSheet.getCell(j, i); String content = temp.getContents(); Log.d("W", j + " ," + i + " ," + content); colArray[j] = content; } rowList.add(colArray); } wb.close(); mInputStream.close(); } catch (BiffException e) { e.printStackTrace(); } catch (IndexOutOfBoundsException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return rowList; }
public static <T extends Number> ArrayList<ArrayList<T>> multScalarWithMatrix( T scalar, ArrayList<ArrayList<T>> a, Class<T> type) { ArrayList<ArrayList<T>> result = new ArrayList<ArrayList<T>>(); try { if (a == null) { throw new NullPointerException(); } int rows = a.size(); int columns = a.get(0).size(); for (int i = 0; i < rows; i++) { ArrayList<T> row = new ArrayList<>(); for (int j = 0; j < columns; j++) { T elem = mulElements(scalar, a.get(i).get(j), type); row.add(elem); } result.add(row); } return result; } catch (NullPointerException e) { Logger.getGlobal().log(Level.SEVERE, "cannot multiply null matrixes"); e.printStackTrace(); return null; } catch (IndexOutOfBoundsException e) { Logger.getGlobal().log(Level.SEVERE, "check your indexes when multiplying matrixes"); e.printStackTrace(); return null; } }
public int insertRule(final String rule, final int index) throws DOMException { final CSSStyleSheetImpl parentStyleSheet = getParentStyleSheetImpl(); if (parentStyleSheet != null && parentStyleSheet.isReadOnly()) { throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMExceptionImpl.READ_ONLY_STYLE_SHEET); } try { final InputSource is = new InputSource(new StringReader(rule)); final CSSOMParser parser = new CSSOMParser(); parser.setParentStyleSheet(parentStyleSheet); parser.setErrorHandler(ThrowCssExceptionErrorHandler.INSTANCE); // parser._parentRule is never read // parser.setParentRule(_parentRule); final CSSRule r = parser.parseRule(is); // Insert the rule into the list of rules ((CSSRuleListImpl) getCssRules()).insert(r, index); } catch (final IndexOutOfBoundsException e) { throw new DOMExceptionImpl( DOMException.INDEX_SIZE_ERR, DOMExceptionImpl.INDEX_OUT_OF_BOUNDS, e.getMessage()); } catch (final CSSException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } catch (final IOException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } return index; }
private static int safelyConnect(String uri, HttpURLConnection connection) throws IOException { try { connection.connect(); } catch (NullPointerException npe) { // this is an Android bug: http://code.google.com/p/android/issues/detail?id=16895 Log.w(TAG, "Bad URI? " + uri); throw new IOException(npe.toString()); } catch (IllegalArgumentException iae) { // Also seen this in the wild, not sure what to make of it. Probably a bad URL Log.w(TAG, "Bad URI? " + uri); throw new IOException(iae.toString()); } catch (SecurityException se) { // due to bad VPN settings? Log.w(TAG, "Restricted URI? " + uri); throw new IOException(se.toString()); } catch (IndexOutOfBoundsException ioobe) { // Another Android problem? // https://groups.google.com/forum/?fromgroups#!topic/google-admob-ads-sdk/U-WfmYa9or0 Log.w(TAG, "Bad URI? " + uri); throw new IOException(ioobe.toString()); } try { return connection.getResponseCode(); } catch (NullPointerException npe) { // this is maybe this Android bug: http://code.google.com/p/android/issues/detail?id=15554 Log.w(TAG, "Bad URI? " + uri); throw new IOException(npe.toString()); } catch (IllegalArgumentException iae) { // Again seen this in the wild for bad header fields in the server response! or bad reads Log.w(TAG, "Bad server status? " + uri); throw new IOException(iae.toString()); } }
/** * @param origPath 源图片文件路径 * @param width 缩略图设定宽度 * @param height 缩略图设定高度 * @return 返回缩略图,失败返回null */ public Bitmap getImageThumbFromMK(String origPath, int width, int height) { // 产生缩略图,并把该文件存到指定目录下,更新数据库中图片信息 Bitmap thumbnail = null; Log.d(TAG, origPath + ":make thumbnail and insert message in database"); ThumbnailCreator mCreator = new ThumbnailCreator(width, height); thumbnail = mCreator.createThumbnail(origPath); if (thumbnail == null) { return null; } String name = null; try { name = origPath.substring(origPath.lastIndexOf("/") + 1, origPath.lastIndexOf(".")); } catch (IndexOutOfBoundsException e) { e.printStackTrace(); return null; } try { File f = new File(imageDB.getAppDir() + "/" + name); FileOutputStream fOut = null; fOut = new FileOutputStream(f); thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, fOut); fOut.flush(); fOut.close(); imageDB.insert(origPath, f.getPath()); } catch (Exception e) { // TODO Auto-generated catch block Log.d(TAG, "create temp file false"); e.printStackTrace(); } return thumbnail; }
public int setAmbientLightSensors(String s) { synchronized (lock_sensors) { String[] sBuff = new String[8]; try { sBuff = s.substring(2).split(",", 8); } catch (IndexOutOfBoundsException e) { logger.error("[Khepera.setAmbientLightSensors()] in s.substring(2), s=" + s + " ", e); e.printStackTrace(); return 0; } int i = 0; try { for (i = 0; i < 8; i++) { Integer.parseInt(sBuff[i]); } } catch (NumberFormatException e) { logger.error("[Khepera.setAmbientLightSensors()] in sBuff[" + i + "]=" + sBuff[i] + " ", e); e.printStackTrace(); return 0; } ambientLightSensors = sBuff; return 1; } }
@Override protected void handleContent(HTMLNode node, char[] data) { if (node.matches("pre")) { BufferedReader in = new BufferedReader(new CharArrayReader(data)); String line; try { while ((line = in.readLine()) != null) { if (line.trim().isEmpty()) continue; try { String[] properties = line.split("\\s+", 5); Proxy.Type type = null; String host = null; int port = -1; if (properties[0].equals("HTTP")) { type = Proxy.Type.HTTP; host = properties[2]; port = Integer.parseInt(properties[1].substring(5)); } else if (properties[0].equals("SOCKS")) { type = Proxy.Type.SOCKS; host = properties[3]; port = Integer.parseInt(properties[2]); } Proxies.put(new DefaultProxy(new Proxy(type, new InetSocketAddress(host, port)))); } catch (IndexOutOfBoundsException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
public Chapter createChapter(int id, String page) { Chapter chapter = new Chapter(id); chapter.setUrl(Constants.BASE_URL + getVersion() + page); String cache = getCachePath() + page; try { String html = client.requestWithCache(chapter.getUrl(), cache, client.METHOD_GET, null); Document chapterDoc = Jsoup.parse(html); // 取出内容 Elements tables = chapterDoc.select("table"); int tableIndexOfMainBody = 1; if (tables.size() == 1) { tableIndexOfMainBody = 0; } Element table = chapterDoc.select("table").get(tableIndexOfMainBody); Elements sectionElements = table.select("td[class=v]"); logger.debug(sectionElements.size()); for (Element tdIndex : sectionElements) { Element tdContent = tdIndex.nextElementSibling(); String section = tdContent.text(); logger.debug(section); chapter.addSection(section); } } catch (IOException e) { logger.error(e.getMessage()); } catch (IndexOutOfBoundsException e) { logger.error(e.getMessage()); } return chapter; }
/** * Constructs a new itinerary object with origin and destination based on flights within it. * * @param flights The list of the itineray's flights */ public Itinerary(ArrayList<Flight> flights) { try { // Create new calander for departure date time for easy calculation // of time between arrival and departure dates. GregorianCalendar temp = flights.get(0).getDepartureDateTime(); this.departureDate = new GregorianCalendar( temp.get(Calendar.YEAR), temp.get(Calendar.MONTH), temp.get(Calendar.DATE)); this.origin = flights.get(0).getOrigin(); this.destination = flights.get(flights.size() - 1).getDestination(); this.flights = flights; this.departureDateAsStr = flights.get(0).getDepartureDateTimeAsStr().split(" ")[0]; // cycle through all flights and get total cots and total // travel time without wait time for (Flight f : this.flights) { this.totalCost += f.getCost(); this.totalTravelTime += f.calculateTravelTime(); } // Calculate wait time between flights as a list of int in minutes. this.calculateWaitTime(); } catch (IndexOutOfBoundsException e) { System.out.println("Empty list of flights given " + e.getMessage()); } }
@Override public void layoutClick(LayoutClickEvent event) { final Component component = event.getComponent(); if (!(component instanceof HorizontalLayout)) { LOG.error("This listener is defined only for horizontalLayout"); return; } Component dataComponent = null; try { if ((dataComponent = ((HorizontalLayout) component).getComponent(1)) == null) { return; } this.labsPanel .getReference() .getApplication() .getMainWindow() .addWindow( new DatePickerWindow( "Add investigation duration", new DatePickerWindow.Callback() { @Override public void onDialogResult( boolean resultIsOk, final DurationBean durationBean) { if (resultIsOk && durationBean != null) { DurationSelectionLayoutListener.this.labsInvestigationAction.setDuration( durationBean); } } })); } catch (IndexOutOfBoundsException e) { LOG.error(e.getLocalizedMessage()); } }
/** * Extract a name from a Server URL by keeping the 1st part of the FQDN, between the protocol and * the first dot or the end of the URL. It is then capitalized. If an IP address is given instead, * it is used as-is. Examples: * * <ul> * <li>http://int.exoplatform.com => Int * <li>http://community.exoplatform.com => Community * <li>https://mycompany.com => Mycompany * <li>https://intranet.secure.mycompany.co.uk => Intranet * <li>http://localhost => Localhost * <li>http://192.168.1.15 => 192.168.1.15 * </ul> * * @param url the Server URL * @param defaultName a default name in case it is impossible to extract * @return a name */ public static String getAccountNameFromURL(String url, String defaultName) { String finalName = defaultName; if (url != null && !url.isEmpty()) { if (!url.startsWith("http")) url = ExoConnectionUtils.HTTP + url; try { URI theURL = new URI(url); finalName = theURL.getHost(); if (!isCorrectIPAddress(finalName)) { int firstDot = finalName.indexOf('.'); if (firstDot > 0) { finalName = finalName.substring(0, firstDot); } // else, no dot was found in the host, // return the hostname as is, e.g. localhost } // else, URL is an IP address, return it as is } catch (URISyntaxException e) { if (Log.LOGD) Log.d(ExoUtils.class.getSimpleName(), e.getMessage(), Log.getStackTraceString(e)); finalName = defaultName; } catch (IndexOutOfBoundsException e) { if (Log.LOGD) Log.d(ExoUtils.class.getSimpleName(), e.getMessage(), Log.getStackTraceString(e)); finalName = defaultName; } } return capitalize(finalName); }
public static <T extends Number> ArrayList<ArrayList<T>> solve( ArrayList<ArrayList<T>> a, ArrayList<ArrayList<T>> bVector, double eps, Class<T> type) { try { if (verifySingularity(a, eps)) { int size = a.size(); ArrayList<ArrayList<T>> solution = new ArrayList<ArrayList<T>>(); for (int i = 0; i < size; i++) { solution.add(new ArrayList<T>()); } for (int i = size - 1; i >= 0; i--) { T sum = bVector.get(i).get(0); for (int j = i + 1; j < size; j++) { T value = a.get(i).get(j); T x = solution.get(j).get(0); sum = subsElements(sum, mulElements(value, x, type), type); } solution.get(i).add(divElements(sum, a.get(i).get(i), type, eps)); } // this.checkSolution(); return solution; } else { return null; } } catch (NullPointerException e) { Logger.getGlobal().log(Level.SEVERE, "something went wrong solving the sys!"); e.printStackTrace(); return null; } catch (IndexOutOfBoundsException e) { Logger.getGlobal().log(Level.SEVERE, "check your indexes!"); e.printStackTrace(); return null; } }
public static <T extends Number> ArrayList<ArrayList<T>> subMatrixes( ArrayList<ArrayList<T>> a, ArrayList<ArrayList<T>> b, Class<T> type) { try { ArrayList<ArrayList<T>> result = new ArrayList<ArrayList<T>>(); if (a.size() != b.size() && a.get(0).size() != b.get(0).size()) { throw new IllegalArgumentException(); } for (int i = 0; i < a.size(); i++) { ArrayList<T> resultRow = new ArrayList<T>(); ArrayList<T> aRow = a.get(i); ArrayList<T> bRow = b.get(i); for (int j = 0; j < a.get(0).size(); j++) { resultRow.add(subsElements(aRow.get(j), bRow.get(j), type)); } result.add(resultRow); } return result; } catch (NullPointerException e) { Logger.getGlobal().log(Level.SEVERE, "cannot extract from null matrix!"); e.printStackTrace(); return null; } catch (IllegalArgumentException e) { Logger.getGlobal().log(Level.SEVERE, "matrixes have different sizes!"); e.printStackTrace(); return null; } catch (IndexOutOfBoundsException e) { Logger.getGlobal().log(Level.SEVERE, "check indexes!"); e.printStackTrace(); return null; } }
public InfoConf(Rider r) { super(r); try { info = r.readWord(); } catch (IndexOutOfBoundsException ioobe) { ioobe.printStackTrace(); } }
/** * Obtains the event at the specified index. * * @param index the location of the desired event in the event vector * @throws <code>ArrayIndexOutOfBoundsException</code> if the specified index is negative or not * less than the current size of this track. * @see #size */ public MidiEvent get(int index) throws ArrayIndexOutOfBoundsException { try { synchronized (eventsList) { return (MidiEvent) eventsList.get(index); } } catch (IndexOutOfBoundsException ioobe) { throw new ArrayIndexOutOfBoundsException(ioobe.getMessage()); } }
public static String idToClass(String repid) { // debug logger.finer("idToClass " + repid); if (repid.startsWith("IDL:")) { ByteString id = new ByteString(repid); try { int end = id.lastIndexOf(':'); ByteString s = end < 0 ? id.substring(4) : id.substring(4, end); ByteBuffer bb = new ByteBuffer(); // // reverse order of dot-separated name components up // till the first slash. // int firstSlash = s.indexOf('/'); if (firstSlash > 0) { ByteString prefix = s.substring(0, firstSlash); ByteString[] elems = prefix.split('.'); for (int i = elems.length - 1; i >= 0; i--) { bb.append(fixName(elems[i])); bb.append('.'); } s = s.substring(firstSlash + 1); } // // Append slash-separated name components ... // ByteString[] elems = s.split('/'); for (int i = 0; i < elems.length; i++) { bb.append(fixName(elems[i])); if (i != elems.length - 1) bb.append('.'); } String result = bb.toString(); logger.finer("idToClassName " + repid + " => " + result); return result; } catch (IndexOutOfBoundsException ex) { logger.log(Level.FINE, "idToClass " + ex.getMessage(), ex); return null; } } else if (repid.startsWith("RMI:")) { int end = repid.indexOf(':', 4); return end < 0 ? repid.substring(4) : repid.substring(4, end); } return null; }
@Override public byte byteAt(int index) { try { return buffer.get(index); } catch (ArrayIndexOutOfBoundsException e) { throw e; } catch (IndexOutOfBoundsException e) { throw new ArrayIndexOutOfBoundsException(e.getMessage()); } }
/** Removes the specific node from this tree. */ public boolean removeNode(int index) { try { remove(index); reassignIDs(index); return true; } catch (IndexOutOfBoundsException e) { e.printStackTrace(); return false; } }
/** Inserts the specific node to this tree. */ public boolean insertNode(int index, DEPNode node) { try { add(index, node); reassignIDs(index); return true; } catch (IndexOutOfBoundsException e) { e.printStackTrace(); return false; } }
@Test public void should_fail_if_index_is_out_of_bounds() { try { location.checkIndexInBounds(tabbedPane, 2); failWhenExpectingException(); } catch (IndexOutOfBoundsException e) { assertThat(e.getMessage()) .isEqualTo("Index <2> is not within the JTabbedPane bounds of <0> and <1> (inclusive)"); } }
private static void switchTo(String tabName) { try { container.setSelectedIndex(container.indexOfTab(tabName)); Tab tab = (Tab) container.getSelectedComponent(); tab.refresh(); } catch (IndexOutOfBoundsException e) { System.err.println("Tab selection index out of bound."); e.printStackTrace(); } }
/** @tests java.util.ArrayList#get(int) */ public void test_getI() { // Test for method java.lang.Object java.util.ArrayList.get(int) assertTrue("Returned incorrect element", alist.get(22) == objArray[22]); try { alist.get(8765); fail("Failed to throw expected exception for index > size"); } catch (IndexOutOfBoundsException e) { // Expected assertNotNull(e.getMessage()); } }
@Override public ByteString substring(int beginIndex, int endIndex) { try { ByteBuffer slice = slice(beginIndex, endIndex); return new NioByteString(slice); } catch (ArrayIndexOutOfBoundsException e) { throw e; } catch (IndexOutOfBoundsException e) { throw new ArrayIndexOutOfBoundsException(e.getMessage()); } }
public void set(int paramInt1, int paramInt2) { try { setSpan(getBss(), paramInt1, paramInt2, 18); setSpan(getFss(), paramInt1, paramInt2, 18); return; } catch (IndexOutOfBoundsException localIndexOutOfBoundsException) { CrDb.d( "fragment link trie malfunctioning", localIndexOutOfBoundsException.getMessage() + " @ " + this.text); } }
public void replaceItem(String newValue, int index) { toolkit.lockAWT(); try { items.set(index, newValue); updatePrefWidth(); doRepaint(); } catch (IndexOutOfBoundsException e) { throw new ArrayIndexOutOfBoundsException(e.getMessage()); } finally { toolkit.unlockAWT(); } }
protected void dispatchDraw(Canvas canvas) { try { super.dispatchDraw(canvas); return; } catch (IndexOutOfBoundsException indexoutofboundsexception) { indexoutofboundsexception.printStackTrace(); } }
/** * ½ØÈ¡Ò»¸ö×Ö·û´®ÖпªÍ·µ½Ö¸¶¨³¤¶ÈµÄ×Ö·û´® * * @param full ÍêÕûµÄ×Ö·û´® * @param end ÐÂ×Ö·û´®µÄ³¤¶È * @return */ public static String cutString(String full, int end, String endStr) { try { if (end >= full.length()) { return full; } else { return full.substring(0, end) + endStr; } } catch (IndexOutOfBoundsException e) { e.printStackTrace(); return null; } }