List of usage examples for com.google.common.collect ImmutableSet stream
default Stream<E> stream()
From source file:com.facebook.buck.features.project.intellij.BaseIjModuleRule.java
protected ImmutableMultimap<Path, Path> getResourcesRootsToResources(JavaPackageFinder packageFinder, ImmutableSet<Path> resourcePaths) { return resourcePaths.stream() .collect(/*from w w w. j a va 2 s . c om*/ ImmutableListMultimap.toImmutableListMultimap( path -> MorePaths.stripCommonSuffix(path.getParent(), packageFinder.findJavaPackageFolder(path)).getFirst(), Function.identity())); }
From source file:com.zuppelli.living.docs.ContextAwareDiagramMojo.java
protected void populateNonPackageNodes(ImmutableSet<ClassPath.ClassInfo> allClasses, final DotGraph.Digraph digraph) { Stream<ClassPath.ClassInfo> infra = allClasses.stream().filter(ClassInfoFilters.filterNot(this.packages)); infra.forEach(new Consumer<ClassPath.ClassInfo>() { public void accept(ClassPath.ClassInfo ci) { final Class clazz = ci.load(); if (!ignoreDeprecated(clazz) && !PACKAGE_INFO.equals(clazz.getSimpleName())) digraph.addNode(clazz.getName()).setLabel(clazz.getSimpleName()) .setComment(clazz.getSimpleName()); }//from ww w.j a v a 2s . co m }); }
From source file:com.zuppelli.living.docs.DomainDiagramMojo.java
@Override protected void populateNonPackageNodes(ImmutableSet<ClassPath.ClassInfo> allClasses, final DotGraph.Digraph digraph) { Stream<ClassPath.ClassInfo> infra = allClasses.stream().filter(filterNot(getPrefix(), "domain")); infra.forEach(new Consumer<ClassPath.ClassInfo>() { public void accept(ClassPath.ClassInfo ci) { final Class clazz = ci.load(); if (!ignoreDeprecated(clazz)) digraph.addNode(clazz.getName()).setLabel(clazz.getSimpleName()) .setComment(clazz.getSimpleName()); }/*from w ww .jav a 2 s . c o m*/ }); }
From source file:com.jeffreybosboom.lyne.rules.DesiredEdgesRule.java
@Override public Puzzle apply(Puzzle puzzle) { for (Iterator<Node> i = puzzle.nodes().iterator(); i.hasNext();) { Node a = i.next();// w w w .j a v a 2s .com List<Node> neighbors = puzzle.neighbors(a).collect(Collectors.toList()); int knownColored = 0, knownNone = 0; for (Node n : neighbors) { ImmutableSet<Node.Kind> possibilities = puzzle.possibilities(a, n); if (!possibilities.contains(Node.Kind.NONE)) ++knownColored; if (possibilities.stream().noneMatch(Node.Kind::isColored)) ++knownNone; } int unknown = neighbors.size() - knownColored - knownNone; if (knownColored > a.desiredEdges()) throw new ContradictionException(); if (knownColored + unknown < a.desiredEdges()) throw new ContradictionException(); if (unknown == 0) continue; //All unknown possibilities are NONE. if (knownColored == a.desiredEdges()) for (Node n : neighbors) { ImmutableSet<Node.Kind> possibilities = puzzle.possibilities(a, n); if (possibilities.contains(Node.Kind.NONE) && possibilities.stream().anyMatch(Node.Kind::isColored)) puzzle = puzzle.set(a, n, Node.Kind.NONE); } //All unknown possibilities are not NONE (but we don't know which color). else if (knownColored + unknown == a.desiredEdges()) for (Node n : neighbors) { ImmutableSet<Node.Kind> possibilities = puzzle.possibilities(a, n); if (possibilities.contains(Node.Kind.NONE) && possibilities.stream().anyMatch(Node.Kind::isColored)) puzzle = puzzle.remove(a, n, Node.Kind.NONE); } } return puzzle; }
From source file:dagger.internal.codegen.DuplicateBindingsValidation.java
private String incompatibleBindingsMessage(DependencyRequest dependencyRequest, ImmutableSet<BindingNode> duplicateBindings, BindingGraph graph) { ImmutableSet<BindingNode> multibindings = duplicateBindings.stream() .filter(node -> node.binding().kind().isMultibinding()).collect(toImmutableSet()); verify(multibindings.size() == 1, "expected only one multibinding for %s: %s", dependencyRequest, multibindings);/*from w w w . jav a 2 s . c om*/ StringBuilder message = new StringBuilder(); java.util.Formatter messageFormatter = new java.util.Formatter(message); messageFormatter.format("%s has incompatible bindings or declarations:\n", dependencyRequest.key()); message.append(INDENT); BindingNode multibinding = getOnlyElement(multibindings); messageFormatter.format("%s bindings and declarations:", multibindingTypeString(multibinding)); formatDeclarations(message, 2, declarations(graph, multibindings)); Set<BindingNode> uniqueBindings = Sets.filter(duplicateBindings, binding -> !binding.equals(multibinding)); message.append(INDENT).append("Unique bindings and declarations:"); formatDeclarations(message, 2, Sets.filter(declarations(graph, uniqueBindings), declaration -> !(declaration instanceof MultibindingDeclaration))); return message.toString(); }
From source file:com.zuppelli.living.docs.ContextAwareDiagramMojo.java
protected void populateAssociations(ImmutableSet<ClassPath.ClassInfo> allClasses, final DotGraph.Digraph digraph) { Stream<ClassPath.ClassInfo> infra; infra = allClasses.stream().filter(ClassInfoFilters.filterNot(this.packages)); infra.forEach(new ClassRelationshipConsumer(digraph, getShowDeprecated())); for (Map.Entry<String, String> entry : this.packages.entrySet()) { Stream<ClassPath.ClassInfo> domain = allClasses.stream() .filter(ClassInfoFilters.filter(entry.getKey())); domain.forEach(new ClassRelationshipConsumer(digraph, getShowDeprecated())); }/* w w w. j av a 2 s . com*/ }
From source file:edu.wpi.checksims.algorithm.similaritymatrix.output.MatrixThresholdPrinter.java
/** * Print significant results in a similarity matrix. * * @param matrix Matrix to print//from w ww . j a v a 2 s . c o m * @return Results in matrix over threshold * @throws InternalAlgorithmError Thrown on internal error processing matrix */ @Override public String printMatrix(SimilarityMatrix matrix) throws InternalAlgorithmError { checkNotNull(matrix); StringBuilder builder = new StringBuilder(); DecimalFormat formatter = new DecimalFormat("0.##"); ImmutableSet<AlgorithmResults> results = matrix.getBaseResults(); Set<AlgorithmResults> filteredBelowThreshold = results.stream() .filter((result) -> result.percentMatchedA() >= threshold || result.percentMatchedB() >= threshold) .collect(Collectors.toCollection(HashSet::new)); if (filteredBelowThreshold.isEmpty()) { builder.append("No significant matches found.\n"); } // Loop until all results over threshold consumed while (!filteredBelowThreshold.isEmpty()) { // Find the largest single result double largest = 0.00; AlgorithmResults largestResult = Iterables.get(filteredBelowThreshold, 0); for (AlgorithmResults result : filteredBelowThreshold) { if (result.percentMatchedA() > largest) { largest = result.percentMatchedA(); largestResult = result; } if (result.percentMatchedB() > largest) { largest = result.percentMatchedB(); largestResult = result; } } double largerOfTwo; double smallerOfTwo; Submission largerSubmission; Submission smallerSubmission; if (largestResult.percentMatchedA() >= largestResult.percentMatchedB()) { largerOfTwo = largestResult.percentMatchedA() * 100; smallerOfTwo = largestResult.percentMatchedB() * 100; largerSubmission = largestResult.a; smallerSubmission = largestResult.b; } else { largerOfTwo = largestResult.percentMatchedB() * 100; smallerOfTwo = largestResult.percentMatchedA() * 100; largerSubmission = largestResult.b; smallerSubmission = largestResult.a; } // We have the largest single result, print it builder.append("Found match of "); builder.append(formatter.format(largerOfTwo)); builder.append("% (inverse match "); builder.append(formatter.format(smallerOfTwo)); builder.append("%) between submissions \""); builder.append(largerSubmission.getName()); builder.append("\" and \""); builder.append(smallerSubmission.getName()); builder.append("\"\n"); // Remove the largest results filteredBelowThreshold.remove(largestResult); } return builder.toString(); }
From source file:net.lldp.checksims.algorithm.similaritymatrix.output.MatrixThresholdPrinter.java
/** * Print significant results in a similarity matrix. * * @param matrix Matrix to print//from ww w . j a v a 2 s .c o m * @return Results in matrix over threshold * @throws InternalAlgorithmError Thrown on internal error processing matrix */ @Override public String printMatrix(SimilarityMatrix matrix) throws InternalAlgorithmError { checkNotNull(matrix); StringBuilder builder = new StringBuilder(); DecimalFormat formatter = new DecimalFormat("0.##"); ImmutableSet<AlgorithmResults> results = matrix.getBaseResults(); Set<AlgorithmResults> filteredBelowThreshold = results.stream().filter( (result) -> result.percentMatchedA().gtEQ(threshold) || result.percentMatchedB().gtEQ(threshold)) .collect(Collectors.toCollection(HashSet::new)); if (filteredBelowThreshold.isEmpty()) { builder.append("No significant matches found.\n"); } // Loop until all results over threshold consumed while (!filteredBelowThreshold.isEmpty()) { // Find the largest single result Real largest = Real.ZERO; AlgorithmResults largestResult = Iterables.get(filteredBelowThreshold, 0); for (AlgorithmResults result : filteredBelowThreshold) { if (result.percentMatchedA().greaterThan(largest)) { largest = result.percentMatchedA(); largestResult = result; } if (result.percentMatchedB().greaterThan(largest)) { largest = result.percentMatchedB(); largestResult = result; } } Real largerOfTwo; Real smallerOfTwo; Submission largerSubmission; Submission smallerSubmission; if (largestResult.percentMatchedA().greaterThanEqualTo(largestResult.percentMatchedB())) { largerOfTwo = largestResult.percentMatchedA().multiply(new Real(100)); smallerOfTwo = largestResult.percentMatchedB().multiply(new Real(100)); largerSubmission = largestResult.a; smallerSubmission = largestResult.b; } else { largerOfTwo = largestResult.percentMatchedB().multiply(new Real(100)); smallerOfTwo = largestResult.percentMatchedA().multiply(new Real(100)); largerSubmission = largestResult.b; smallerSubmission = largestResult.a; } // We have the largest single result, print it builder.append("Found match of "); builder.append(formatter.format(largerOfTwo.asDouble())); builder.append("% (inverse match "); builder.append(formatter.format(smallerOfTwo.asDouble())); builder.append("%) between submissions \""); builder.append(largerSubmission.getName()); builder.append("\" and \""); builder.append(smallerSubmission.getName()); builder.append("\"\n"); // Remove the largest results filteredBelowThreshold.remove(largestResult); } return builder.toString(); }
From source file:com.olacabs.fabric.compute.pipeline.NotificationBus.java
public synchronized void publish(PipelineMessage message, int from, boolean forward) { switch (message.getMessageType()) { case TIMER:// w ww . j a va 2 s. c om // It is a timer message, ACKing is disabled comms.get(from).commsChannel.publish(message); break; case USERSPACE: // It is a userspace message, ACKing is enabled PipelineMessage actionableMessage = message; ImmutableSet.Builder<EventSet> ackCandidatesBuilder = ImmutableSet.builder(); if (!message.getMessages().isAggregate()) { // Find out the oldest ancestor of this event set while (true) { if (null == actionableMessage.getParent()) { break; } actionableMessage = actionableMessage.getParent(); } if (!tracker.containsKey(actionableMessage.getMessages().getId())) { // Set up the tracker for this event set since it is sent from a source for the first time // Add this event set to the tracker with an empty bitset tracker.put(actionableMessage.getMessages().getId(), new SimpleBitSet(64)); } SimpleBitSet msgBitSet = tracker.get(actionableMessage.getMessages().getId()); try { // If the event set is being sent forward and the sender sends normal message, set bits // for each of the receivers based on the auto incremented id assigned to them if (forward && connections.containsKey(from) && ((comms.containsKey(from) && comms.get(from).pipelineStage.sendsNormalMessage()) || !comms.containsKey(from))) { connections.get(from).pipelineStages.stream().forEach(msgBitSet::set); } } catch (Exception e) { LOGGER.error("Error setting tracking bits for generator: {}", from, e); } // unset the bit corresponding to the sender msgBitSet.unset(from); // if all the bits are unset and if this event set is generated by a source, mark the // event set as a candidate for ACKing if (!msgBitSet.hasSetBits() && actionableMessage.getMessages().isSourceGenerated()) { ackCandidatesBuilder.add(actionableMessage.getMessages()); } } try { // publish the message to each of the receivers if (forward && connections.containsKey(from)) { connections.get(from).pipelineStages.stream() .forEach(pipeLineStage -> comms.get(pipeLineStage).commsChannel.publish(message)); } } catch (Throwable t) { LOGGER.error("Error sending event to children for {}", from, t); } // event sets which are eligible for ACKing ImmutableSet<EventSet> ackSet = ackCandidatesBuilder.build(); // ACK all the event sets ackSet.stream().forEach(eventSet -> sources.get(eventSet.getSourceId()).ackMessage(eventSet)); // No event set to ACK, hence we can remove the tracker entry for this event set if (!ackSet.isEmpty()) { tracker.remove(actionableMessage.getMessages().getId()); } break; default: break; } }
From source file:dagger.internal.codegen.DuplicateBindingsValidator.java
private String incompatibleBindingsMessage(Key key, ImmutableSet<Binding> duplicateBindings, BindingGraph graph) {// w w w . j a v a 2 s . co m ImmutableSet<dagger.model.Binding> multibindings = duplicateBindings.stream() .filter(binding -> binding.kind().isMultibinding()).collect(toImmutableSet()); verify(multibindings.size() == 1, "expected only one multibinding for %s: %s", key, multibindings); StringBuilder message = new StringBuilder(); java.util.Formatter messageFormatter = new java.util.Formatter(message); messageFormatter.format("%s has incompatible bindings or declarations:\n", key); message.append(INDENT); dagger.model.Binding multibinding = getOnlyElement(multibindings); messageFormatter.format("%s bindings and declarations:", multibindingTypeString(multibinding)); formatDeclarations(message, 2, declarations(graph, multibindings)); Set<dagger.model.Binding> uniqueBindings = Sets.filter(duplicateBindings, binding -> !binding.equals(multibinding)); message.append('\n').append(INDENT).append("Unique bindings and declarations:"); formatDeclarations(message, 2, Sets.filter(declarations(graph, uniqueBindings), declaration -> !(declaration instanceof MultibindingDeclaration))); return message.toString(); }