List of usage examples for java.util ArrayList indexOf
public int indexOf(Object o)
From source file:oscar.eform.EFormUtil.java
private static String putTemplateValues(ArrayList<String> paramNames, ArrayList<String> paramValues, String template) {// w ww . j a va 2 s.c o m if (blank(template)) return template; String tag = "$t{"; String nwTemplate = ""; int pointer = 0; ArrayList<Integer> fieldBeginList = getFieldIndices(tag, template); for (int fieldBegin : fieldBeginList) { nwTemplate += template.substring(pointer, fieldBegin); int fieldEnd = template.indexOf("}", fieldBegin); pointer = fieldEnd + 1; String field = template.substring(fieldBegin + tag.length(), fieldEnd); if (paramNames.contains(field)) { nwTemplate += paramValues.get(paramNames.indexOf(field)); } else { nwTemplate += ""; logger.debug("Cannot find input name {" + field + "} in eform"); } } nwTemplate += template.substring(pointer, template.length()); return nwTemplate; }
From source file:org.apache.hadoop.yarn.server.nodemanager.amrmproxy.BaseAMRMProxyTest.java
/** * Helper method that can be used to register multiple application masters in * parallel to the specified RM end points * /*ww w.j av a 2s . c o m*/ * @param testContexts - used to identify the requests * @return */ protected <T> List<RegisterApplicationMasterResponseInfo<T>> registerApplicationMastersInParallel( final ArrayList<T> testContexts) { List<RegisterApplicationMasterResponseInfo<T>> responses = runInParallel(testContexts, new Function<T, RegisterApplicationMasterResponseInfo<T>>() { @Override public RegisterApplicationMasterResponseInfo<T> invoke(T testContext) { RegisterApplicationMasterResponseInfo<T> response = null; try { int index = testContexts.indexOf(testContext); response = new RegisterApplicationMasterResponseInfo<T>( registerApplicationMaster(index), testContext); Assert.assertNotNull(response.getResponse()); Assert.assertEquals(Integer.toString(index), response.getResponse().getQueue()); LOG.info("Sucessfully registered application master with test context: " + testContext); } catch (Throwable ex) { response = null; LOG.error("Failed to register application master with test context: " + testContext); } return response; } }); Assert.assertEquals("Number of responses received does not match with request", testContexts.size(), responses.size()); Set<T> contextResponses = new TreeSet<T>(); for (RegisterApplicationMasterResponseInfo<T> item : responses) { contextResponses.add(item.getTestContext()); } for (T ep : testContexts) { Assert.assertTrue(contextResponses.contains(ep)); } return responses; }
From source file:org.apache.oozie.util.db.SqlStatement.java
/** * Replace the place holders with actual values in the sql statement * * @param oldVal Place holder/* ww w . j av a 2s. c o m*/ * @param newVal Actual Value * @return SQL Statement with oldVal(place holder) replaced with newVal(actual value) */ public SqlStatement setValue(Object oldVal, Object newVal) { ArrayList<Object> temp = new ArrayList<Object>(values); if (values.contains(oldVal)) { int i = temp.indexOf(oldVal); temp.set(i, newVal); } SqlStatement retVal = create(temp); return retVal; }
From source file:com.kbot2.scriptable.methods.data.Walking.java
private WalkerNode[] findPath(WalkerNode startNode, WalkerNode endNode) { try {/*from w w w . ja v a2s . c om*/ if (!loadNodes || !loadLisks) load(); ArrayList<WalkerNode> l = new ArrayList<WalkerNode>(); for (int i = 0; i < nodes.size(); i++) { WalkerNode thisNode = nodes.get(i); thisNode.distance = 999999; thisNode.previous = null; l.add(thisNode); } startNode.distance = 0; while (l.isEmpty() == false) { WalkerNode nearestNode = l.get(0); for (int i = 0; i < l.size(); i++) { WalkerNode thisNode = l.get(i); if (thisNode.distance <= nearestNode.distance) nearestNode = thisNode; } l.remove(l.indexOf(nearestNode)); if (nearestNode == endNode) l.clear(); else for (int i = 0; i < nearestNode.neighbours.size(); i++) { WalkerNode neighbourNode = nearestNode.neighbours.get(i); int alt = nearestNode.distance + nearestNode.distance(neighbourNode); if (alt < neighbourNode.distance) { neighbourNode.distance = alt; neighbourNode.previous = nearestNode; } } } ArrayList<WalkerNode> nodePath = new ArrayList<WalkerNode>(); nodePath.add(endNode); WalkerNode previousNode = endNode.previous; while (previousNode != null) { nodePath.add(previousNode); previousNode = previousNode.previous; } if (nodePath.size() == 1) return null; WalkerNode[] nodeArray = new WalkerNode[nodePath.size()]; for (int i = nodePath.size() - 1; i >= 0; i--) nodeArray[nodePath.size() - i - 1] = nodePath.get(i); return nodeArray; } catch (Exception e) { } return null; }
From source file:org.apache.sysml.runtime.io.ReaderTextCSVParallel.java
private MatrixBlock computeCSVSizeAndCreateOutputMatrixBlock(InputSplit[] splits, Path path, JobConf job, boolean hasHeader, String delim, long estnnz) throws IOException, DMLRuntimeException { int nrow = 0; int ncol = 0; FileInputFormat.addInputPath(job, path); TextInputFormat informat = new TextInputFormat(); informat.configure(job);//from www.ja v a 2 s .c om // count no of entities in the first non-header row LongWritable key = new LongWritable(); Text oneLine = new Text(); RecordReader<LongWritable, Text> reader = informat.getRecordReader(splits[0], job, Reporter.NULL); try { if (reader.next(key, oneLine)) { String cellStr = oneLine.toString().trim(); ncol = StringUtils.countMatches(cellStr, delim) + 1; } } finally { IOUtilFunctions.closeSilently(reader); } // count rows in parallel per split try { ExecutorService pool = Executors.newFixedThreadPool(_numThreads); ArrayList<CountRowsTask> tasks = new ArrayList<CountRowsTask>(); for (InputSplit split : splits) { tasks.add(new CountRowsTask(split, informat, job, hasHeader)); hasHeader = false; } pool.invokeAll(tasks); pool.shutdown(); // collect row counts for offset computation // early error notify in case not all tasks successful _offsets = new SplitOffsetInfos(tasks.size()); for (CountRowsTask rt : tasks) { if (!rt.getReturnCode()) throw new IOException("Count task for csv input failed: " + rt.getErrMsg()); _offsets.setOffsetPerSplit(tasks.indexOf(rt), nrow); _offsets.setLenghtPerSplit(tasks.indexOf(rt), rt.getRowCount()); nrow = nrow + rt.getRowCount(); } } catch (Exception e) { throw new IOException("Threadpool Error " + e.getMessage(), e); } // allocate target matrix block based on given size; // need to allocate sparse as well since lock-free insert into target return createOutputMatrixBlock(nrow, ncol, nrow, ncol, estnnz, true, true); }
From source file:org.openmrs.module.emrapi.adt.AdtServiceImpl.java
public boolean areConsecutiveVisits(List<Integer> visits, Patient patient) { if (patient != null && visits != null && (visits.size() > 0)) { List<Visit> patientVisits = visitService.getVisitsByPatient(patient, true, false); if ((patientVisits != null) && (patientVisits.size() > 0)) { ArrayList<Integer> allVisits = new ArrayList<Integer>(); int j = 0; for (Visit visit : patientVisits) { allVisits.add(j++, visit.getId()); }/*from w w w . ja va2s .c om*/ if (allVisits.containsAll(visits)) { //find the index of the first candidate for a consecutive visit int i = allVisits.indexOf(visits.get(0)); //make sure there are still more elements in the list than the the number of candidate consecutives if ((allVisits.size() - i) >= visits.size()) { for (Integer candidateVisit : visits) { if (allVisits.get(i).compareTo(candidateVisit) == 0) { i++; } else { return false; } } return true; } } } } return false; }
From source file:org.apache.hadoop.yarn.server.nodemanager.amrmproxy.BaseAMRMProxyTest.java
protected <T> List<FinishApplicationMasterResponseInfo<T>> finishApplicationMastersInParallel( final ArrayList<T> testContexts) { List<FinishApplicationMasterResponseInfo<T>> responses = runInParallel(testContexts, new Function<T, FinishApplicationMasterResponseInfo<T>>() { @Override/*from ww w . j a va 2 s. c o m*/ public FinishApplicationMasterResponseInfo<T> invoke(T testContext) { FinishApplicationMasterResponseInfo<T> response = null; try { response = new FinishApplicationMasterResponseInfo<T>( finishApplicationMaster(testContexts.indexOf(testContext), FinalApplicationStatus.SUCCEEDED), testContext); Assert.assertNotNull(response.getResponse()); LOG.info("Sucessfully finished application master with test contexts: " + testContext); } catch (Throwable ex) { response = null; LOG.error("Failed to finish application master with test context: " + testContext); } return response; } }); Assert.assertEquals("Number of responses received does not match with request", testContexts.size(), responses.size()); Set<T> contextResponses = new TreeSet<T>(); for (FinishApplicationMasterResponseInfo<T> item : responses) { Assert.assertNotNull(item); Assert.assertNotNull(item.getResponse()); contextResponses.add(item.getTestContext()); } for (T ep : testContexts) { Assert.assertTrue(contextResponses.contains(ep)); } return responses; }
From source file:com.ibm.bi.dml.runtime.io.ReaderTextCSVParallel.java
/** * //from w ww . ja va2 s . c o m * @param path * @param job * @param hasHeader * @param delim * @return * @throws IOException * @throws DMLRuntimeException */ private MatrixBlock computeCSVSizeAndCreateOutputMatrixBlock(InputSplit[] splits, Path path, JobConf job, boolean hasHeader, String delim, long estnnz) throws IOException, DMLRuntimeException { int nrow = 0; int ncol = 0; FileInputFormat.addInputPath(job, path); TextInputFormat informat = new TextInputFormat(); informat.configure(job); // count no of entities in the first non-header row LongWritable key = new LongWritable(); Text oneLine = new Text(); RecordReader<LongWritable, Text> reader = informat.getRecordReader(splits[0], job, Reporter.NULL); try { if (reader.next(key, oneLine)) { String cellStr = oneLine.toString().trim(); ncol = StringUtils.countMatches(cellStr, delim) + 1; } } finally { IOUtilFunctions.closeSilently(reader); } // count rows in parallel per split try { ExecutorService pool = Executors.newFixedThreadPool(_numThreads); ArrayList<CountRowsTask> tasks = new ArrayList<CountRowsTask>(); for (InputSplit split : splits) { tasks.add(new CountRowsTask(split, informat, job, hasHeader)); hasHeader = false; } pool.invokeAll(tasks); pool.shutdown(); // collect row counts for offset computation // early error notify in case not all tasks successful _offsets = new SplitOffsetInfos(tasks.size()); for (CountRowsTask rt : tasks) { if (!rt.getReturnCode()) throw new IOException("Count task for csv input failed: " + rt.getErrMsg()); _offsets.setOffsetPerSplit(tasks.indexOf(rt), nrow); _offsets.setLenghtPerSplit(tasks.indexOf(rt), rt.getRowCount()); nrow = nrow + rt.getRowCount(); } } catch (Exception e) { throw new IOException("Threadpool Error " + e.getMessage(), e); } // allocate target matrix block based on given size; // need to allocate sparse as well since lock-free insert into target return createOutputMatrixBlock(nrow, ncol, estnnz, true, true); }
From source file:com.stefensharkey.entityedit.command.CommandEnchant.java
@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { Player player = (Player) sender;//from w ww. j av a2 s .c o m LivingEntity entity = Utils.getEntityInCrosshairs(player); ArrayList<String> argsList = new ArrayList<>(); for (String arg : args) { argsList.add(arg.toUpperCase()); } if (entity != null) { if (args.length < 3) { sender.sendMessage(ChatColor.RED + "At least one enchantment is required."); return false; } else { if (argsList.contains("-h") || argsList.contains("-c") || argsList.contains("-l") || argsList.contains("-b")) { if (argsList.contains("-h")) { ArrayList<String> helmEnchants; String helmArgs = StringUtils.join(argsList, " "); helmEnchants = new ArrayList<>(Arrays.asList(helmArgs .substring(helmArgs.indexOf("-h", helmArgs.indexOf("-", helmArgs.indexOf("-h")))) .split(" "))); if (argsList.size() > argsList.indexOf("-h") + 1) { Map<Enchantment, Integer> enchantMap = new HashMap<>(); for (String enchant : helmEnchants) { enchantMap.put(Enchantment.getByName(enchant), 1); } entity.getEquipment().getHelmet().addEnchantments(enchantMap); } else { if (entity.getEquipment().getHelmet().hasItemMeta()) { entity.getEquipment().getHelmet().getEnchantments().clear(); } } } if (argsList.contains("-c")) { ArrayList<String> chestplateEnchantments; String chestplateArgs = StringUtils.join(argsList, " "); chestplateEnchantments = new ArrayList<>( Arrays.asList(chestplateArgs .substring(chestplateArgs.indexOf("-c", chestplateArgs.indexOf("-", chestplateArgs.indexOf("-c")))) .split(" "))); if (argsList.size() > argsList.indexOf("-c") + 1) { Map<Enchantment, Integer> enchantMap = new HashMap<>(); for (String enchant : chestplateEnchantments) { enchantMap.put(Enchantment.getByName(enchant), 1); } entity.getEquipment().getChestplate().addEnchantments(enchantMap); } else { if (entity.getEquipment().getChestplate().hasItemMeta()) { entity.getEquipment().getChestplate().getEnchantments().clear(); } } } if (argsList.contains("-l")) { ArrayList<String> leggingEnchantments; String leggingArgs = StringUtils.join(argsList, " "); leggingEnchantments = new ArrayList<>( Arrays.asList( leggingArgs .substring(leggingArgs.indexOf("-l", leggingArgs.indexOf("-", leggingArgs.indexOf("-l")))) .split(" "))); if (argsList.size() > argsList.indexOf("-l") + 1) { Map<Enchantment, Integer> enchantMap = new HashMap<>(); for (String enchant : leggingEnchantments) { enchantMap.put(Enchantment.getByName(enchant), 1); } entity.getEquipment().getLeggings().addEnchantments(enchantMap); } else { if (entity.getEquipment().getLeggings().hasItemMeta()) { entity.getEquipment().getLeggings().getEnchantments().clear(); } } } if (argsList.contains("-b")) { ArrayList<String> bootEnchantments; String bootArgs = StringUtils.join(argsList, " "); bootEnchantments = new ArrayList<>(Arrays.asList(bootArgs .substring(bootArgs.indexOf("-b", bootArgs.indexOf("-", bootArgs.indexOf("-b")))) .split(" "))); if (argsList.size() > argsList.indexOf("-b") + 1) { Map<Enchantment, Integer> enchantMap = new HashMap<>(); for (String enchant : bootEnchantments) { enchantMap.put(Enchantment.getByName(enchant), 1); } entity.getEquipment().getBoots().addEnchantments(enchantMap); } else { if (entity.getEquipment().getBoots().hasItemMeta()) { entity.getEquipment().getBoots().getEnchantments().clear(); } } } return true; } sender.sendMessage(ChatColor.RED + "Syntax error."); sender.sendMessage(ChatColor.RED + "/entityedit enchant <[-clear] [-h [enchantments]] [-c [enchantments]] [-l [enchantments]] [-b [enchantments]]>"); return false; } } sender.sendMessage(ChatColor.RED + "No entities found."); return true; }
From source file:tdunnick.jphineas.console.queue.Charts.java
/** * Sort and setup chart data by "constraint" * //w w w .j a v a2 s . c o m * @param r list of constraint, time pairs * @param ends ending date for list * @param days covered by list * @return bar chart data */ private CategoryDataset createBarChartDataset(ArrayList<String[]> r, long ends, long days) { ArrayList<String> constraints = new ArrayList<String>(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // first time through just collect the constraint names for (int i = 0; i < r.size(); i++) { String[] item = r.get(i); String k = item[0]; if (!constraints.contains(k)) constraints.add(k); } long interval = days * MS; long start = ends - interval; interval /= 5; int[] counts = new int[constraints.size()]; for (int i = 0; i < constraints.size(); i++) counts[i] = 0; for (int i = 0; i < r.size(); i++) { String[] item = r.get(i); long d = Long.parseLong(item[1]); if (d > start) { addBarData(dataset, constraints, start, counts); start += interval; } counts[constraints.indexOf(item[0])]++; } addBarData(dataset, constraints, start, counts); while ((start += interval) < ends) addBarData(dataset, constraints, start, counts); return dataset; }