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:dagger.internal.codegen.FrameworkDependency.java

/**
 * The framework dependencies of {@code binding}. There will be one element for each
 * different binding key in the <em>{@linkplain Binding#unresolved() unresolved}</em> version of
 * {@code binding}.//from  ww w  . j ava 2 s .c o  m
 *
 * <p>For example, given the following modules:
 * <pre><code>
 *   {@literal @Module} abstract class {@literal BaseModule<T>} {
 *     {@literal @Provides} Foo provideFoo(T t, String string) {
 *       return ;
 *     }
 *   }
 *
 *   {@literal @Module} class StringModule extends {@literal BaseModule<String>} {}
 * </code></pre>
 *
 * Both dependencies of {@code StringModule.provideFoo} have the same binding key:
 * {@code String}. But there are still two dependencies, because in the unresolved binding they
 * have different binding keys:
 *
 * <dl>
 * <dt>{@code T} <dd>{@code String t}
 * <dt>{@code String} <dd>{@code String string}
 * </dl>
 * 
 * <p>Note that the sets returned by this method when called on the same binding will be equal,
 * and their elements will be in the same order.
 */
/* TODO(dpb): The stable-order postcondition is actually hard to verify in code for two equal
 * instances of Binding, because it really depends on the order of the binding's dependencies,
 * and two equal instances of Binding may have the same dependencies in a different order. */
static ImmutableSet<FrameworkDependency> frameworkDependenciesForBinding(Binding binding) {
    DependencyRequestMapper dependencyRequestMapper = DependencyRequestMapper
            .forBindingType(binding.bindingType());
    ImmutableSet.Builder<FrameworkDependency> frameworkDependencies = ImmutableSet.builder();
    for (Collection<DependencyRequest> requests : groupByUnresolvedKey(binding)) {
        frameworkDependencies.add(new AutoValue_FrameworkDependency(
                getOnlyElement(FluentIterable.from(requests).transform(DependencyRequest.BINDING_KEY_FUNCTION)
                        .toSet()),
                dependencyRequestMapper.getFrameworkClass(requests), ImmutableSet.copyOf(requests)));
    }
    return frameworkDependencies.build();
}

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

/**
 * Gets the union of response codes within two {@link ImmutableList} of {@link Ds3ResponseCode}
 *///from  www  . j a v a 2s .co m
private static ImmutableSet<Integer> getResponseCodeUnion(final ImmutableList<Ds3ResponseCode> oldCodes,
        final ImmutableList<Ds3ResponseCode> newCodes) {
    final ImmutableSet.Builder<Integer> builder = ImmutableSet.builder();
    if (hasContent(oldCodes)) {
        oldCodes.forEach(code -> builder.add(code.getCode()));
    }
    if (hasContent(newCodes)) {
        newCodes.forEach(code -> builder.add(code.getCode()));
    }
    return builder.build();
}

From source file:org.sosy_lab.cpachecker.cpa.pointer2.util.ExplicitLocationSet.java

public static LocationSet from(Iterable<? extends String> pLocations) {
    Iterator<? extends String> elementIterator = pLocations.iterator();
    if (!elementIterator.hasNext()) {
        return LocationSetBot.INSTANCE;
    }/*from   w  w w  . ja  v a  2  s.  c  om*/
    ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    while (elementIterator.hasNext()) {
        String location = elementIterator.next();
        builder.add(location);
    }
    return new ExplicitLocationSet(builder.build());
}

From source file:com.spectralogic.ds3contractcomparator.print.htmlprinter.generators.row.ModifiedHtmlRowGenerator.java

/**
 * Gets the set of property values from a list of objects
 *//*from   w w  w  . j  a v a2  s  .co  m*/
static <T> ImmutableSet<String> getPropertyValues(final ImmutableList<T> list, final String property) {
    if (isEmpty(list)) {
        return ImmutableSet.of();
    }
    final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    list.forEach(o -> {
        try {
            builder.add(BeanUtils.getProperty(o, property));
        } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
            LOG.error("Cannot create property union of objects from class " + o.getClass().toString()
                    + " using property " + property + ": " + e.getMessage(), e);
        }
    });

    return builder.build();
}

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

/**
 * Gets the union of names of all params within two {@link ImmutableList} of {@link Ds3EnumConstant}
 *//*from  w ww .  j ava  2 s. c o m*/
private static ImmutableSet<String> getEnumConstantNameUnion(final ImmutableList<Ds3EnumConstant> oldEnums,
        final ImmutableList<Ds3EnumConstant> newEnums) {
    final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    if (hasContent(oldEnums)) {
        oldEnums.forEach(enumConstant -> builder.add(enumConstant.getName()));
    }
    if (hasContent(newEnums)) {
        newEnums.forEach(enumConstant -> builder.add(enumConstant.getName()));
    }
    return builder.build();
}

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

/**
 * Gets the union of names of all params within two {@link ImmutableList} of {@link Ds3Element}
 *//*from  w w w  .  j  a  v  a 2  s.c o m*/
private static ImmutableSet<String> getElementNameUnion(final ImmutableList<Ds3Element> oldElements,
        final ImmutableList<Ds3Element> 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:edu.jhu.hlt.tift.Rewriter.java

private static Set<PatternStringTuple> convertStringArrayPatternsToTupleSet(String[] patternArray) {
    ImmutableSet.Builder<PatternStringTuple> patterns = new ImmutableSet.Builder<>();
    for (int i = 0; i < patternArray.length - 1; i += 2)
        patterns.add(new PatternStringTuple(Pattern.compile(patternArray[i], Pattern.MULTILINE),
                patternArray[i + 1]));/*from  w w w. j a v a2  s  .com*/

    return patterns.build();
}

From source file:org.apache.aurora.scheduler.filter.SchedulingFilterImpl.java

private static void maybeAddVeto(ImmutableSet.Builder<Veto> vetoes, ResourceType resourceType, double available,
        double requested) {

    double tooLarge = requested - available;
    if (tooLarge > 0) {
        vetoes.add(Veto.insufficientResources(resourceType.getAuroraName(),
                scale(tooLarge, resourceType.getScalingRange())));
    }/* w ww.java 2s  .  c  o m*/
}

From source file:com.android.build.gradle.internal.dsl.AbiSplitOptions.java

/**
 * Returns the list of actual abi filters, each value of the collection is guaranteed to be non
 * null and of the possible API value.//  w  w  w .ja v  a2  s .co m
 * @param allFilters list of applicable filters {@see #getApplicationFilters}
 */
@NonNull
public static ImmutableSet<String> getAbiFilters(@NonNull Set<String> allFilters) {
    ImmutableSet.Builder<String> filters = ImmutableSet.builder();
    for (@Nullable
    String abi : allFilters) {
        // use object equality since abi can be null.
        //noinspection StringEquality
        if (abi != OutputFile.NO_FILTER) {
            filters.add(abi);
        }
    }
    return filters.build();
}

From source file:com.facebook.buck.hashing.PathHashing.java

public static ImmutableSet<Path> hashPath(Hasher hasher, FileHashLoader fileHashLoader,
        ProjectFilesystem projectFilesystem, Path root) throws IOException {
    Preconditions.checkArgument(!root.equals(EMPTY_PATH), "Path to hash (%s) must not be empty", root);
    ImmutableSet.Builder<Path> children = ImmutableSet.builder();
    for (Path path : ImmutableSortedSet.copyOf(projectFilesystem.getFilesUnderPath(root))) {
        StringHashing.hashStringAndLength(hasher, MorePaths.pathWithUnixSeparators(path));
        if (!root.equals(path)) {
            children.add(root.relativize(path));
        }/*from w ww  .  j  av  a2  s.  c om*/
        hasher.putBytes(fileHashLoader.get(projectFilesystem.resolve(path)).asBytes());
    }
    return children.build();
}