List of usage examples for java.util ArrayList iterator
public Iterator<E> iterator()
From source file:com.wentam.defcol.connect_to_computer.HomeCommandHandler.java
@Override public void handle(final HttpRequest request, final HttpResponse response, HttpContext httpContext) throws HttpException, IOException { HttpEntity entity = new EntityTemplate(new ContentProducer() { public void writeTo(final OutputStream outstream) throws IOException { OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8"); String req = request.getRequestLine().getUri(); req = req.replaceAll("/\\?", ""); String[] pairs = req.split("&"); HashMap data = new HashMap(); for (int i = 0; i < pairs.length; i++) { if (pairs[i].contains("=")) { String[] pair = pairs[i].split("="); data.put(pair[0], pair[1]); }/*from w ww .java 2 s .com*/ } String action = "none"; if (data.containsKey("action")) { action = (String) data.get("action"); } String resp = "404 on " + action; if (action.equals("none") || action.equals("home")) { response.setHeader("Content-Type", "text/html"); resp = getHtml(); } else if (action.equals("getPalettes")) { response.setHeader("Content-Type", "application/json"); JSONArray json = new JSONArray(); int tmp[] = { 0 }; ArrayList<String> palettes = pFile.getRows(tmp); Iterator i = palettes.iterator(); while (i.hasNext()) { JSONObject item = new JSONObject(); try { item.put("name", i.next()); } catch (JSONException e) { } json.put(item); } resp = json.toString(); } else if (action.equals("getJquery")) { response.setHeader("Content-Type", "application/javascript"); resp = jquery; } else if (action.equals("getJs")) { response.setHeader("Content-Type", "application/javascript"); resp = getJs(); } else if (action.equals("getPaletteColors")) { response.setHeader("Content-Type", "application/javascript"); int id = Integer.parseInt((String) data.get("id")); int tmp[] = { 1 }; String row = pFile.getRow(id, tmp); String colors[] = row.split("\\."); JSONArray json = new JSONArray(); for (int i = 0; i < colors.length; i++) { json.put(colors[i]); } resp = json.toString(); } writer.write(resp); writer.flush(); } }); response.setEntity(entity); }
From source file:net.morphbank.mbsvc3.webservices.RestServiceExcelUpload.java
private void htmlPresentation(HttpServletRequest request, HttpServletResponse response, String folderPath, ArrayList<String> reportContent) { StringBuffer listOfFiles = new StringBuffer(); Iterator<String> iter = reportContent.iterator(); while (iter.hasNext()) { String next = iter.next(); listOfFiles.append(next + "<br />"); }/*from w w w . j a va2 s .co m*/ if (listOfFiles.length() == 0) { listOfFiles.append("No report file found. The upload probably stopped before creating a report."); } request.setAttribute("listOfFiles", listOfFiles.toString()); try { this.getServletContext().getRequestDispatcher("/showListOfFile.jsp").forward(request, response); } catch (ServletException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.adintellig.UDFJson.java
private Object extract_json_withindex(Object json, ArrayList<String> indexList) throws JSONException { jsonList.clear();/*from w w w . j a v a 2s. c om*/ jsonList.add(json); Iterator<String> itr = indexList.iterator(); while (itr.hasNext()) { String index = itr.next(); ArrayList<Object> tmp_jsonList = new ArrayList<Object>(); if (index.equalsIgnoreCase("*")) { for (int i = 0; i < (jsonList).size(); i++) { try { JSONArray array = (JSONArray) (jsonList).get(i); for (int j = 0; j < array.length(); j++) { tmp_jsonList.add(array.get(j)); } } catch (Exception e) { continue; } } jsonList = tmp_jsonList; } else { for (int i = 0; i < (jsonList).size(); i++) { try { tmp_jsonList.add(((JSONArray) (jsonList).get(i)).get(Integer.parseInt(index))); } catch (ClassCastException e) { continue; } catch (JSONException e) { return null; } jsonList = tmp_jsonList; } } } return (jsonList.size() > 1) ? new JSONArray(jsonList) : jsonList.get(0); }
From source file:com.streamsets.pipeline.stage.processor.kv.redis.RedisStore.java
@Override public Map<Pair<String, DataType>, LookupValue> loadAll(Iterable<? extends Pair<String, DataType>> keys) throws Exception { ArrayList<Pair<String, DataType>> keyList = Lists.newArrayList(keys); List<LookupValue> values = get(keyList); Iterator<? extends Pair<String, DataType>> keyIterator = keyList.iterator(); Iterator<LookupValue> valueIterator = values.iterator(); Map<Pair<String, DataType>, LookupValue> result = new HashMap<>(keyList.size()); while (keyIterator.hasNext() && valueIterator.hasNext()) { result.put(keyIterator.next(), valueIterator.next()); }/*from w ww. java 2s . c o m*/ return result; }
From source file:de.klemp.middleware.controller.Controller.java
/** * This method searches the methods from the classes of the first and the * second component. If a method of the second component needs a data, then * the String "Struktur fehlt" will be set in the column "data" of the table * "Classes". If a method does not need a data the column data is set="". *//*from w w w. j a v a 2 s . co m*/ public static synchronized void searchMethods() { createDBConnection(); try { Statement statement = conn.createStatement(); statement.execute("delete from \"Classes\";"); statement.execute("delete from \"Data\";"); structures.clear(); PreparedStatement st = conn .prepareStatement("insert into \"Classes\" (component, class, method) values (?,?,?); "); ArrayList classes = getClasses(component1); Iterator iterator = classes.iterator(); st.setInt(1, 1); while (iterator.hasNext()) { Object class1 = iterator.next(); Method[] methods = class1.getClass().getDeclaredMethods(); String name1 = class1.getClass().getName(); String[] className = name1.split("\\."); st.setString(2, className[1]); for (int i = 0; i < methods.length; i++) { String name = methods[i].getName(); st.setString(3, name); st.execute(); } } classes = getClasses(component2); iterator = classes.iterator(); st.setInt(1, 2); PreparedStatement st2 = conn .prepareStatement("insert into \"Data\" ( class, method,topic,data) values (?,?,?,?); "); while (iterator.hasNext()) { Object class2 = iterator.next(); Method[] methods = class2.getClass().getDeclaredMethods(); String name2 = class2.getClass().getName(); String[] className = name2.split("\\."); st.setString(2, className[1]); st2.setString(1, className[1]); for (int i = 0; i < methods.length; i++) { String method = methods[i].getName(); st2.setString(3, ""); st.setString(3, method); st2.setString(2, method); Class<?>[] parameter = methods[i].getParameterTypes(); for (int j = 0; j < parameter.length; j++) { if (parameter[j].getName() == "Controller.Structure") { st2.setString(4, "structure is missing"); st2.execute(); break; } if (parameter[j].getName() == "Controller.Sensor") { st2.setString(4, "Sensor"); st2.execute(); break; } } st.execute(); } } } catch (SQLException e) { logger.error("SQL Exception", e); } closeDBConnection(); }
From source file:com.streamsets.pipeline.hbase.api.common.processor.HBaseStore.java
@Override public Map<Pair<String, HBaseColumn>, Optional<String>> loadAll( Iterable<? extends Pair<String, HBaseColumn>> keys) throws Exception { ArrayList<Pair<String, HBaseColumn>> keyList = Lists.newArrayList(keys); List<Optional<String>> values = get(keyList); Iterator<? extends Pair<String, HBaseColumn>> keyIterator = keyList.iterator(); Iterator<Optional<String>> valueIterator = values.iterator(); Map<Pair<String, HBaseColumn>, Optional<String>> result = new HashMap<>(keyList.size()); while (keyIterator.hasNext() && valueIterator.hasNext()) { result.put(keyIterator.next(), valueIterator.next()); }//ww w .ja v a2s. co m return result; }
From source file:de.klemp.middleware.controller.Controller.java
public static void informSensorController(String klasse, String method, String name, Sensor sensor) { isBrokerStarted();/*from w ww .ja v a 2 s .c o m*/ System.out.println("controller informed"); ArrayList<MethodToInvoke> list = controller.get(klasse + "," + method + "," + name); if (list != null) { Iterator iterator = list.iterator(); while (iterator.hasNext()) { MethodToInvoke m = (MethodToInvoke) iterator.next(); System.out.println("controller informed" + m.getdata()); if (deviceActive.get(m.getClasses() + "," + m.getTopic())) { Method m2 = m.getMethod(); String data = m.getdata(); if (data.equals("Sensor")) { Object[] parameter = new Object[3]; parameter[0] = name; parameter[1] = m.getTopic(); parameter[2] = sensor; try { m2.invoke(null, parameter); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { logger.error("Method could not be invoced", e); } } } } } }
From source file:logdruid.util.DataMiner.java
public static void populateRecordingSamples(Repository repo) { PatternCache patternCache = new PatternCache(); FileReader flstr = null;// ww w . j a va 2 s . c om BufferedReader buf1st; Map<Recording, String> recMatch = new HashMap<Recording, String>(); Matcher matcher; Matcher matcher2; logger.info("popu1"); if (repo.getBaseSourcePath() == null) return; logger.info("popu1"); File folder = new File(repo.getBaseSourcePath()); try { if (repo.isRecursiveMode()) { listOfFiles = FileListing.getFileListing(folder); logger.info("popu1"); } else { listOfFiles = Arrays.asList(folder.listFiles()); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block } if (repo != null && repo.getBaseSourcePath() != null) { ChartData cd = DataMiner.gatherSourceData(repo); logger.info("popu2"); ArrayList sources = repo.getSources(); Iterator sourceArrayListIte = sources.iterator(); while (sourceArrayListIte.hasNext()) { // Map<Recording, String> regMap=getRegexp(repo, src); cd.sourceArrayList = repo.getSources(); Iterator<Source> sourceIterator = cd.sourceArrayList.iterator(); Source src = (Source) sourceArrayListIte.next(); Map<String, ArrayList<FileRecord>> hm = cd.getGroupFilesMap(src); logger.info("popu3"); Iterator it = hm.entrySet().iterator(); while (it.hasNext()) { final Map.Entry pairs = (Map.Entry) it.next(); logger.info("popu4: " + pairs.getKey()); ArrayList<FileRecord> grouFile = (ArrayList<FileRecord>) pairs.getValue(); // return DataMiner.mine((String) pairs.getKey(), (ArrayList<String>) pairs.getValue(), repo, source, repo.isStats(), repo.isTimings()); Iterator<FileRecord> fileArrayListIterator = grouFile.iterator(); while (fileArrayListIterator.hasNext()) { final FileRecord fileName = fileArrayListIterator.next(); try { flstr = new FileReader(new File(fileName.getCompletePath())); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } buf1st = new BufferedReader(flstr); String line; logger.info("matched file:" + fileName); recMatch = getRegexp(repo, src); int lineCount = 0; try { while ((line = buf1st.readLine()) != null) { // check against one Recording pattern at a tim // if (logger.isDebugEnabled()) { // logger.debug("line " + line); // } Iterator recMatchIte = recMatch.entrySet().iterator(); while (recMatchIte.hasNext()) { Map.Entry me = (Map.Entry) recMatchIte.next(); Recording rec = (Recording) me.getKey(); matcher = patternCache.getPattern((String) (rec.getRegexp())).matcher(line); if (matcher.find()) { // logger.info("1**** matched: " + line); ArrayList<RecordingItem> recordingItem = ((Recording) rec) .getRecordingItem(); int cnt = 0; matcher2 = patternCache.getPattern((String) me.getValue()).matcher(line); if (matcher2.find()) { DataVault.addMatchedLines(rec, line); } else { DataVault.addUnmatchedLines(rec, line); } } } } } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } } } }
From source file:club.jmint.crossing.config.AclConfig.java
public boolean isInterfaceAccessible(String clientIp, String inf) { //if ACL not enabled, means all rights are permitted. if (!isAclEnabled) { return true; }/*ww w . j av a 2 s.c o m*/ if (!ruleMap.get("interface").isEnabled()) { return true; } ArrayList<String> al = gifMap.get(clientIp); if (al == null) { return false; //not found } Iterator<String> it = al.iterator(); String en; while (it.hasNext()) { en = it.next(); if (en.equals(inf)) { return true; } } return false; }
From source file:com.huguesjohnson.sega32xcollector.ebay.EbayUtils.java
public SearchResult search(ArrayList<String> keywords) { SearchResult results = new SearchResult(); Iterator<String> iterator = keywords.iterator(); while (iterator.hasNext()) { results.append(this.search(iterator.next())); }//from w w w . ja v a2 s .c o m results.sort(); return (results); }