List of usage examples for java.util ArrayList contains
public boolean contains(Object o)
From source file:com.activecq.api.ActiveProperties.java
/** * Uses reflection to create a List of the keys defined in the ActiveField subclass (and its inheritance tree). * Only fields that meet the following criteria are returned: * - public/*from w w w . j a v a 2 s .com*/ * - static * - final * - String * - Upper case * @return a List of all the Fields */ @SuppressWarnings("unchecked") public List<String> getKeys() { ArrayList<String> keys = new ArrayList<String>(); ArrayList<String> names = new ArrayList<String>(); Class cls = this.getClass(); if (cls == null) { return Collections.unmodifiableList(keys); } Field fieldList[] = cls.getFields(); for (Field fld : fieldList) { int mod = fld.getModifiers(); // Only look at public static final fields if (!Modifier.isPublic(mod) || !Modifier.isStatic(mod) || !Modifier.isFinal(mod)) { continue; } // Only look at String fields if (!String.class.equals(fld.getType())) { continue; } // Only look at uppercase fields if (!StringUtils.equals(fld.getName().toUpperCase(), fld.getName())) { continue; } // Get the value of the field String value; try { value = StringUtils.stripToNull((String) fld.get(this)); } catch (IllegalArgumentException e) { continue; } catch (IllegalAccessException e) { continue; } // Do not add duplicate or null keys, or previously added named fields if (value == null || names.contains(fld.getName()) || keys.contains(value)) { continue; } // Success! Add key to key list keys.add(value); // Add field named to process field names list names.add(fld.getName()); } return Collections.unmodifiableList(keys); }
From source file:edu.illinois.enforcemop.examples.apache.collections.TestBlockingBuffer.java
/** * Tests interrupted {@link BlockingBuffer#get()}. *//*from www .j av a 2 s . co m*/ @Test // @Schedules({ // @Schedule(name = "InterruptedGet", sequence = "[beforeGet:afterGet]@readThread->beforeInterrupt@main," + // "finishAddException@readThread->afterInterrupt@main") }) public void testInterruptedGet() throws InterruptedException { Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer()); Object obj = new Object(); // spawn a read thread to wait on the empty buffer ArrayList exceptionList = new ArrayList(); Thread thread = new ReadThread(blockingBuffer, obj, exceptionList, "InterruptedGet", "readThread"); thread.start(); try { Thread.sleep(100); //INS-SLEEP } catch (Exception e1) { e1.printStackTrace(); } // Interrupting the thread should cause it to throw BufferUnderflowException /* @Event("beforeInterrupt")*/ thread.interrupt(); // Chill, so thread can throw and add message to exceptionList Thread.sleep(100); /* @Event("afterInterrupt")*/ assertTrue("InterruptedGet", exceptionList.contains("BufferUnderFlow")); // assertFalse("InterruptedGet", thread.isAlive()); // if( thread.isAlive() ) { // fail( "Read thread has hung." ); // } }
From source file:com.jaspersoft.jasperserver.api.engine.scheduling.ReportSchedulingFacade.java
private void foundInvalidID(List<ReportJobIdHolder> expectedIDs, List<ReportJob> actualIDs) throws ReportJobNotFoundException { if (actualIDs == null) throw new ReportJobNotFoundException(expectedIDs.get(0).getId()); ArrayList<Long> foundIDList = new ArrayList<Long>(); for (ReportJob actualIDJob : actualIDs) foundIDList.add(actualIDJob.getId()); for (ReportJobIdHolder expectedID : expectedIDs) { long id = expectedID.getId(); if (!foundIDList.contains(id)) throw new ReportJobNotFoundException(id); }/*w w w.j a v a 2s .c o m*/ }
From source file:ddf.test.itests.catalog.TestFederation.java
@Test public void testCatalogEndpointExposure() throws InvalidSyntaxException { // Check the service references ArrayList<String> expectedEndpoints = new ArrayList<>(); expectedEndpoints.add("openSearchUrl"); expectedEndpoints.add("cswUrl"); CatalogEndpoint endpoint = getServiceManager().getService(CatalogEndpoint.class); String urlBindingName = endpoint.getEndpointProperties().get(CatalogEndpointImpl.URL_BINDING_NAME_KEY); assertTrue("Catalog endpoint url binding name: '" + urlBindingName + "' is expected.", expectedEndpoints.contains(urlBindingName)); }
From source file:com.xpn.xwiki.plugin.collection.CollectionPlugin.java
/** * Retrieves the breadcrumb path for a document first by looking at the request.bc param then by looking up parents * * @param docName page from which to start the breadcrumb * @param context XWiki Context/*from ww w . j a v a 2 s . c om*/ */ public List<String> getBreadcrumb(String docName, XWikiContext context) { String bcParam = context.getRequest().get("bc"); ArrayList<String> pageList = new ArrayList<String>(); String lastPage = docName; if (bcParam != null) { // adding String[] pages = StringUtils.split(bcParam, ";"); for (int i = pages.length - 1; i >= 0; i--) { String page = pages[i]; if ((i != pages.length - 1) || !docName.equals(page)) { if (!page.equals("") && !pageList.contains(page) && !page.equals("XWiki.XWikiGuest") && !page.equals("XWiki.XWikiUsers")) { pageList.add(page); lastPage = page; } } } } // now continue the BC from the last page using the parent information return getBreadcrumbFromParents(lastPage, pageList, context); }
From source file:com.mobiperf.measurements.PingTask.java
private MeasurementResult executePingCmdTask(int ipByteLen) 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 = Util.pingExecutableBasedOnIPType(ipByteLen, parent); Logger.i("Ping executable is " + pingTask.pingExe); if (pingTask.pingExe == null) { Logger.e("Ping executable not found"); throw new MeasurementError("Ping executable not found"); }//from w w w . j av a2 s . c o m try { 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); pingProc = Runtime.getRuntime().exec(command); dataConsumed += pingTask.packetSizeByte * Config.PING_COUNT_PER_MEASUREMENT * 2; // 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, PING_METHOD_CMD); } 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; }
From source file:com.l2jfrozen.gameserver.geo.pathfinding.PathFinding.java
public final Node[] searchByClosest2(final Node start, final Node end) { // 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 final L2FastSet<Node> visited = L2Collections.newL2FastSet(); // List of Nodes to Visit final ArrayList<Node> to_visit = L2Collections.newArrayList(); to_visit.add(start);//ww w . j a v a 2 s . c om try { final int targetx = end.getNodeX(); final int targety = end.getNodeY(); int dx, dy; boolean added; int i = 0; while (i < 550) { if (to_visit.isEmpty()) { // No Path found return null; } final Node node = to_visit.remove(0); if (node.equals(end)) // path found! { return constructPath2(node); } i++; visited.add(node); node.attachNeighbors(); final Node[] neighbors = node.getNeighbors(); if (neighbors == null) continue; for (final 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:za.org.opengov.stockout.service.medical.impl.ProductServiceImpl.java
@Override public void populateDatabaseFromCSV(File file, String seperator, String textDelimeter) { CSVParser parser;//from w ww .ja va 2 s . c om try { parser = new CSVParser(new FileInputStream(file), seperator, textDelimeter); for (List<String> row : parser.getRows()) { String medicineName = row.get(0); String dosage = row.get(1); String fullName = row.get(8); // add the medicine if it isn't in the DB already Medicine m = medicineService.findByName(medicineName); if (m == null) { m = new Medicine(); m.setName(medicineName.trim().toUpperCase()); medicineService.put(m); } ArrayList<String> terminateWords = new ArrayList<String>(); terminateWords.add("TAB"); terminateWords.add("SOL"); terminateWords.add("ORAL"); terminateWords.add("CAP"); terminateWords.add("INJ"); terminateWords.add("SUS"); terminateWords.add("POW"); terminateWords.add("PAED"); terminateWords.add("CSV"); String productName = ""; String suffix = ""; boolean appendToName = true; // split full name into product name and description String[] tokens = fullName.split(" "); for (int i = 0; i < tokens.length; i++) { if (!tokens[i].isEmpty()) { if (!appendToName) { suffix += tokens[i] + " "; } else { // inspect token to see if it terminates the product // name if (Character.isDigit(tokens[i].charAt(0)) || terminateWords.contains(tokens[i])) { appendToName = false; suffix += tokens[i] + " "; continue; } productName += tokens[i] + " "; } } } productName = productName.trim(); suffix = suffix.trim(); Product p = new Product(); p.setUid(generateProductCode(fullName)); p.setMedicine(m); p.setName(productName); p.setDescription(suffix); put(p); } } catch (FileNotFoundException e) { System.err.println("Could not load CSV file: " + file.getPath()); } }
From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_demand.java
@Override public ArrayList<String> getAttributesColumnsHeaders() { ArrayList<String> attColumnsHeaders = new ArrayList<>(); currentTopology = callback.getDesign(); for (Demand demand : getVisibleElementsInTable()) for (Map.Entry<String, String> entry : demand.getAttributes().entrySet()) if (attColumnsHeaders.contains(entry.getKey()) == false) attColumnsHeaders.add(entry.getKey()); return attColumnsHeaders; }