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:ca.cutterslade.match.scheduler.Scheduler.java

private static ImmutableSet<String> setOf(int n) {
    ImmutableSet.Builder<String> b = ImmutableSet.builder();
    for (int i = 0; i < n; i++)
        b.add(String.valueOf(i));
    return b.build();
}

From source file:com.spectralogic.ds3contractcomparator.print.simpleprinter.Ds3AnnotationDiffSimplePrinter.java

/**
 * Gets the union of names of all params within two {@link ImmutableList} of {@link Ds3AnnotationElement}
 *///from w ww.ja  va2 s.  c  om
private static ImmutableSet<String> getAnnotationElementNameUnion(
        final ImmutableList<Ds3AnnotationElement> oldElements,
        final ImmutableList<Ds3AnnotationElement> newElements) {
    final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    if (hasContent(oldElements)) {
        oldElements.forEach(element -> builder.add(element.getName()));
    }
    if (hasContent(newElements)) {
        newElements.forEach(element -> builder.add(element.getName()));
    }
    return builder.build();
}

From source file:org.mule.module.extension.internal.util.CapabilityUtils.java

/**
 * Returns the items in {@code capabilities} which
 * are instances of {@code capabilityType}
 *
 * @param capabilities   a {@link Set} of capabilities
 * @param capabilityType the type of the capabilities you seek
 * @return a sub {@link Set} of {@code capabilities}
 *//*from  w  w  w.j  a  va 2 s.c o m*/
public static <T> Set<T> getCapabilities(Set<?> capabilities, Class<T> capabilityType) {
    ImmutableSet.Builder<T> matches = ImmutableSet.builder();
    for (Object capability : capabilities) {
        if (capabilityType.isInstance(capability)) {
            matches.add((T) capability);
        }
    }

    return matches.build();
}

From source file:com.spectralogic.ds3contractcomparator.print.simpleprinter.Ds3EnumConstantDiffSimplePrinter.java

/**
 * Gets the union of names of all properties within two {@link ImmutableList} of {@link Ds3Property}
 *//*from  w  w  w. j  av a2  s.  c  o  m*/
private static ImmutableSet<String> getPropertyNameUnion(final ImmutableList<Ds3Property> oldProperties,
        final ImmutableList<Ds3Property> newProperties) {
    final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    if (hasContent(oldProperties)) {
        oldProperties.forEach(property -> builder.add(property.getName()));
    }
    if (hasContent(newProperties)) {
        newProperties.forEach(property -> builder.add(property.getName()));
    }
    return builder.build();
}

From source file:net.femtoparsec.remote.Views.java

/**
 * <p>Compute and return the difference between two views (members in both view, members in the first view only, and members in the second view only).
 * It is called difference since it assumes that the first view if chronologically before the second view.</p>
 *
 * @param first the first view// w w  w .  java  2  s. com
 * @param second the second view
 * @return the view difference
 */
public static ViewDifference getDifference(View first, View second) {
    Objects.requireNonNull(second, "to");

    final DefaultViewDifference.Builder builder = DefaultViewDifference.builder();

    builder.setFrom(first).setTo(second);

    Set<Address> leftMembers = new HashSet<>();

    if (first != null) {
        //assume that all members have left the view
        leftMembers.addAll(first.getMembers());
    }

    ImmutableSet.Builder<Address> newMembersBuilder = ImmutableSet.builder();
    ImmutableSet.Builder<Address> unchangedMembersBuilder = ImmutableSet.builder();

    for (Address member : second) {
        if (leftMembers.remove(member)) {
            unchangedMembersBuilder.add(member);
        } else {
            newMembersBuilder.add(member);
        }
    }

    builder.setLeftMembers(ImmutableSet.copyOf(leftMembers)).setNewMembers(newMembersBuilder.build())
            .setUnchangedMembers(unchangedMembersBuilder.build());

    return builder.build();
}

From source file:com.spotify.heroic.common.FeatureSet.java

@JsonCreator
public static FeatureSet create(final Set<String> features) {
    final ImmutableSet.Builder<Feature> enabled = ImmutableSet.builder();
    final ImmutableSet.Builder<Feature> disabled = ImmutableSet.builder();

    for (final String feature : features) {
        if (feature.startsWith("-")) {
            disabled.add(Feature.create(feature.substring(1)));
        } else {//w  w  w . ja  va  2s.  c o m
            enabled.add(Feature.create(feature));
        }
    }

    return new FeatureSet(enabled.build(), disabled.build());
}

From source file:com.google.devtools.build.lib.syntax.LValue.java

private static void collectBoundNames(Expression lhs, ImmutableSet.Builder<String> result) {
    if (lhs instanceof Identifier) {
        result.add(((Identifier) lhs).getName());
        return;/*ww  w .j a  v a  2 s . co m*/
    }
    if (lhs instanceof ListLiteral) {
        ListLiteral variables = (ListLiteral) lhs;
        for (Expression expression : variables.getElements()) {
            collectBoundNames(expression, result);
        }
    }
}

From source file:org.bitcoinj.params.Networks.java

public static void unregister(NetworkParameters network) {
    if (networks.contains(network)) {
        ImmutableSet.Builder<NetworkParameters> builder = ImmutableSet.builder();
        for (NetworkParameters parameters : networks) {
            if (parameters.equals(network))
                continue;
            builder.add(parameters);
        }//from  www .  j ava 2 s.  c o m
        networks = builder.build();
    }
}

From source file:com.facebook.buck.rules.visibility.VisibilityPatterns.java

@SuppressWarnings("unchecked")
public static ImmutableSet<VisibilityPattern> createFromStringList(CellPathResolver cellNames, String paramName,
        @Nullable Object value, UnconfiguredBuildTarget target) {
    if (value == null) {
        return ImmutableSet.of();
    }//  ww  w  .j  a  v a 2s.co m
    if (!(value instanceof List)) {
        throw new RuntimeException(String.format("Expected an array for %s but was %s", paramName, value));
    }
    List<String> originalPatterns = (List<String>) value;
    ImmutableSet.Builder<VisibilityPattern> patterns = ImmutableSet
            .builderWithExpectedSize(originalPatterns.size());
    for (String visibility : originalPatterns) {
        try {
            patterns.add(VisibilityPatternParser.parse(cellNames, visibility));
        } catch (IllegalArgumentException e) {
            throw new HumanReadableException(e,
                    "Bad visibility expression: %s listed %s in its %s argument, but only %s "
                            + "or fully qualified target patterns are allowed (i.e. those starting with "
                            + "// or a cell).",
                    target.getFullyQualifiedName(), visibility, paramName,
                    VisibilityPatternParser.VISIBILITY_PUBLIC);
        }
    }
    return patterns.build();
}

From source file:android.keystore.cts.Asn1Utils.java

public static Set<Integer> getIntegersFromAsn1Set(ASN1Encodable set) throws CertificateParsingException {
    if (!(set instanceof ASN1Set)) {
        throw new CertificateParsingException("Expected set, found " + set.getClass().getName());
    }//www . j  a  v  a 2  s .com

    ImmutableSet.Builder<Integer> builder = ImmutableSet.builder();
    for (Enumeration<?> e = ((ASN1Set) set).getObjects(); e.hasMoreElements();) {
        builder.add(getIntegerFromAsn1((ASN1Integer) e.nextElement()));
    }
    return builder.build();
}