Java Code Examples for com.google.common.collect.ImmutableSet.Builder

The following are Jave code examples for showing how to use Builder of the com.google.common.collect.ImmutableSet class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: athena   File: ReactiveForwarding.java   View Source Code Vote up 6 votes
private Set<FlowEntry> getFlowRulesFrom(ConnectPoint egress) {
    ImmutableSet.Builder<FlowEntry> builder = ImmutableSet.builder();
    flowRuleService.getFlowEntries(egress.deviceId()).forEach(r -> {
        if (r.appId() == appId.id()) {
            r.treatment().allInstructions().forEach(i -> {
                if (i.type() == Instruction.Type.OUTPUT) {
                    if (((Instructions.OutputInstruction) i).port().equals(egress.port())) {
                        builder.add(r);
                    }
                }
            });
        }
    });

    return builder.build();
}
 
Example 2
Project: athena   File: SegmentRoutingAppConfig.java   View Source Code Vote up 6 votes
/**
 * Gets vRouters from the config.
 *
 * @return Set of vRouter MAC addresses, empty is not specified,
 *         or null if not valid
 */
public Set<MacAddress> vRouterMacs() {
    if (!object.has(VROUTER_MACS)) {
        return ImmutableSet.of();
    }

    ImmutableSet.Builder<MacAddress> builder = ImmutableSet.builder();
    ArrayNode arrayNode = (ArrayNode) object.path(VROUTER_MACS);
    for (JsonNode jsonNode : arrayNode) {
        MacAddress mac;

        String macStr = jsonNode.asText(null);
        if (macStr == null) {
            return null;
        }
        try {
            mac = MacAddress.valueOf(macStr);
        } catch (IllegalArgumentException e) {
            return null;
        }

        builder.add(mac);
    }
    return builder.build();
}
 
Example 3
Project: athena   File: DefaultTopology.java   View Source Code Vote up 6 votes
/**
 * Computes on-demand the set of shortest disjoint path pairs between source and
 * destination devices.
 *
 * @param src    source device
 * @param dst    destination device
 * @param weight link weight function
 * @return set of disjoint shortest path pairs
 */
public Set<DisjointPath> getDisjointPaths(DeviceId src, DeviceId dst, LinkWeight weight) {
    DefaultTopologyVertex srcV = new DefaultTopologyVertex(src);
    DefaultTopologyVertex dstV = new DefaultTopologyVertex(dst);
    Set<TopologyVertex> vertices = graph.getVertexes();
    if (!vertices.contains(srcV) || !vertices.contains(dstV)) {
        // src or dst not part of the current graph
        return ImmutableSet.of();
    }

    GraphPathSearch.Result<TopologyVertex, TopologyEdge> result =
            SUURBALLE.search(graph, srcV, dstV, weight, ALL_PATHS);
    ImmutableSet.Builder<DisjointPath> builder = ImmutableSet.builder();
    for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) {
        builder.add(networkDisjointPath((org.onlab.graph.DisjointPathPair<TopologyVertex, TopologyEdge>) path));
    }
    return builder.build();
}
 
Example 4
Project: ontolib   File: ImmutableOntology.java   View Source Code Vote up 6 votes
/**
 * @return Precomputed map from term id to list of ancestor term ids (a term is its own ancestor).
 */
private ImmutableMap<TermId, ImmutableSet<TermId>> precomputeAncestors() {
  final ImmutableMap.Builder<TermId, ImmutableSet<TermId>> mapBuilder = ImmutableMap.builder();

  for (TermId termId : graph.getVertices()) {
    final ImmutableSet.Builder<TermId> setBuilder = ImmutableSet.builder();
    BreadthFirstSearch<TermId, ImmutableEdge<TermId>> bfs = new BreadthFirstSearch<>();
    bfs.startFromForward(graph, termId, new VertexVisitor<TermId, ImmutableEdge<TermId>>() {
      @Override
      public boolean visit(DirectedGraph<TermId, ImmutableEdge<TermId>> g, TermId v) {
        setBuilder.add(v);
        return true;
      }
    });

    mapBuilder.put(termId, setBuilder.build());
  }

  return mapBuilder.build();
}
 
Example 5
Project: tac-kbp-eal   File: CorpusQueryExecutor2016.java   View Source Code Vote up 5 votes
private ImmutableSet<Symbol> gatherTypes(final EREEvent ereEvent) {
  final ImmutableSet.Builder<Symbol> ret = ImmutableSet.builder();
  for (final EREEventMention ereEventMention : ereEvent.getEventMentions()) {
    final Symbol mappedMainType = ontologyMapper.eventType(
        Symbol.from(ereEventMention.getType())).get();
    final Symbol mappedSubType = ontologyMapper.eventSubtype(
        Symbol.from(ereEventMention.getSubtype())).get();

    ret.add(concat(concat(mappedMainType, "."), mappedSubType));
  }
  return ret.build();
}
 
Example 6
Project: tac-kbp-eal   File: CorpusQueryExecutor2016.java   View Source Code Vote up 5 votes
private void gatherDocumentEventsForResponses(final List<Response> matchingResponses,
    final DocumentSystemOutput2015 docSystemOutput,
    final ImmutableSet.Builder<DocEventFrameReference> retB) {
  final ImmutableSet.Builder<ResponseSet> matchingResponseSetsB = ImmutableSet.builder();
  for (final Response matchingResponse : matchingResponses) {
    matchingResponseSetsB.addAll(docSystemOutput.linking()
        .responsesToContainingResponseSets().get(matchingResponse));
  }
  final ImmutableSet<ResponseSet> matchingResponseSets = matchingResponseSetsB.build();

  for (final ResponseSet matchingResponseSet : matchingResponseSets) {
    retB.add(docSystemOutput.linking().asEventFrameReference(matchingResponseSet));
  }
}
 
Example 7
Project: ArchUnit   File: ArchUnitArchitectureTest.java   View Source Code Vote up 5 votes
private static Set<String> sourceRootsOf(Class<?>... classes) {
    ImmutableSet.Builder<String> result = ImmutableSet.builder();
    for (Class<?> c : classes) {
        String classFile = "/" + c.getName().replace('.', '/') + ".class";
        String file = c.getResource(classFile).getFile();
        result.add(file.substring(0, file.indexOf(classFile)));
    }
    return result.build();
}
 
Example 8
Project: ProjectAres   File: Methods.java   View Source Code Vote up 5 votes
public static Set<Method> ancestors(Method method) {
    if(Members.isPrivate(method)) return Collections.emptySet();

    final ImmutableSet.Builder<Method> builder = ImmutableSet.builder();
    for(Class<?> ancestor : Types.ancestors(method.getDeclaringClass())) {
        final Method sup = overrideIn(ancestor, method);
        if(sup != null) builder.add(sup);
    }
    return builder.build();
}
 
Example 9
Project: Uranium   File: CraftScoreboard.java   View Source Code Vote up 5 votes
public ImmutableSet<Score> getScores(OfflinePlayer player) throws IllegalArgumentException {
    Validate.notNull(player, "OfflinePlayer cannot be null");

    ImmutableSet.Builder<Score> scores = ImmutableSet.builder();
    for (CraftObjective objective : objectives.values()) {
        scores.add(objective.getScore(player));
    }
    return scores.build();
}
 
Example 10
Project: ArchUnit   File: JavaClass.java   View Source Code Vote up 5 votes
@PublicAPI(usage = ACCESS)
public Set<JavaFieldAccess> getFieldAccessesFromSelf() {
    ImmutableSet.Builder<JavaFieldAccess> result = ImmutableSet.builder();
    for (JavaCodeUnit codeUnit : codeUnits) {
        result.addAll(codeUnit.getFieldAccesses());
    }
    return result.build();
}
 
Example 11
Project: athena   File: ApplicationArchive.java   View Source Code Vote up 5 votes
/**
 * Returns the set of installed application names.
 *
 * @return installed application names
 */
public Set<String> getApplicationNames() {
    ImmutableSet.Builder<String> names = ImmutableSet.builder();
    File[] files = appsDir.listFiles(File::isDirectory);
    if (files != null) {
        for (File file : files) {
            names.add(file.getName());
        }
    }
    return names.build();
}
 
Example 12
Project: tac-kbp-eal   File: KBPTIMEXExpression.java   View Source Code Vote up 5 votes
public ImmutableSet<KBPTIMEXExpression> lessSpecificCompatibleTimes() {
  final ImmutableSet.Builder<KBPTIMEXExpression> ret = ImmutableSet.builder();

  final StringBuilder curDay = new StringBuilder(day);
  final StringBuilder curMonth = new StringBuilder(month);
  final StringBuilder curYear = new StringBuilder(year);

  for (int i = 1; i >= 0; --i) {
    if (!isX(curDay.charAt(i))) {
      curDay.setCharAt(i, 'X');
      ret.add(KBPTIMEXExpression.fromYMD(curYear.toString(),
          curMonth.toString(), curDay.toString()));
    }
  }

  for (int i = 1; i >= 0; --i) {
    if (!isX(curMonth.charAt(i))) {
      curMonth.setCharAt(i, 'X');
      ret.add(KBPTIMEXExpression.fromYMD(curYear.toString(),
          curMonth.toString(), curDay.toString()));
    }
  }

  // don't terminate at 0 because all Xes is an invalid year
  for (int i = 3; i >= 1; --i) {
    if (!isX(curYear.charAt(i))) {
      curYear.setCharAt(i, 'X');
      ret.add(KBPTIMEXExpression.fromYMD(curYear.toString(),
          curMonth.toString(), curDay.toString()));
    }
  }

  return ret.build();
}
 
Example 13
Project: dremio-oss   File: DremioDatabaseMetaDataImpl.java   View Source Code Vote up 5 votes
public static final Set<SQLConvertSupport> toSQLConvertSupport(Iterable<ConvertSupport> convertSupportIterable) {
  ImmutableSet.Builder<SQLConvertSupport> sqlConvertSupportSet = ImmutableSet.builder();
  for(ConvertSupport convertSupport: convertSupportIterable) {
    try {
      sqlConvertSupportSet.add(new SQLConvertSupport(
          toSQLType(convertSupport.getFrom()),
          toSQLType(convertSupport.getTo())));
    } catch(IllegalArgumentException e) {
      // Ignore unknown types...
    }
  }
  return sqlConvertSupportSet.build();
}
 
Example 14
Project: sats-core   File: GSVMWorld.java   View Source Code Vote up 5 votes
/**
 * {@inheritDoc}
 *
 * @return An immutable set containing all licenses.
 */
@Override
public ImmutableSet<GSVMLicense> getLicenses() {
    if (licenseSet == null) {
        ImmutableSet.Builder<GSVMLicense> builder = ImmutableSet.builder();
        builder.add(nationalCircle.getLicenses());
        builder.add(regionalCircle.getLicenses());
        licenseSet = builder.build();
    }
    return licenseSet;
}
 
Example 15
Project: Reer   File: GradleApiSpecAggregator.java   View Source Code Vote up 5 votes
private Spec mergeSpecsOf(List<Class<? extends GradleApiSpecProvider>> providers) {
    final ImmutableSet.Builder<String> exportedPackages = ImmutableSet.builder();
    final ImmutableSet.Builder<String> exportedResourcePrefixes = ImmutableSet.builder();
    for (Class<? extends GradleApiSpecProvider> provider : providers) {
        Spec spec = specFrom(provider);
        exportedPackages.addAll(spec.getExportedPackages());
        exportedResourcePrefixes.addAll(spec.getExportedResourcePrefixes());
    }
    return new DefaultSpec(exportedPackages.build(), exportedResourcePrefixes.build());
}
 
Example 16
Project: ArchUnit   File: JavaClass.java   View Source Code Vote up 5 votes
@PublicAPI(usage = ACCESS)
public Set<JavaMethodCall> getMethodCallsToSelf() {
    ImmutableSet.Builder<JavaMethodCall> result = ImmutableSet.builder();
    for (JavaMethod method : methods) {
        result.addAll(method.getCallsOfSelf());
    }
    return result.build();
}
 
Example 17
Project: Reer   File: PlayPluginConfigurations.java   View Source Code Vote up 5 votes
@Override
public FileCollectionInternal createDelegate() {
    ImmutableSet.Builder<File> files = ImmutableSet.builder();
    for (ResolvedArtifact artifact : configuration.getResolvedConfiguration().getResolvedArtifacts()) {
        if ((artifact.getId().getComponentIdentifier() instanceof ProjectComponentIdentifier) == matchProjectComponents) {
            files.add(artifact.getFile());
        }
    }
    return new SimpleFileCollection(files.build());
}
 
Example 18
Project: athena   File: DefaultGraphDescription.java   View Source Code Vote up 5 votes
private ImmutableSet<TopologyEdge> buildEdges(Iterable<Link> links) {
    ImmutableSet.Builder<TopologyEdge> edges = ImmutableSet.builder();
    for (Link link : links) {
        try {
            edges.add(new DefaultTopologyEdge(vertexOf(link.src()),
                                              vertexOf(link.dst()),
                                              link));
        } catch (IllegalArgumentException e) {
            log.debug("Ignoring {}, missing vertex", link);
        }
    }
    return edges.build();
}
 
Example 19
Project: creacoinj   File: Networks.java   View Source Code Vote up 4 votes
public static void register(Collection<? extends NetworkParameters> networks) {
    ImmutableSet.Builder<NetworkParameters> builder = ImmutableSet.builder();
    builder.addAll(Networks.networks);
    builder.addAll(networks);
    Networks.networks = builder.build();
}
 
Example 20
Project: tac-kbp-eal   File: NaiveResponseLinkingProjector.java   View Source Code Vote up 4 votes
public ResponseLinking projectTo(AnswerKey targetAnswerKey) {
  checkState(sourceLinking != null, "You forgot to call from()");
  checkState(targetAnswerKey.docId() == sourceLinking.docID());

  final Function<Response, Optional<TypeRoleFillerRealis>> toEquivalenceClassIfPossible =
      TypeRoleFillerRealis.extractFromSystemResponseIfPossible(
          targetAnswerKey.corefAnnotation().normalizeCASIfPossibleFunction());

  final ImmutableSet.Builder<TypeRoleFillerRealisSet> projectedSetsB =
      ImmutableSet.builder();

  for (final ResponseSet responseSet : sourceLinking.responseSets()) {
    // get the equivalence class for every response for which
    // coref information is available in the target
    final ImmutableSet<TypeRoleFillerRealis> projectedEquivalenceClasSet =
        ImmutableSet.copyOf(Optional.presentInstances(
            transform(responseSet, toEquivalenceClassIfPossible)));
    // empty sets are meaningless and invalid, so no response in the source
    // could be projected to the target, the set isn't projected either
    if (!projectedEquivalenceClasSet.isEmpty()) {
      projectedSetsB.add(TypeRoleFillerRealisSet.from(projectedEquivalenceClasSet));
    }
  }
  final ImmutableSet<TypeRoleFillerRealisSet> projectedSets = projectedSetsB.build();
  final ImmutableSet<TypeRoleFillerRealis> TRFRsInProjection =
      ImmutableSet.copyOf(concat(projectedSets));
  final ImmutableSet<TypeRoleFillerRealis> allTargetTRFRs = ImmutableSet.copyOf(
      Optional.presentInstances(FluentIterable
          .from(targetAnswerKey.annotatedResponses())
          .transform(AssessedResponseFunctions.response())
          .transform(toEquivalenceClassIfPossible)));

  final Set<TypeRoleFillerRealis> projectedIncompletesNotFoundElsewhere =
      Sets.difference(allTargetTRFRs, TRFRsInProjection);

  final EventArgumentLinking projectedEventArgumentLinking = EventArgumentLinking.builder()
      .docID(targetAnswerKey.docId()).eventFrames(projectedSets)
      .incomplete(projectedIncompletesNotFoundElsewhere).build();

  return EventArgumentLinkingAligners.getExactMatchEventArgumentLinkingAligner().alignToResponseLinking(
      projectedEventArgumentLinking, targetAnswerKey);
}