List of usage examples for java.util ArrayList stream
default Stream<E> stream()
From source file:app.NotificationJSONizer.java
public static void jsonize(ArrayList<backend.Notification> notis, PrintWriter out) { JSONArray a = new JSONArray(); notis.stream().forEach((noti) -> { JSONObject o = noti.jsonize();//from w w w . j a v a2s. co m o.put("type", noti.get_type().toString()); a.add(o); }); out.print(a.toString()); }
From source file:Main.java
public static Stream<Node> getChildren(Node node) { NodeList children = node.getChildNodes(); ArrayList<Node> childNodeList = new ArrayList<>(); for (int c = 0; c < children.getLength(); c++) { childNodeList.add(children.item(c)); }/*from ww w .j ava 2s . c o m*/ Stream<Node> childrenStream = childNodeList.stream(); return childrenStream; }
From source file:org.pentaho.js.require.RebuildCacheCallable.java
private static void makePathsAbsolute(Map<String, Object> result, String baseUrl) { HashMap<String, String> paths = (HashMap<String, String>) result.get("paths"); paths.forEach((moduleId, location) -> { if (checkNeedsBaseUrl(location)) { paths.put(moduleId, baseUrl + location); }/*from w ww .java 2 s . c om*/ }); ArrayList<Object> packages = (ArrayList<Object>) result.get("packages"); final ArrayList<Object> convertedPackages = packages.stream().filter(Objects::nonNull) .map(packageDefinition -> { if (packageDefinition instanceof HashMap) { final HashMap<String, String> complexPackageDefinition = (HashMap<String, String>) packageDefinition; if (complexPackageDefinition.containsKey("location")) { String location = complexPackageDefinition.get("location"); if (checkNeedsBaseUrl(location)) { complexPackageDefinition.put("location", baseUrl + location); return complexPackageDefinition; } } } return packageDefinition; }).collect(Collectors.toCollection(ArrayList<Object>::new)); result.put("packages", convertedPackages); }
From source file:edgeserver.Publicador.java
private static void armazenaFila(ArrayList filaPublicacoes) throws IOException { new PrintWriter("fila.txt").close(); filaPublicacoes.stream().forEach((publicacao) -> { BufferedWriter bw = null; try {/* w w w . j a v a2 s .com*/ // APPEND MODE SET HERE bw = new BufferedWriter(new FileWriter("fila.txt", true)); bw.write(publicacao.toString()); bw.newLine(); bw.flush(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { // always close the file if (bw != null) try { bw.close(); } catch (IOException ioe2) { // just ignore it } } }); }
From source file:org.neo4j.nlp.examples.wikipedia.main.java
private static List<Map<String, Object>> getWikipediaArticles() throws IOException { final String txUri = "http://localhost:7474/db/data/" + "transaction/commit"; WebResource resource = Client.create().resource(txUri); String query = "MATCH (n:Page) WITH n, rand() as sortOrder " + "ORDER BY sortOrder " + "LIMIT 1000 " + "RETURN n.title as title"; String payload = "{\"statements\" : [ {\"statement\" : \"" + query + "\"} ]}"; ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON) .entity(payload).post(ClientResponse.class); ObjectMapper objectMapper = new ObjectMapper(); HashMap<String, Object> result; try {// w w w . j av a 2 s .c om result = objectMapper.readValue(response.getEntity(String.class), HashMap.class); } catch (Exception e) { throw e; } response.close(); List<Map<String, Object>> results = new ArrayList<>(); ArrayList resultSet = ((ArrayList) result.get("results")); List<LinkedHashMap<String, Object>> dataSet = (List<LinkedHashMap<String, Object>>) resultSet.stream() .map(a -> (LinkedHashMap<String, Object>) a).collect(Collectors.toList()); List<LinkedHashMap> rows = (List<LinkedHashMap>) ((ArrayList) (dataSet.get(0).get("data"))).stream() .map(m -> (LinkedHashMap) m).collect(Collectors.toList()); ArrayList cols = (ArrayList) (dataSet.get(0).get("columns")); for (LinkedHashMap row : rows) { ArrayList values = (ArrayList) row.get("row"); Map<String, Object> resultRecord = new HashMap<>(); for (int i = 0; i < values.size(); i++) { resultRecord.put(cols.get(i).toString(), values.get(i)); } results.add(resultRecord); } return results; }
From source file:org.neo4j.nlp.examples.sentiment.main.java
private static boolean testOnText(String text, String label) { JsonObject jsonParam = new JsonObject(); jsonParam.add("text", new JsonPrimitive(text)); String jsonPayload = new Gson().toJson(jsonParam); String input = executePost("http://localhost:7474/service/graphify/classify", jsonPayload); System.out.println(input);/*from ww w. j a va 2 s. com*/ ObjectMapper objectMapper = new ObjectMapper(); Map<String, Object> hashMap = new HashMap<>(); try { hashMap = (Map<String, Object>) objectMapper.readValue(input, HashMap.class); } catch (IOException e) { e.printStackTrace(); } // Validate guess ArrayList classes = (ArrayList) hashMap.get("classes"); if (classes.size() > 0) { LinkedHashMap className = (LinkedHashMap) classes.stream().findFirst().get(); return className.get("class").equals(label); } else { return false; } }
From source file:org.apache.sysml.runtime.codegen.SpoofOperator.java
public static long getTotalInputNnz(ArrayList<MatrixBlock> inputs) { return inputs.stream().mapToLong(in -> in.getNonZeros()).sum(); }
From source file:org.apache.sysml.runtime.codegen.SpoofOperator.java
public static long getTotalInputSize(ArrayList<MatrixBlock> inputs) { return inputs.stream().mapToLong(in -> (long) in.getNumRows() * in.getNumColumns()).sum(); }
From source file:org.sleuthkit.autopsy.imageanalyzer.ImageAnalyzerModule.java
/** * * @param file/*from w ww. jav a2s. com*/ * * @return true if the file had a TSK_FILE_TYPE_SIG attribute on a * TSK_GEN_INFO that is in the supported list. False if there was an * unsupported attribute, null if no attributes were found */ public static Boolean hasSupportedMimeType(AbstractFile file) { try { ArrayList<BlackboardAttribute> fileSignatureAttrs = file .getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_FILE_TYPE_SIG); if (fileSignatureAttrs.isEmpty() == false) { return fileSignatureAttrs.stream().anyMatch(attr -> supportedMimes.contains(attr.getValueString())); } } catch (TskCoreException ex) { LOGGER.log(Level.INFO, "failed to read TSK_FILE_TYPE_SIG attribute for " + file.getName(), ex); } return null; }
From source file:org.sleuthkit.autopsy.imageanalyzer.ImageAnalyzerModule.java
/** @param file * * @return true if the given file has a supported video mime type or * extension, else false//w w w . ja v a 2 s . c om */ public static boolean isVideoFile(AbstractFile file) { try { ArrayList<BlackboardAttribute> fileSignatureAttrs = file .getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_FILE_TYPE_SIG); if (fileSignatureAttrs.isEmpty() == false) { return fileSignatureAttrs.stream().anyMatch(attr -> videoMimes.contains(attr.getValueString())); } } catch (TskCoreException ex) { LOGGER.log(Level.INFO, "failed to read TSK_FILE_TYPE_SIG attribute for " + file.getName(), ex); } //if there were no file type attributes, or we failed to read it, fall back on extension return videoExtensions.contains(getFileExtension(file)); }