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

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

Introduction

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

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

Usage

From source file:org.terasology.assets.management.AssetManager.java

/**
 * Retrieves a list of all loaded assets of the given Asset class (including subtypes)
 *
 * @param type The Asset class of interest
 * @param <T>  The Asset class/*from  w w  w  .ja  v a 2s. co  m*/
 * @param <U>  The AssetData class
 * @return A list of all the loaded assets
 */
public <T extends Asset<U>, U extends AssetData> Set<T> getLoadedAssets(Class<T> type) {
    List<AssetType<? extends T, ?>> assetTypes = assetTypeManager.getAssetTypes(type);
    switch (assetTypes.size()) {
    case 0:
        return Collections.emptySet();
    default:
        ImmutableSet.Builder<T> builder = ImmutableSet.builder();
        for (AssetType<? extends T, ?> assetType : assetTypes) {
            builder.addAll(assetType.getLoadedAssets());
        }
        return builder.build();
    }
}

From source file:com.google.devtools.build.lib.sandbox.DarwinSandboxedStrategy.java

@Override
protected ImmutableSet<Path> getWritableDirs(Path sandboxExecRoot, Map<String, String> env) {
    FileSystem fs = sandboxExecRoot.getFileSystem();
    ImmutableSet.Builder<Path> writableDirs = ImmutableSet.builder();

    writableDirs.addAll(super.getWritableDirs(sandboxExecRoot, env));
    writableDirs.add(fs.getPath("/dev"));

    String sysTmpDir = System.getenv("TMPDIR");
    if (sysTmpDir != null) {
        writableDirs.add(fs.getPath(sysTmpDir));
    }/*from  w w  w . ja v a  2s  .com*/

    writableDirs.add(fs.getPath("/tmp"));

    // ~/Library/Cache and ~/Library/Logs need to be writable (cf. issue #2231).
    Path homeDir = fs.getPath(System.getProperty("user.home"));
    writableDirs.add(homeDir.getRelative("Library/Cache"));
    writableDirs.add(homeDir.getRelative("Library/Logs"));

    // Other temporary directories from getconf.
    for (Path path : confPaths) {
        if (path.exists()) {
            writableDirs.add(path);
        }
    }

    return writableDirs.build();
}

From source file:com.google.devtools.build.lib.packages.RawAttributeMapper.java

/**
 * Variation of {@link #get} that merges the values of configurable lists together (with
 * duplicates removed)./*w  w w  . j  a  va 2s.  c o  m*/
 *
 * <p>For example, given:
 * <pre>
 *   attr = select({
 *       ':condition1': [A, B, C],
 *       ':condition2': [C, D]
 *       }),
 * </pre>
 * this returns the value <code>[A, B, C, D]</code>.
 *
 * <p>If the attribute isn't configurable (e.g. <code>attr = [A, B]</code>), returns
 * its raw value.
 *
 * <p>Throws an {@link IllegalStateException} if the attribute isn't a list type.
 */
@Nullable
public <T> Collection<T> getMergedValues(String attributeName, Type<List<T>> type) {
    Preconditions.checkState(type instanceof Type.ListType);
    if (!isConfigurable(attributeName, type)) {
        return get(attributeName, type);
    }

    ImmutableSet.Builder<T> mergedValues = ImmutableSet.builder();
    for (Selector<List<T>> selector : getSelectorList(attributeName, type).getSelectors()) {
        for (List<T> configuredList : selector.getEntries().values()) {
            mergedValues.addAll(configuredList);
        }
    }
    return mergedValues.build();
}

From source file:com.twitter.aurora.scheduler.filter.SchedulingFilterImpl.java

private Set<Veto> getResourceVetoes(ResourceSlot offer, ITaskConfig task) {
    ImmutableSet.Builder<Veto> builder = ImmutableSet.builder();
    for (FilterRule rule : rulesFromOffer(offer)) {
        builder.addAll(rule.apply(task));
    }//w w w. j a va  2 s .co  m
    return builder.build();
}

From source file:com.facebook.buck.android.relinker.NativeRelinker.java

/**
 * Creates a map from every BuildRule to the set of transitive dependents of that BuildRule that
 * are in the linkableRules set.//from ww  w. j  ava2  s .co m
 */
private ImmutableMap<BuildRule, ImmutableSet<BuildRule>> getAllDependentsMap(Set<BuildRule> linkableRules,
        DirectedAcyclicGraph<BuildRule> graph, ImmutableList<BuildRule> sortedRules) {
    final Map<BuildRule, ImmutableSet<BuildRule>> allDependentsMap = new HashMap<>();
    // Using the sorted list of rules makes this calculation much simpler. We can just assume that
    // we already know all the dependents of a rules incoming nodes when we are processing that
    // rule.
    for (BuildRule rule : sortedRules.reverse()) {
        ImmutableSet.Builder<BuildRule> transitiveDependents = ImmutableSet.builder();
        for (BuildRule dependent : graph.getIncomingNodesFor(rule)) {
            transitiveDependents.addAll(allDependentsMap.get(dependent));
            if (linkableRules.contains(dependent)) {
                transitiveDependents.add(dependent);
            }
        }
        allDependentsMap.put(rule, transitiveDependents.build());
    }
    return ImmutableMap.copyOf(allDependentsMap);
}

From source file:org.lanternpowered.server.data.IValueContainer.java

@SuppressWarnings("unchecked")
@Override/*w w w . j  a va2 s. c om*/
default Set<Key<?>> getKeys() {
    final ImmutableSet.Builder<Key<?>> keys = ImmutableSet.builder();

    // Check local registrations
    keys.addAll(getValueCollection().getKeys());

    // Check for global registrations
    LanternValueFactory.get().getKeyRegistrations().stream()
            .filter(registration -> ((Processor<BaseValue<?>, ?>) registration).isApplicableTo(this))
            .forEach(registration -> keys.add(registration.getKey()));

    // Check if custom data is supported by this container
    if (this instanceof AdditionalContainerHolder) {
        final AdditionalContainerCollection<?> containers = ((AdditionalContainerHolder<?>) this)
                .getAdditionalContainers();
        containers.getAll().forEach(manipulator -> keys.addAll(manipulator.getKeys()));
    }

    return keys.build();
}

From source file:org.sosy_lab.cpachecker.cpa.programcounter.ProgramCounterState.java

@Override
public ProgramCounterState join(ProgramCounterState pOther) {
    if (isTop() || pOther.isTop()) {
        return TOP;
    }//from   www. ja  v  a  2s  .  c om
    ImmutableSet.Builder<BigInteger> builder = null;
    for (BigInteger value : pOther.values) {
        if (!containsValue(value)) {
            if (builder == null) {
                builder = ImmutableSet.builder();
                builder.addAll(values);
            }
            builder.add(value);
        }
    }
    if (builder == null) {
        return this;
    }
    return new ProgramCounterState(builder.build());
}

From source file:org.elasticsearch.cluster.block.ClusterBlocks.java

public ClusterBlockException indexBlockedException(ClusterBlockLevel level, String index) {
    if (!indexBlocked(level, index)) {
        return null;
    }/*  w  w w . j a  va2  s .co m*/
    ImmutableSet.Builder<ClusterBlock> builder = ImmutableSet.builder();
    builder.addAll(global(level));
    ImmutableSet<ClusterBlock> indexBlocks = indices(level).get(index);
    if (indexBlocks != null) {
        builder.addAll(indexBlocks);
    }
    return new ClusterBlockException(builder.build());
}

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

/**
 * Searching for all paths between two devices according to defined deep of search.
 * // ww  w.  j a v a  2  s  .co  m
 * @param service - topology service
 * @param src - source device Id
 * @param dst - destination device Id
 * @param deep - deep of search as path cost
 * 
 * @return set of paths
 */
public static Set<Path> result(TopologyService service, DeviceId src, DeviceId dst, int deep) {
    ImmutableSet.Builder<Path> builder = ImmutableSet.builder();
    TopologyGraph graph = service.getGraph(service.currentTopology());
    DefaultTopologyVertex vs = new DefaultTopologyVertex(src);
    DefaultTopologyVertex vd = new DefaultTopologyVertex(dst);
    @SuppressWarnings("rawtypes")
    EdgeWeight weight = new HopCountLinkWeight(10);

    @SuppressWarnings({ "rawtypes", "unchecked" })
    List<Path> list = new ArrayList();

    @SuppressWarnings("unchecked")
    Result<TopologyVertex, TopologyEdge> result = CUST.search(graph, vs, vd, weight, GraphPathSearch.ALL_PATHS,
            4);
    for (org.onlab.graph.Path<TopologyVertex, TopologyEdge> path : result.paths()) {
        List<Link> links = path.edges().stream().map(TopologyEdge::link).collect(Collectors.toList());
        DefaultPath dp = new DefaultPath(ProviderId.NONE, links, path.cost());
        list.add(dp);
        //         builder.add(dp);
    }

    Collections.sort(list, new Comparator<Path>() {
        public int compare(Path p1, Path p2) {
            Double c1 = p1.cost();
            Double c2 = p2.cost();
            return (c1 < c2 ? -1 : (c1 == c2 ? 0 : 1));
        }
    });

    builder.addAll(list);

    return builder.build();
}

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

@Override
protected void collect(CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) {
    ObjcProvider objcProvider = common.getObjcProvider();

    ImmutableSet.Builder<LibraryToLink> libraries = new ImmutableSet.Builder<>();
    for (Artifact library : objcProvider.get(ObjcProvider.LIBRARY)) {
        libraries.add(LinkerInputs.opaqueLibraryToLink(library, ArtifactCategory.STATIC_LIBRARY,
                FileSystemUtils.removeExtension(library.getRootRelativePathString())));
    }//from  w w w. j  a  v  a  2  s. com

    libraries.addAll(objcProvider.get(ObjcProvider.CC_LIBRARY));

    builder.addLibraries(libraries.build());
}