List of usage examples for java.util ArrayList contains
public boolean contains(Object o)
From source file:com.ibm.bi.dml.test.utils.TestUtils.java
/** * <p>//from www.java2 s . c om * Compares to arrays for equality. The elements in the array can be in * different order. * </p> * * @param expecteds * expected values * @param actuals * actual values */ public static void assertInterchangedArraysEquals(String[] expecteds, String[] actuals) { assertEquals("different number of elements in arrays", expecteds.length, actuals.length); ArrayList<Integer> foundIndexes = new ArrayList<Integer>(); expactation: for (int i = 0; i < expecteds.length; i++) { for (int j = 0; j < actuals.length; j++) { if (expecteds[i] == actuals[j] && !foundIndexes.contains(Integer.valueOf(j))) { foundIndexes.add(Integer.valueOf(j)); continue expactation; } } fail("Missing element " + expecteds[i]); } }
From source file:com.ibm.bi.dml.test.utils.TestUtils.java
/** * <p>// w ww .ja v a2 s . c o m * Compares to arrays for equality. The elements in the array can be in * different order. * </p> * * @param expecteds * expected values * @param actuals * actual values */ public static void assertInterchangedArraysEquals(int[] expecteds, int[] actuals) { assertEquals("different number of elements in arrays", expecteds.length, actuals.length); ArrayList<Integer> foundIndexes = new ArrayList<Integer>(); expactation: for (int i = 0; i < expecteds.length; i++) { for (int j = 0; j < actuals.length; j++) { if (expecteds[i] == actuals[j] && !foundIndexes.contains(Integer.valueOf(j))) { foundIndexes.add(Integer.valueOf(j)); continue expactation; } } fail("Missing element " + expecteds[i]); } }
From source file:com.ibm.bi.dml.test.utils.TestUtils.java
/** * <p>/* w w w .j a v a 2 s .co m*/ * Compares to arrays for equality. The elements in the array can be in * different order. * </p> * * @param expecteds * expected values * @param actuals * actual values */ public static void assertInterchangedArraysEquals(double[] expecteds, double[] actuals) { assertEquals("different number of elements in arrays", expecteds.length, actuals.length); ArrayList<Integer> foundIndexes = new ArrayList<Integer>(); expactation: for (int i = 0; i < expecteds.length; i++) { for (int j = 0; j < actuals.length; j++) { if (expecteds[i] == actuals[j] && !foundIndexes.contains(Integer.valueOf(j))) { foundIndexes.add(Integer.valueOf(j)); continue expactation; } } fail("Missing element " + expecteds[i]); } }
From source file:net.smart_json_database.JSONDatabase.java
private void getTagsForJSONEntity(JSONEntity entity, SQLiteDatabase db) { ArrayList<String> names = new ArrayList<String>(); String sql = "SELECT * FROM " + TABLE_REL_TAG_JSON_DATA + " WHERE to_id = ?"; Cursor c = db.rawQuery(sql, new String[] { "" + entity.getUid() }); if (c.getCount() > 0) { String name = ""; c.moveToFirst();//ww w . j a v a 2 s . co m int col_from_id = c.getColumnIndex("from_id"); do { name = invertedTags.get(new Integer(c.getInt(col_from_id))); if (name == null) { continue; } if (names.contains(name)) { continue; } names.add(name); } while (c.moveToNext()); } c.close(); if (names.size() > 0) { TagRelation relation = new TagRelation(); relation.init(names); entity.setTags(relation); } }
From source file:com.l2jfree.gameserver.geodata.pathfinding.PathFinding.java
public final Node[] searchByClosest2(Node start, Node end, int instanceId) { // Always continues checking from the closest to target non-blocked // node from to_visit list. There's extra length in path if needed // to go backwards/sideways but when moving generally forwards, this is extra fast // and accurate. And can reach insane distances (try it with 800 nodes..). // Minimum required node count would be around 300-400. // Generally returns a bit (only a bit) more intelligent looking routes than // the basic version. Not a true distance image (which would increase CPU // load) level of intelligence though. // List of Visited Nodes L2FastSet<Node> visited = L2Collections.newL2FastSet(); // List of Nodes to Visit ArrayList<Node> to_visit = L2Collections.newArrayList(); to_visit.add(start);/*www.j av a2 s .com*/ try { int targetx = end.getNodeX(); int targety = end.getNodeY(); int dx, dy; boolean added; int i = 0; while (i < 550) { if (to_visit.isEmpty()) { // No Path found return null; } Node node = to_visit.remove(0); if (node.equals(end)) //path found! return constructPath2(node); else { i++; visited.add(node); node.attachNeighbors(instanceId); Node[] neighbors = node.getNeighbors(); if (neighbors == null) continue; for (Node n : neighbors) { if (!visited.contains(n) && !to_visit.contains(n)) { added = false; n.setParent(node); dx = targetx - n.getNodeX(); dy = targety - n.getNodeY(); n.setCost(dx * dx + dy * dy); for (int index = 0; index < to_visit.size(); index++) { // supposed to find it quite early.. if (to_visit.get(index).getCost() > n.getCost()) { to_visit.add(index, n); added = true; break; } } if (!added) to_visit.add(n); } } } } //No Path found return null; } finally { L2Collections.recycle(visited); L2Collections.recycle(to_visit); } }
From source file:com.piusvelte.hydra.UnidataConnection.java
private String getRecordID(String object, String[] columns, String[] values) throws Exception { String recordID = null;//from ww w. j ava2s . co m for (int c = 0; (c < columns.length) && (c < values.length); c++) { if (("@ID").equals(columns[c])) { recordID = values[c]; break; } } ArrayList<String> keyNames = new ArrayList<String>(); if (recordID == null) { // @ID wasn't sent, look for the Colleague I-descriptors ArrayList<Integer> keyLocs = new ArrayList<Integer>(); UniCommand uCommand = mSession.command(); uCommand.setCommand(String.format(SELECTION_QUERY_FORMAT, "DICT " + object, "SELECT DICT STUDENT.TERMS WITH LOC LIKE 'FIELD(@ID,...*...'").toString()); UniSelectList uSelect = mSession.selectList(0); uCommand.exec(); UniDictionary dict = mSession.openDict(object); UniString fieldID = null; Pattern keyPattern = Pattern.compile("^FIELD\\(@ID,\"\\*\",\\d+\\)"); try { while ((fieldID = uSelect.next()).length() > 0) { dict.setRecordID(fieldID); String loc = dict.getLoc().toString(); if (keyPattern.matcher(loc).matches()) { int keyLoc = Integer.parseInt(loc.substring(14, loc.length() - 1)); if (!keyLocs.contains(keyLoc)) { keyLocs.add(keyLoc); keyNames.add(fieldID.toString()); } } } } catch (NumberFormatException e) { e.printStackTrace(); } catch (UniSelectListException e) { e.printStackTrace(); } catch (UniFileException e) { e.printStackTrace(); } dict.close(); int s = keyNames.size(); if (s > 0) { // check if the keys are defined String[] keyParts = new String[s]; int partsFound = 0; for (int k = 0; k < s; k++) { for (int c = 0; (c < columns.length) && (c < values.length); c++) { if (keyNames.get(k).equals(columns[c])) { keyParts[keyLocs.get(k)] = values[c]; partsFound++; break; } } } if (partsFound < s) throw new Exception("key not defined"); else { recordID = ""; for (int k = 0; k < s; k++) recordID += keyParts[k]; } } } return recordID; }
From source file:com.mythesis.userbehaviouranalysis.ProfileAnalysis.java
/** * a method that returns a number of random urls * @param path SWebRank output directory * @param numOfQueries the number of queries * @param numOfpages the number of urls per query * @return a list of urls/*from w w w. ja va2 s.com*/ */ private ArrayList<String> getSuggestions(String path, int numOfQueries, int numOfpages, String[] history) { List<String> historyUrls = Arrays.asList(history); ArrayList<String> randomQueries = getQueries(path, numOfQueries); //for each query select a number of random urls //for now it only works for bing search engine ArrayList<String> suggestions = new ArrayList<>(); for (String s : randomQueries) { File level = new File(s + "\\" + "bing" + "\\"); File[] docPaths = level.listFiles(); List<String> urls = new ArrayList<>(); for (File f : docPaths) { String str = f.getAbsolutePath(); if (StringUtils.isNumeric(str.substring(str.lastIndexOf("\\") + 1))) { File webPagePath = new File(str + "\\current_url.txt"); try { String url = FileUtils.readFileToString(webPagePath); urls.add(url); } catch (IOException ex) { Logger.getLogger(ProfileAnalysis.class.getName()).log(Level.SEVERE, null, ex); } } } if (numOfpages > urls.size()) { for (String ur : urls) { if (!suggestions.contains(ur) && !historyUrls.contains(ur)) suggestions.add(ur); } continue; } int totalUrls = urls.size() - 1; Random randomPage = new Random(); int count = 0; while (count < numOfpages) { String val = urls.get(randomPage.nextInt(totalUrls)); if (!suggestions.contains(val) && !historyUrls.contains(val)) { suggestions.add(val); count++; } } } return suggestions; }
From source file:com.moscona.dataSpace.persistence.DirectoryDataStore.java
private void dumpSummary(DataFrame element, PrintStream out, HashSet<IDataElement> visited) throws DataSpaceException { Set<String> columns = element.getColumnNames(); ArrayList<String> labels = new ArrayList<String>(); ArrayList<String> factors = new ArrayList<String>(); ArrayList<String> others = new ArrayList<String>(); String id = element.getRowId(); if (id != null) { out.println(" ID column: " + id); factors.add(id);//w ww .j av a 2s . c o m } for (String col : columns) { IVector c = element.get(col); visited.add(c); if (element.isLabel(col)) { labels.add(col); } else if (c.isFactor() && !factors.contains(col)) { factors.add(col); } else { others.add(col); } } Collections.sort(labels); Collections.sort(factors); Collections.sort(others); out.println(" columns:"); for (String col : factors) { IVector vector = element.get(col); String description = vector.getDescription(); out.println(" " + col + " " + (vector.isSorted() ? "(factor, sorted)" : "(factor)") + (description == null ? "" : ": " + description)); } for (String col : others) { IVector vector = element.get(col); String description = vector.getDescription(); out.println(" " + col + " " + (vector.isSorted() ? "(sorted)" : "") + (description == null ? "" : ": " + description)); } for (String col : labels) { IVector c = element.get(col); String description = c.getDescription(); out.println(" " + col + " (label" + (c.isFactor() ? ", factor" : "") + (c.isSorted() ? ", sorted)" : ")") + (description == null ? "" : ": " + description)); } ArrayList<String> order = new ArrayList<String>(factors); order.addAll(others); order.addAll(labels); out.println(); out.println(" data frame column details:"); for (String col : order) { AbstractVector vector = (AbstractVector) element.get(col); String description = vector.getDescription(); out.println(); out.println(" " + col + (description == null ? "" : ": " + description)); dumpSummary(vector, out, " "); } }
From source file:com.mobiperf.speedometer.measurements.PingTask.java
private MeasurementResult executePingCmdTask() throws MeasurementError { Logger.i("Starting executePingCmdTask"); PingDesc pingTask = (PingDesc) this.measurementDesc; String errorMsg = ""; MeasurementResult measurementResult = null; // TODO(Wenjie): Add a exhaustive list of ping locations for different // Android phones pingTask.pingExe = parent.getString(R.string.ping_executable); try {/* ww w . j a v a2s .co m*/ String command = Util.constructCommand(pingTask.pingExe, "-i", Config.DEFAULT_INTERVAL_BETWEEN_ICMP_PACKET_SEC, "-s", pingTask.packetSizeByte, "-w", pingTask.pingTimeoutSec, "-c", Config.PING_COUNT_PER_MEASUREMENT, targetIp); Logger.i("Running: " + command); command = "/system/bin/getevent"; Logger.i("Running: " + command); pingProc = Runtime.getRuntime().exec(command); // Grab the output of the process that runs the ping command InputStream is = pingProc.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = null; int lineCnt = 0; ArrayList<Double> rrts = new ArrayList<Double>(); ArrayList<Integer> receivedIcmpSeq = new ArrayList<Integer>(); double packetLoss = Double.MIN_VALUE; int packetsSent = Config.PING_COUNT_PER_MEASUREMENT; // Process each line of the ping output and store the rrt in array // rrts. while ((line = br.readLine()) != null) { // Ping prints a number of 'param=value' pairs, among which we // only need the // 'time=rrt_val' pair String[] extractedValues = Util.extractInfoFromPingOutput(line); if (extractedValues != null) { int curIcmpSeq = Integer.parseInt(extractedValues[0]); double rrtVal = Double.parseDouble(extractedValues[1]); // ICMP responses from the system ping command could be // duplicate and out of order if (!receivedIcmpSeq.contains(curIcmpSeq)) { rrts.add(rrtVal); receivedIcmpSeq.add(curIcmpSeq); } } this.progress = 100 * ++lineCnt / Config.PING_COUNT_PER_MEASUREMENT; this.progress = Math.min(Config.MAX_PROGRESS_BAR_VALUE, progress); broadcastProgressForUser(progress); // Get the number of sent/received pings from the ping command // output int[] packetLossInfo = Util.extractPacketLossInfoFromPingOutput(line); if (packetLossInfo != null) { packetsSent = packetLossInfo[0]; int packetsReceived = packetLossInfo[1]; packetLoss = 1 - ((double) packetsReceived / (double) packetsSent); } Logger.i(line); } // Use the output from the ping command to compute packet loss. If // that's not // available, use an estimation. if (packetLoss == Double.MIN_VALUE) { packetLoss = 1 - ((double) rrts.size() / (double) Config.PING_COUNT_PER_MEASUREMENT); } measurementResult = constructResult(rrts, packetLoss, packetsSent); Logger.i(MeasurementJsonConvertor.toJsonString(measurementResult)); } catch (IOException e) { Logger.e(e.getMessage()); errorMsg += e.getMessage() + "\n"; } catch (SecurityException e) { Logger.e(e.getMessage()); errorMsg += e.getMessage() + "\n"; } catch (NumberFormatException e) { Logger.e(e.getMessage()); errorMsg += e.getMessage() + "\n"; } catch (InvalidParameterException e) { Logger.e(e.getMessage()); errorMsg += e.getMessage() + "\n"; } finally { // All associated streams with the process will be closed upon // destroy() cleanUp(pingProc); } if (measurementResult == null) { Logger.e("Error running ping: " + errorMsg); throw new MeasurementError(errorMsg); } return measurementResult; }