List of usage examples for java.util Collection stream
default Stream<E> stream()
From source file:io.atomix.core.tree.DocumentPath.java
/** * Returns the path that points to the least common ancestor of the specified * collection of paths.//from www . jav a 2 s . c om * * @param paths collection of path * @return path to least common ancestor */ public static DocumentPath leastCommonAncestor(Collection<DocumentPath> paths) { if (paths.isEmpty()) { return null; } return DocumentPath.from( StringUtils.getCommonPrefix(paths.stream().map(DocumentPath::toString).toArray(String[]::new))); }
From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.agent.KubernetesCacheDataConverter.java
static int relationshipCount(Collection<CacheData> data) { return data.stream().map(d -> relationshipCount(d)).reduce(0, (a, b) -> a + b); }
From source file:de.metas.ui.web.window.datatypes.json.JSONDocument.java
/** * @param documents/*from ww w. j ava 2 s . c o m*/ * @param includeFieldsList * @return list of {@link JSONDocument}s */ public static List<JSONDocument> ofDocumentsList(final Collection<Document> documents, final JSONOptions jsonOpts) { return documents.stream().map(document -> ofDocument(document, jsonOpts)).collect(Collectors.toList()); }
From source file:edu.wpi.checksims.testutil.AlgorithmUtils.java
/** * Ensure that every pair in a set of pairs is representing in algorithm results * * @param results Collection of algorithm results to check in * @param pairs Pairs of submissions to search for in the results *//*from w w w.java 2 s .c o m*/ public static void checkResultsContainsPairs(Collection<AlgorithmResults> results, Set<Pair<Submission, Submission>> pairs) { assertNotNull(results); assertNotNull(pairs); assertEquals(results.size(), pairs.size()); for (Pair<Submission, Submission> pair : pairs) { long numWithResult = results.stream().filter((result) -> { return (result.a.equals(pair.getLeft()) && result.b.equals(pair.getRight())) || (result.a.equals(pair.getRight()) && result.b.equals(pair.getLeft())); }).count(); assertEquals(1, numWithResult); } }
From source file:com.yahoo.bard.webservice.util.SimplifiedIntervalList.java
/** * Takes one or more lists of intervals, and combines them into a single, sorted list with the minimum number of * intervals needed to capture exactly the same instants as the original intervals. * <p>//from www. jav a2s. c om * If any subintervals of the input collection abut or overlap they will be replaced with a single, combined * interval. * <p> * Examples: * <ul> * <li>['2014/2017', '2015/2020'] will combine into ['2014/2020'] * <li>['2015/2016', '2016/2017'] will combine into ['2015/2017] * <li>['2015/2016', '2013/2014'] will sort into ['2013/2014', '2015/2016'] * <li>['2015/2015', '2015/2016', '2012/2013'] will sort and combine to ['2012/2013', '2015/2016'] * </ul> * @param intervals The collection(s) of intervals being collated * * @return A single list of sorted intervals simplified to the smallest number of intervals able to describe the * duration */ @SafeVarargs public static SimplifiedIntervalList simplifyIntervals(Collection<Interval>... intervals) { Stream<Interval> allIntervals = Stream.empty(); for (Collection<Interval> intervalCollection : intervals) { allIntervals = Stream.concat(allIntervals, intervalCollection.stream()); } return allIntervals.sorted(IntervalStartComparator.INSTANCE::compare).collect(getCollector()); }
From source file:com.github.erchu.beancp.MapperExecutorSelector.java
public static boolean isMapAvailable(final MappingInfo mappingsInfo, final Class sourceClass, final Class destinationClass, final Collection<DeclarativeMapImpl<?, ?>> maps, final Collection<MapConventionExecutor> mapAnyConventions) { notNull(sourceClass, "sourceClass"); notNull(destinationClass, "destinationClass"); notNull(maps, "maps"); if (getBestMatchingDeclarativeMap(sourceClass, destinationClass, maps) != null) { return true; }/*w w w . jav a 2 s . co m*/ return mapAnyConventions.stream().anyMatch(i -> i.canMap(mappingsInfo, sourceClass, destinationClass)); }
From source file:ai.grakn.graql.internal.gremlin.GraqlTraversal.java
/** * Create a semi-optimal traversal plan using a greedy approach * @param graph the graph to use//from w w w .ja v a 2 s .co m * @param innerQueries a collection of inner queries that the traversal must execute * @return a semi-optimal traversal plan */ static GraqlTraversal semiOptimal(GraknGraph graph, Collection<ConjunctionQuery> innerQueries) { // Find a semi-optimal way to execute each conjunction Set<? extends List<Fragment>> fragments = innerQueries.stream().map(GraqlTraversal::semiOptimalConjunction) .collect(toImmutableSet()); return GraqlTraversal.create(graph, fragments); }
From source file:delfos.dataset.util.DatasetPrinter.java
public static String printCompactRatingTable(DatasetLoader<? extends Rating> datasetLoader, Collection<User> _users) { final List<User> users = _users.stream().sorted(User.BY_ID).collect(Collectors.toList()); final List<Item> itemsAllUsersRated = datasetLoader.getContentDataset().stream().sorted(Item.BY_ID) .collect(Collectors.toList()); return actuallyDoTheTable(itemsAllUsersRated, users, datasetLoader); }
From source file:com.shenit.commons.utils.CollectionUtils.java
/** * Get last n element of a collection/*from w w w . j a va2s .c o m*/ * @param cols * @param n * @return */ @SuppressWarnings("unchecked") public static <T> Collection<T> last(Collection<T> cols, int n) { if (cols == null) return null; if (cols.size() <= n) return cols; return (Collection<T>) Arrays.asList(cols.stream().skip(cols.size() - n).toArray()); }
From source file:delfos.dataset.util.DatasetPrinter.java
public static <Node> String printWeightedGraph(WeightedGraph<Node> weightedGraph, Collection<Node> nodes) { return weightedGraph.toStringTable(nodes.stream().collect(Collectors.toSet())); }