Example usage for com.google.common.collect ImmutableSet.Builder add

List of usage examples for com.google.common.collect ImmutableSet.Builder add

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSet.Builder add.

Prototype

boolean add(E e);

Source Link

Document

Adds the specified element to this set if it is not already present (optional operation).

Usage

From source file:edu.mit.streamjit.util.ReflectionUtils.java

public static <T> ImmutableSet<Class<?>> getAllSupertypes(Class<T> klass) {
    ImmutableSet.Builder<Class<?>> builder = ImmutableSet.builder();
    builder.add(klass);
    for (Class<?> c : klass.getInterfaces())
        builder.add(c);/*from w ww .j  a  v  a2  s.co  m*/
    if (klass.getSuperclass() != null)
        builder.addAll(getAllSupertypes(klass.getSuperclass()));
    return builder.build();
}

From source file:org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory.java

private static ImmutableSet<String> validateBaseCapabilities(final Set<String> baseCapabilities) {
    // Check base capabilities to be supported by the server
    final Sets.SetView<String> unknownBaseCaps = Sets.difference(baseCapabilities, DEFAULT_BASE_CAPABILITIES);
    Preconditions.checkArgument(unknownBaseCaps.isEmpty(),
            "Base capabilities that will be supported by netconf server have to be subset of %s, unknown base capabilities: %s",
            DEFAULT_BASE_CAPABILITIES, unknownBaseCaps);

    final ImmutableSet.Builder<String> b = ImmutableSet.builder();
    b.addAll(baseCapabilities);//from  www .j  a  va 2s  .  c o  m
    // Base 1.0 capability is supported by default
    b.add(XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_0);
    return b.build();
}

From source file:com.calclab.emite.xep.disco.DiscoveryManagerImpl.java

private static final ImmutableSet<Item> parseItems(final XMLPacket query) {
    final ImmutableSet.Builder<Item> builder = ImmutableSet.builder();
    for (final XMLPacket child : query.getChildren("item")) {
        builder.add(new Item(XmppURI.uri(child.getAttribute("jid")), child.getAttribute("name"),
                child.getAttribute("node")));
    }/*  w w w  . j ava2  s.  com*/
    return builder.build();
}

From source file:com.google.devtools.build.lib.skyframe.TransitiveTraversalValue.java

private static ImmutableSet<String> canonicalSet(Iterable<String> strIterable) {
    ImmutableSet.Builder<String> builder = new ImmutableSet.Builder<>();
    for (String str : strIterable) {
        builder.add(StringCanonicalizer.intern(str));
    }/*from w w  w.j  a  va  2 s.c om*/
    return builder.build();
}

From source file:org.eclipse.xtext.xtext.ParameterConfigHelper.java

public static Set<Parameter> getAssignedArguments(RuleCall ruleCall, Set<Parameter> contextParameters) {
    if (!ruleCall.getArguments().isEmpty()) {
        ConditionEvaluator evaluator = new ConditionEvaluator(contextParameters);
        ImmutableSet.Builder<Parameter> result = ImmutableSet.builder();
        for (NamedArgument argument : ruleCall.getArguments()) {
            if (evaluator.evaluate(argument.getValue())) {
                result.add(argument.getParameter());
            }/*from   w w w . j  a v  a 2  s . c om*/
        }
        return result.build();
    } else {
        return Collections.emptySet();
    }
}

From source file:com.calclab.emite.xep.disco.DiscoveryManagerImpl.java

private static final ImmutableSet<Feature> parseFeatures(final XMLPacket query) {
    final ImmutableSet.Builder<Feature> builder = ImmutableSet.builder();
    for (final XMLPacket child : query.getChildren("feature")) {
        builder.add(new Feature(child.getAttribute("var")));
    }//from ww  w .j a  va  2s.c  o  m
    return builder.build();
}

From source file:com.googlecode.jmxtrans.model.ResultAttributes.java

/**
 * Get the {@link ResultAttributes} value for each attribute name.
 *
 * @return Set of {@link ResultAttribute}
 * @see #forName(String)//from   w  w  w. ja  v a  2  s.  co m
 */
public static ImmutableSet<ResultAttribute> forNames(@Nonnull Collection<String> attributeNames) {
    ImmutableSet.Builder<ResultAttribute> builder = ImmutableSet.<ResultAttribute>builder();
    for (String attributeName : attributeNames) {
        builder.add(forName(attributeName));
    }
    return builder.build();
}

From source file:com.facebook.buck.util.MorePosixFilePermissions.java

/**
 * Convert a unix bit representation (e.g. 0644) into a set of posix file permissions.
 *//*from  ww  w .  j av a  2  s . c o  m*/
public static ImmutableSet<PosixFilePermission> fromMode(long mode) {
    ImmutableSet.Builder<PosixFilePermission> permissions = ImmutableSet.builder();

    for (int index = 0; index < ORDERED_PERMISSIONS.size(); index++) {
        if ((mode & (1 << index)) != 0) {
            permissions.add(ORDERED_PERMISSIONS.get(index));
        }
    }

    return permissions.build();
}

From source file:com.facebook.buck.rules.TargetNodeToBuildRuleTransformer.java

private static ImmutableSet<BuildTargetPattern> getVisibilityPatterns(TargetNode<?> targetNode)
        throws NoSuchBuildTargetException {
    ImmutableSet.Builder<BuildTargetPattern> builder = ImmutableSet.builder();
    BuildRuleFactoryParams params = targetNode.getRuleFactoryParams();
    for (String visibility : params.getOptionalListAttribute("visibility")) {
        builder.add(params.buildTargetPatternParser.parse(visibility, ParseContext.forVisibilityArgument()));
    }// w w  w  . j a  va  2s  . c o m
    return builder.build();
}

From source file:alluxio.yarn.YarnUtils.java

/**
 * Returns the host names for all nodes in yarnClient's YARN cluster.
 *
 * @param yarnClient the client to use to look up node information
 * @return the set of host names/*from ww w.  ja  va  2  s  .co m*/
 * @throws YarnException if an error occurs within YARN
 * @throws IOException if an error occurs in YARN's underlying IO
 */
public static Set<String> getNodeHosts(YarnClient yarnClient) throws YarnException, IOException {
    ImmutableSet.Builder<String> nodeHosts = ImmutableSet.builder();
    for (NodeReport runningNode : yarnClient.getNodeReports(USABLE_NODE_STATES)) {
        nodeHosts.add(runningNode.getNodeId().getHost());
    }
    return nodeHosts.build();
}