List of usage examples for java.util.stream Stream map
<R> Stream<R> map(Function<? super T, ? extends R> mapper);
From source file:com.thoughtworks.go.config.CaseInsensitiveString.java
private static List<CaseInsensitiveString> toList(Stream<String> stream) { return stream.map(CaseInsensitiveString::new).collect(Collectors.toList()); }
From source file:com.thoughtworks.go.config.CaseInsensitiveString.java
private static List<String> toStringList(Stream<CaseInsensitiveString> stream) { return stream.map(CaseInsensitiveString::toString).collect(Collectors.toList()); }
From source file:com.ikanow.aleph2.core.shared.utils.TimeSliceDirUtils.java
/** Internal utility * @param dir_listing//w ww . j ava 2s .c o m * @return */ private static Stream<Tuple3<String, String, Validation<String, Date>>> candidateTimedDirectories( final Stream<String> dir_listing) { return dir_listing.map(dir -> dir.endsWith("/") ? dir.substring(0, dir.length() - 1) : dir) .map(dir -> Tuples._2T(dir, dir.lastIndexOf("/"))) // if not present, returns -1 which means the substring below grabs the entire thing .map(dir_date -> Tuples._2T(dir_date._1(), dir_date._1().substring(1 + dir_date._2()))) .map(dir_date -> Tuples._3T(dir_date._1(), dir_date._2(), dir_date._2().lastIndexOf("_"))) // if not present, returns -1 which means the substring below grabs the entire thing .map(dir_date_index -> { // ugly case where ends in a segment (with or without date) if ((dir_date_index._2().length() - dir_date_index._3()) <= 4) { //ie 3 chars + 1 for '_', means it can't be a date so must be a segment final String new_date = dir_date_index._1().substring(0, dir_date_index._3()); //(up to including the last _) return Tuples._3T(dir_date_index._1(), new_date, new_date.lastIndexOf("_")); } else return dir_date_index; }) .map(dir_date_index -> Tuples._2T(dir_date_index._1(), dir_date_index._2().substring(1 + dir_date_index._3()))) .map(dir_date -> Tuples._3T(dir_date._1(), dir_date._2(), TimeUtils.getDateFromSuffix(dir_date._2()))); }
From source file:com.wrmsr.wava.basic.BasicSet.java
public static BasicSet build(Stream<Basic> basics) { return new BasicSet(basics.map(basic -> { checkArgument(!Basics.TERMINAL_NAMES.contains(basic.getName())); return ImmutablePair.of(basic.getName(), basic); }).collect(toPersistentHashMap()));/*from w w w . j av a 2 s .co m*/ }
From source file:com.github.robozonky.app.events.SessionEvents.java
/** * Takes a set of {@link Runnable}s and queues them to be fired on a background thread, in the guaranteed order of * appearance.//from w w w. ja v a 2 s . c o m * @param futures Each item in the stream represents a singular event to be fired. * @return When complete, all listeners have been notified of all the events. */ @SuppressWarnings("rawtypes") private static Runnable runAsync(final Stream<Runnable> futures) { final Runnable[] results = futures.map(EventFiringQueue.INSTANCE::fire).toArray(Runnable[]::new); return GlobalEvents.merge(results); }
From source file:alfio.controller.api.support.TicketHelper.java
private static List<Pair<String, String>> mapISOCountries(Stream<String> isoCountries, Locale locale) { return isoCountries.map(isoCode -> Pair.of(isoCode, new Locale("", isoCode).getDisplayCountry(locale))) .sorted(Comparator.comparing(Pair::getRight)).collect(Collectors.toList()); }
From source file:com.yevster.spdxtra.Read.java
private static Stream<Relationship> getRelationshipsWithSparql(Dataset dataset, String sparql) { try (DatasetAutoAbortTransaction transaction = DatasetAutoAbortTransaction.begin(dataset, ReadWrite.READ)) { QueryExecution qe = QueryExecutionFactory.create(sparql, dataset); ResultSet results = qe.execSelect(); Stream<QuerySolution> solutionStream = StreamSupport.stream( Spliterators.spliteratorUnknownSize(results, Spliterator.ORDERED | Spliterator.NONNULL), false); return solutionStream.map((QuerySolution qs) -> { RDFNode relationshipNode = qs.get("o"); assert (relationshipNode.isResource()); return new Relationship(relationshipNode.asResource()); });//from w w w .j a v a 2 s .co m } }
From source file:com.yevster.spdxtra.Read.java
public static Stream<SpdxPackage> getAllPackages(Dataset dataset) { try (DatasetAutoAbortTransaction transaction = DatasetAutoAbortTransaction.begin(dataset, ReadWrite.READ)) { String sparql = createSparqlQueryByType(SpdxUris.SPDX_PACKAGE); QueryExecution qe = QueryExecutionFactory.create(sparql, dataset); ResultSet results = qe.execSelect(); Stream<QuerySolution> querySolutionStream = StreamSupport.stream( Spliterators.spliteratorUnknownSize(results, Spliterator.ORDERED | Spliterator.NONNULL), false); return querySolutionStream.map((QuerySolution qs) -> { RDFNode subject = qs.get("s"); return new SpdxPackage(subject.asResource()); });//from w ww . ja v a 2 s . com } }
From source file:com.ikanow.aleph2.analytics.services.DeduplicationService.java
/** Utility to find a single field for dedup purposes * @param in - stream of JSON objects//www .j a va2 s.c om * @param key_field * @return */ protected static List<Tuple2<JsonNode, Tuple2<Long, IBatchRecord>>> extractKeyField( final Stream<Tuple2<Long, IBatchRecord>> in, final String key_field) { return in.map(x -> extractKeyField(x._2().getJson(), key_field).map(y -> Tuples._2T(y, x)).orElse(null)) .filter(x -> null != x).collect(Collectors.toList()); }
From source file:eu.mihosoft.vrl.v3d.Edge.java
private static List<Edge> boundaryEdgesOfPlaneGroup(List<Polygon> planeGroup) { List<Edge> edges = new ArrayList<>(); Stream<Polygon> pStream; if (planeGroup.size() > 200) { pStream = planeGroup.parallelStream(); } else {/*from w w w. ja va2 s .co m*/ pStream = planeGroup.stream(); } pStream.map((p) -> Edge.fromPolygon(p)).forEach((pEdges) -> { edges.addAll(pEdges); }); Stream<Edge> edgeStream; if (edges.size() > 200) { edgeStream = edges.parallelStream(); } else { edgeStream = edges.stream(); } // find potential boundary edges, i.e., edges that occur once (freq=1) List<Edge> potentialBoundaryEdges = new ArrayList<>(); edgeStream.forEachOrdered((e) -> { int count = Collections.frequency(edges, e); if (count == 1) { potentialBoundaryEdges.add(e); } }); // now find "false boundary" edges end remove them from the // boundary-edge-list // // thanks to Susanne Hllbacher for the idea :) Stream<Edge> bndEdgeStream; if (potentialBoundaryEdges.size() > 200) { bndEdgeStream = potentialBoundaryEdges.parallelStream(); } else { bndEdgeStream = potentialBoundaryEdges.stream(); } List<Edge> realBndEdges = bndEdgeStream .filter(be -> edges.stream().filter(e -> falseBoundaryEdgeSharedWithOtherEdge(be, e)).count() == 0) .collect(Collectors.toList()); // // System.out.println("#bnd-edges: " + realBndEdges.size() // + ",#edges: " + edges.size() // + ", #del-bnd-edges: " + (boundaryEdges.size() - realBndEdges.size())); return realBndEdges; }