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:org.ambraproject.wombat.config.site.SiteRequestCondition.java

/**
 * Get the set of patterns mapped for a request handler across all sites.
 *
 * @param siteSet     the set of all sites
 * @param baseMapping the unmodified annotation on the request handler
 * @return all patterns that are mapped to the request handler for any site in the set
 *///w w w .  j av  a 2s  .  c  o  m
public static Set<String> getAllPatterns(SiteSet siteSet, RequestMappingContext baseMapping) {
    if (baseMapping.isSiteless()) {
        return ImmutableSet.of(baseMapping.getPattern());
    }
    Set<RequestMappingContext> mappings = buildPatternMap(siteSet, baseMapping).keySet();
    ImmutableSet.Builder<String> patterns = ImmutableSet.builder();
    for (RequestMappingContext mapping : mappings) {
        patterns.add(mapping.getPattern());
    }
    return patterns.build();
}

From source file:org.ambraproject.rhino.service.impl.ArticleListCrudServiceImpl.java

private static String buildMissingArticleMessage(Collection<Article> foundArticles,
        Collection<String> requestedArticleKeys) {
    ImmutableSet.Builder<String> foundArticleKeys = ImmutableSet.builder();
    for (Article foundArticle : foundArticles) {
        foundArticleKeys.add(foundArticle.getDoi());
    }//from   www .j a va2s.c  o m

    Collection<String> missingKeys = Sets.difference(ImmutableSet.copyOf(requestedArticleKeys),
            foundArticleKeys.build());
    missingKeys = new ArrayList<>(missingKeys); // coerce to a type that Gson can handle
    return "Articles not found with DOIs: " + new Gson().toJson(missingKeys);
}

From source file:org.openspotlight.common.util.SLCollections.java

public static <T> Iterable<T> iterableOf(final T t, final T... ts) {
    final ImmutableSet.Builder<T> builder = ImmutableSet.builder();
    builder.add(t);
    if (ts != null) {
        for (final T tn : ts) {
            builder.add(tn);//  www .  j a  v a 2  s.co m
        }
    }
    return builder.build();
}

From source file:org.lanternpowered.server.data.type.LanternSkinPart.java

/**
 * Converts the bit pattern into a set of skin parts.
 *
 * @param bitPattern the bit pattern/*from  w w  w. j  av  a2 s .  c om*/
 * @return the skin parts
 */
public static Set<SkinPart> fromBitPattern(int bitPattern) {
    final ImmutableSet.Builder<SkinPart> parts = ImmutableSet.builder();
    final int count = Integer.bitCount(bitPattern);
    for (int i = 0; i < count; i++) {
        final LanternSkinPart part = lookup.get(i);
        if (part != null && (bitPattern & part.mask) != 0) {
            parts.add(part);
        }
    }
    return parts.build();
}

From source file:com.facebook.buck.apple.AppleResources.java

public static ImmutableSet<AppleResourceDescription.Arg> collectDirectResources(TargetGraph targetGraph,
        TargetNode<?, ?> targetNode) {
    ImmutableSet.Builder<AppleResourceDescription.Arg> builder = ImmutableSet.builder();
    Iterable<TargetNode<?, ?>> deps = targetGraph.getAll(targetNode.getDeps());
    for (TargetNode<?, ?> node : deps) {
        if (node.getDescription() instanceof AppleResourceDescription) {
            builder.add((AppleResourceDescription.Arg) node.getConstructorArg());
        }//from   w  w w . j  a  va 2 s  .  c  om
    }
    return builder.build();
}

From source file:com.sun.tools.hat.internal.util.Misc.java

public static ImmutableSet<JavaHeapObject> getReferees(Iterable<JavaHeapObject> instances,
        final Predicate<JavaHeapObject> filter) {
    final ImmutableSet.Builder<JavaHeapObject> builder = ImmutableSet.builder();
    for (JavaHeapObject instance : instances) {
        instance.visitReferencedObjects(obj -> {
            if (filter.apply(obj)) {
                builder.add(obj);
            }//  w  w w .  j  a  v  a  2 s  .  c om
        });
    }
    return builder.build();
}

From source file:org.openspotlight.common.util.SLCollections.java

public static <T> Iterable<T> iterableOfAll(final Iterable<T> iterable, final Iterable<T>... iterables) {
    final ImmutableSet.Builder<Iterable<T>> builder = ImmutableSet.builder();
    builder.add(iterable);
    for (final Iterable<T> it : iterables) {
        builder.add(it);//  www.  j a va 2  s  .  c  om
    }
    return iterableOfAll(builder.build());
}

From source file:com.google.devtools.build.lib.rules.objc.TargetDeviceFamily.java

/**
 * Converts the {@code TARGETED_DEVICE_FAMILY} setting in build settings to a set of
 * {@code TargetedDevice}s./*w  w  w .j  av a2s . co  m*/
 */
public static Set<TargetDeviceFamily> fromBuildSetting(String targetedDevice) {
    ImmutableSet.Builder<TargetDeviceFamily> result = ImmutableSet.builder();
    for (String numericSetting : Splitter.on(',').split(targetedDevice)) {
        numericSetting = numericSetting.trim();
        switch (numericSetting) {
        case "1":
            result.add(IPHONE);
            break;
        case "2":
            result.add(IPAD);
            break;
        default:
            throw new IllegalArgumentException("Expect comma-separated list containing only '1' and/or '2' for "
                    + "TARGETED_DEVICE_FAMILY: " + targetedDevice);
        }
    }
    return result.build();
}

From source file:com.plvision.switchover.fwd.PathFinder.java

/**
 * Searching of primary and backup paths between two devices.
 * //from w  w w  . ja va  2  s .c  om
 * @param service - topology service
 * @param src - source device Id
 * @param dst - destination device Id
 * 
 * @return set of paths
 */
public static Set<Path> result(TopologyService service, DeviceId src, DeviceId dst) {
    ImmutableSet.Builder<Path> builder = ImmutableSet.builder();
    Set<Path> paths1 = service.getPaths(service.currentTopology(), src, dst);
    Set<DisjointPath> paths2 = service.getDisjointPaths(service.currentTopology(), src, dst);
    paths1.forEach(path -> {
        builder.add(path);
    });
    paths2.forEach(path -> {
        builder.add(path.backup());
    });
    return builder.build();
}

From source file:com.facebook.buck.android.ClassNameFilter.java

/**
 * Convenience factory to produce a filter from a very simple pattern language.
 *
 * <p>patterns are substrings by default, but {@code ^} at the start or end of a pattern
 * anchors it to the start or end of the class name.
 *
 * @param patterns  Patterns to include in the filter.
 * @return  A new filter./*from  w w  w . ja  va  2s  .  co  m*/
 */
public static ClassNameFilter fromConfiguration(Iterable<String> patterns) {
    ImmutableList.Builder<String> prefixes = ImmutableList.builder();
    ImmutableList.Builder<String> suffixes = ImmutableList.builder();
    ImmutableList.Builder<String> substrings = ImmutableList.builder();
    ImmutableSet.Builder<String> exactMatches = ImmutableSet.builder();

    for (String pattern : patterns) {
        boolean isPrefix = pattern.charAt(0) == '^';
        boolean isSuffix = pattern.charAt(pattern.length() - 1) == '^';
        if (isPrefix && isSuffix) {
            exactMatches.add(pattern.substring(1, pattern.length() - 1));
        } else if (isPrefix) {
            prefixes.add(pattern.substring(1));
        } else if (isSuffix) {
            suffixes.add(pattern.substring(0, pattern.length() - 1));
        } else {
            substrings.add(pattern);
        }
    }

    return new ClassNameFilter(prefixes.build(), suffixes.build(), substrings.build(), exactMatches.build());
}