List of usage examples for java.util List stream
default Stream<E> stream()
From source file:info.rmarcus.birkhoffvonneumann.MatrixUtils.java
public static double[] flatten(double[][] a) { List<Double> l = new ArrayList<Double>(a.length * a.length); for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[i].length; j++) { l.add(a[i][j]);//from w ww .j a v a 2 s . c o m } } final double[] toR = l.stream().mapToDouble(d -> d).toArray(); if (toR != null) return toR; throw new BVNRuntimeException("Unable to map double stream to array!"); }
From source file:ai.grakn.engine.controller.TasksController.java
static private <T> CompletableFuture<List<T>> all(List<CompletableFuture<T>> cf) { return CompletableFuture.allOf(cf.toArray(new CompletableFuture[cf.size()])) .thenApply(v -> cf.stream().map(CompletableFuture::join).collect(toList())); }
From source file:alfio.manager.system.ConfigurationManager.java
static Map<ConfigurationKeys.SettingCategory, List<Configuration>> union(ConfigurationPathLevel... levels) { List<Configuration> configurations = Arrays.stream(levels) .sorted(ConfigurationPathLevel.COMPARATOR.reversed()) .flatMap(l -> ConfigurationKeys.byPathLevel(l).stream().map(mapEmptyKeys(l))) .sorted((c1, c2) -> new CompareToBuilder() .append(c2.getConfigurationPathLevel(), c1.getConfigurationPathLevel()) .append(c1.getConfigurationKey(), c2.getConfigurationKey()).toComparison()) .collect(LinkedList::new, (List<Configuration> list, Configuration conf) -> { int existing = (int) list.stream() .filter(c -> c.getConfigurationKey() == conf.getConfigurationKey()).count(); if (existing == 0) { list.add(conf);/*from ww w.j av a 2 s.c o m*/ } }, (l1, l2) -> { }); return configurations.stream().collect(groupByCategory()); }
From source file:com.asakusafw.workflow.executor.TaskExecutors.java
private static URLClassLoader loader(TaskExecutionContext context, List<? extends Path> libraries) { URL[] urls = libraries.stream().map(Path::toUri).flatMap(uri -> { try {/*w ww .ja v a 2 s. c om*/ return Stream.of(uri.toURL()); } catch (MalformedURLException e) { LOG.warn("failed to convert URI: {}", uri, e); return Stream.empty(); } }).toArray(URL[]::new); return URLClassLoader.newInstance(urls, context.getClassLoader()); }
From source file:com.thinkbiganalytics.metadata.jpa.support.GenericQueryDslFilter.java
/** * build the Filter for the base QueryDSL class and the passed in filter list * * @param filters name:test, age>10//from w ww .j a v a 2 s. co m */ public static <T> BooleanBuilder buildFilter(EntityPathBase basePath, List<SearchCriteria> filters) { BooleanBuilder booleanBuilder = new BooleanBuilder(); if (filters != null && !filters.isEmpty()) { filters.stream().forEach(filter -> { Path p = buildPathFromFilterColumn(basePath, filter.getKey()); if (p != null) { Object value = filter.getValue(); Operator op = operators.get(filter.getOperation()); if (validateOperatorPath(op, p, filter.getKey(), value)) { if (Ops.LIKE_IC.equals(op) && value instanceof String && value != null && !((String) value).endsWith("%")) { value = ((String) value) + "%"; } if (value == null || (value instanceof String && ((String) value).equalsIgnoreCase(NULL_FILTER))) { op = Ops.IS_NULL; value = null; } else if (value instanceof String && ((String) value).equalsIgnoreCase(NOT_NULL_FILTER)) { op = Ops.IS_NOT_NULL; value = null; } if (value != null) { Object convertedValue = getValueForQuery(p, filter.getKey(), op, value); if (convertedValue != null && convertedValue instanceof Collection) { op = Ops.IN; } if (convertedValue != null) { Expression e = null; if (convertedValue instanceof Comparable) { e = Expressions.asComparable((Comparable) convertedValue); } else { e = Expressions.constant(convertedValue); } //reset the operator if looking for UUID if (convertedValue instanceof UUID || convertedValue instanceof Enum) { op = Ops.EQ; } //reset the operator if looking for UUID // if(convertedValue instanceof UUID){ // op = Ops.EQ; // } if (filter.isOrFilter()) { booleanBuilder.or(Expressions.predicate(op, p, e)); } else { booleanBuilder.and(Expressions.predicate(op, p, e)); } } } else { if (filter.isOrFilter()) { booleanBuilder.or(Expressions.predicate(op, p)); } else { booleanBuilder.and(Expressions.predicate(op, p)); } } } } }); } return booleanBuilder; }
From source file:Main.java
public static <T> List<List<T>> innerJoin(List<T> l1, List<T> l2, BiFunction<T, T, T> function) { if (l1 == null || l2 == null) { throw new NullPointerException("inner join arrays must not be null"); }//from w ww .ja v a2 s . c o m if (l1.isEmpty() && l2.isEmpty()) { return Collections.emptyList(); } else if (l1.isEmpty()) { return Collections.singletonList(l2); } else if (l2.isEmpty()) { return Collections.singletonList(l1); } List<List<T>> result = new ArrayList<>(l1.size() * l2.size()); l1.stream().forEach(t1 -> { List<T> l = new ArrayList<>(); l2.stream().forEach(t2 -> l.add(function.apply(t1, t2))); result.add(l); }); return result; }
From source file:com.diversityarrays.kdxplore.vistool.VisToolData.java
static public String createReportText(Bag<String> missingOrBad, Bag<String> suppressed) { String fmt = Msg.raw_MSG_VALUE_COLON_VALUE_COUNT(); List<String> lines = new ArrayList<>(); if (!missingOrBad.isEmpty()) { lines.add(Msg.MSG_SOME_TRAIT_VALUES_NOT_PLOTTED()); lines.add("Missing or Invalid:"); appendLines(fmt, missingOrBad, lines); }// ww w . j av a2 s . com if (!suppressed.isEmpty()) { if (missingOrBad.isEmpty()) { lines.add(Msg.MSG_SOME_TRAIT_VALUES_NOT_PLOTTED()); } lines.add("Suppressed:"); appendLines(fmt, suppressed, lines); } return lines.stream().collect(Collectors.joining("\n")); //$NON-NLS-1$ }
From source file:de.metas.ui.web.window.datatypes.json.JSONDocument.java
public static JSONDocument ofDocumentView(final IDocumentView documentView) { final JSONDocument jsonDocument = new JSONDocument(documentView.getDocumentPath()); ////from w ww . j a v a 2s .c om // Fields { final List<JSONDocumentField> jsonFields = new ArrayList<>(); // Add pseudo "ID" field first final String idFieldName = documentView.getIdFieldNameOrNull(); if (idFieldName != null) { final Object id = documentView.getDocumentId().toJson(); jsonFields.add(0, JSONDocumentField.idField(id)); } // Append the other fields documentView.getFieldNameAndJsonValues().entrySet().stream() .map(e -> JSONDocumentField.ofNameAndValue(e.getKey(), e.getValue())).forEach(jsonFields::add); jsonDocument.setFields(jsonFields); // // Document view record specific attributes if (documentView.isProcessed()) { jsonDocument.putOtherProperty("processed", true); } if (documentView.hasAttributes()) { jsonDocument.putOtherProperty(JSONDocumentViewLayout.PROPERTY_supportAttributes, true); } if (documentView.getType() != null) { jsonDocument.putOtherProperty("type", documentView.getType().getName()); } } // // Included documents if any { final List<? extends IDocumentView> includedDocuments = documentView.getIncludedDocuments(); if (!includedDocuments.isEmpty()) { final List<JSONDocument> jsonIncludedDocuments = includedDocuments.stream() .map(JSONDocument::ofDocumentView).collect(GuavaCollectors.toImmutableList()); jsonDocument.setIncludedDocuments(jsonIncludedDocuments); } } return jsonDocument; }
From source file:com.github.horrorho.inflatabledonkey.cloud.clients.AssetsClient.java
public static List<Assets> assets(HttpClient httpClient, CloudKitty kitty, ProtectionZone zone, Collection<Manifest> manifests) throws IOException { if (manifests.isEmpty()) { return new ArrayList<>(); }//from w ww. j a va 2 s. c o m List<String> manifestIDs = manifests.stream().map(AssetsClient::manifestIDs).flatMap(Collection::stream) .collect(Collectors.toList()); List<CloudKit.RecordRetrieveResponse> responses = kitty.recordRetrieveRequest(httpClient, "_defaultZone", manifestIDs); logger.info("-- assets() - responses: {}", responses.size()); // Manifests with multiple counts only return protection info for the first block, as we are passing blocks in // order we can reference the previous protection zone. // TODO tighten up. AtomicReference<ProtectionZone> previous = new AtomicReference<>(zone); return responses.stream().filter(CloudKit.RecordRetrieveResponse::hasRecord) .map(CloudKit.RecordRetrieveResponse::getRecord).map(r -> assets(r, zone, previous)) .collect(Collectors.toList()); }
From source file:com.wrmsr.wava.TestWhatever.java
public static void doFunction(com.wrmsr.wava.core.unit.Function function_) throws Exception { System.out.println(function_.getName().get()); com.wrmsr.wava.core.unit.Function function = new StandardFunctionProcessor().processFunction(function_); BasicSet basics;/*w w w. j av a2s .c o m*/ { Node root = function.getBody(); Map<Name, Node> namedNodes = Analyses.getNamedNodes(root); Map<Node, Name> namedNodeNames = namedNodes.entrySet().stream() .collect(toIdentityMap(e -> e.getValue(), e -> e.getKey())); List<Node> nodes = Analyses.linearize(root); Map<Node, Integer> nodeIndices = indexIdentityMap(nodes); Map<Node, Name> nodeNames = nodes.stream() .map(node -> ImmutablePair.of(node, namedNodeNames.containsKey(node) ? namedNodeNames.get(node) : Name.of("node" + nodeIndices.get(node)))) .collect(toIdentityMap(Map.Entry::getKey, Map.Entry::getValue)); ValueTypeAnalysis vta = ValueTypeAnalysis.analyze(root, false); ControlFlowGraph cfg = ControlFlowGraph.analyzeShallow(root, namedNodes, vta); basics = BasicSet.build( Basics.buildBasics(cfg, vta, nodeNames, nodeIndices).values().stream().map(Basics::cleanBasic)); } // showBasics(basics, true); // { // Node root = worst(basics, findBasicLoops(basics, generateBasicDominatorTree(basics))); // JDeclaration jdecl = jcompileFunction(new com.wrmsr.wava.core.unit.Function(function.getName(), function.getResult(), function.getArgCount(), function.getLocals(), root)).get(0); // CodeBlock.Builder code = CodeBlock.builder(); // new JRenderer(code).renderDeclaration(jdecl); // System.out.println(JRenderer.renderWithIndent(code.build(), " ")); // } while (true) { int size = basics.size(); System.out.println(size); basics = transformBasics(SimpleMatching::mergeUnconditionalBasic, basics); basics = transformBasics(SimpleMatching::mergeEmptyBasic, basics); basics = transformBasics(BooleanMatching::shrinkIf, basics); basics = transformBasics(BooleanMatching::shrinkIfElse, basics); basics = transformBasics(bind(LoopMatching::shrinkSelfLoops, BasicLoopInfo.build(basics, BasicDominatorInfo.build(basics)))::apply, basics); basics = transformBasics(bind(TestWhatever::shrinkSimpleLoop, BasicLoopInfo.build(basics, BasicDominatorInfo.build(basics)))::apply, basics); basics = transformBasics(TestWhatever::collapseIfOr, basics); if (basics.size() == size) { break; } } showBasics(function.getName(), basics, true); // getLoopContents(basics, Name.of("node155")); // Map<Name, Name> loopParents = new HashMap<>(); // { // Stack<Name> rootStack = new Stack<>(); // rootStack.push(null); // Set<Name> set = new HashSet<>(loops); // while (!rootStack.isEmpty()) { // Name parent = rootStack.pop(); // if (parent != null) { // set.remove(parent); // } // Set<Name> rootLoops = set.stream().filter(loop -> !set.stream().anyMatch(otherLoop -> !otherLoop.equals(loop) && loopContents.get(otherLoop).contains(loop))).collect(toImmutableSet()); // for (Name rootLoop : rootLoops) { // loopParents.put(rootLoop, parent); // rootStack.push(rootLoop); // } // } // checkState(set.isEmpty()); // } // if (basics.size() > 3 && basics.size() < 8) { // showBasics(function.getName(), basics, true); // } // cfgStackify(basics); // DirectedGraph<Integer, DefaultEdge> graph = new DefaultDirectedGraph<>(DefaultEdge.class); // nodeIndices.values().forEach(graph::addVertex); // cfg.getEdges().forEach(e -> graph.addEdge(nodeIndices.get(e.getInput()), nodeIndices.get(e.getOutput()))); // DominatorTree<Integer, DefaultEdge> dt = new DominatorTree<>(graph, 0); }