Example usage for com.google.common.collect ImmutableSet builder

List of usage examples for com.google.common.collect ImmutableSet builder

Introduction

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

Prototype

public static <E> Builder<E> builder() 

Source Link

Usage

From source file:org.fcrepo.kernel.impl.utils.impl.InfinispanCacheStoreEntry.java

@Override
public Collection<FixityResult> checkFixity(final String algorithm) {
    final BinaryKey key = binaryKey();
    final ImmutableSet.Builder<FixityResult> fixityResults = new ImmutableSet.Builder<>();

    if (store().hasBinary(key)) {
        final String dataKey = InfinispanUtils.dataKeyFrom((InfinispanBinaryStore) store(), key);
        final ChunkBinaryMetadata metadata = InfinispanUtils.getMetadata((InfinispanBinaryStore) store(), key);

        final DistributedFixityCheck task = new DistributedFixityCheck(dataKey, algorithm,
                metadata.getChunkSize(), metadata.getLength());

        final List<Future<Collection<FixityResult>>> futures = clusterExecutor().submitEverywhere(task,
                dataKey + "-0");

        while (!futures.isEmpty()) {
            final Iterator<Future<Collection<FixityResult>>> iterator = futures.iterator();
            while (iterator.hasNext()) {
                final Future<Collection<FixityResult>> future = iterator.next();
                try {
                    final Collection<FixityResult> result = future.get(100, MILLISECONDS);
                    iterator.remove();//from w w  w .  j av  a2 s  .c  o  m

                    fixityResults.addAll(result);
                } catch (final TimeoutException e) {
                    LOGGER.trace("Going to retry cluster transform after timeout", e);
                } catch (InterruptedException | ExecutionException e) {
                    throw propagate(e);
                }
            }
        }
    }
    return fixityResults.build();
}

From source file:org.jclouds.softlayer.SoftLayerProviderMetadata.java

public static Properties defaultProperties() {
    Properties properties = new Properties();
    properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_LOGIN_DETAILS_DELAY, "" + 60 * 60 * 1000);
    properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME, "Cloud Server");
    // ex: for private (ex. don't share hardware) use "Private [0-9]+ x ([.0-9]+) GHz Core[s]?"
    // ex: for private and public use ".*[0-9]+ x ([.0-9]+) GHz Core[s]?"
    properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_CPU_REGEX, "[0-9]+ x ([0-9.]+) GHz Core[s]?");
    // SAN or LOCAL
    properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_DISK0_TYPE, "LOCAL");
    // 10, 100, 1000
    properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_PORT_SPEED, "10");
    ImmutableSet.Builder<String> prices = ImmutableSet.builder();
    prices.add("21"); // 1 IP Address
    prices.add("55"); // Host Ping: categoryCode: monitoring, notification
    prices.add("57"); // Email and Ticket: categoryCode: notification
    prices.add("58"); // Automated Notification: categoryCode: response
    prices.add("1800"); // 0 GB Bandwidth: categoryCode: bandwidth
    prices.add("905"); // Reboot / Remote Console: categoryCode: remote_management
    prices.add("418"); // Nessus Vulnerability Assessment & Reporting: categoryCode:
                       // vulnerability_scanner
    prices.add("420"); // Unlimited SSL VPN Users & 1 PPTP VPN User per account: categoryCode:
                       // vpn_management
    properties.setProperty(PROPERTY_SOFTLAYER_VIRTUALGUEST_PRICES, Joiner.on(',').join(prices.build()));
    properties.setProperty(TEMPLATE,//from w  w w.j a va2s.  c  o  m
            "osFamily=UBUNTU,osVersionMatches=1[012].[01][04],os64Bit=true,osDescriptionMatches=.*Minimal Install.*");
    return properties;
}

From source file:org.jclouds.location.suppliers.RegionToProviderOrJustProvider.java

protected Builder<Location> buildJustProviderOrRegions() {
    Builder<Location> locations = ImmutableSet.builder();
    Location provider = Iterables.getOnlyElement(super.get());
    if (regions.size() == 0)
        return locations.add(provider);
    else/*from   w w  w  . j  a  v a  2s .  c  o  m*/
        for (String region : regions) {
            LocationBuilder builder = new LocationBuilder().scope(LocationScope.REGION).id(region)
                    .description(region).parent(provider);
            if (isoCodesById.containsKey(region))
                builder.iso3166Codes(isoCodesById.get(region));
            locations.add(builder.build());
        }
    return locations;
}

From source file:org.sosy_lab.cpachecker.cpa.livevar.LiveVariablesState.java

public LiveVariablesState union(LiveVariablesState pState2) {
    if (isSubsetOf(pState2)) {
        return pState2;
    } else if (pState2.isSubsetOf(this)) {
        return this;
    }/*from  w  w w .  j  av  a2s  . c  om*/

    Builder<ASimpleDeclaration> builder = ImmutableSet.builder();
    builder.addAll(liveVars);
    builder.addAll(pState2.liveVars);

    return new LiveVariablesState(builder.build());
}

From source file:org.ow2.proactive.procci.model.occi.metamodel.Category.java

/**
 * Constructor which set all the parameters
 *
 * @param scheme     is the categorisation scheme
 * @param term       is the unique identifier of the category instance
 * @param title      is the name of the instance
 * @param attributes are the category and sub-types attributes
 *///from   w  w  w .  j a v  a  2  s .c o  m
public Category(String scheme, String term, String title, Set<Attribute> attributes) {
    if (("").equals(scheme)) {
        this.scheme = UUID.randomUUID().toString();
    } else {
        this.scheme = scheme;
    }
    this.title = title;
    this.term = term;
    this.attributes = new ImmutableSet.Builder<Attribute>().add(MetamodelAttributes.SCHEME)
            .add(MetamodelAttributes.TERM).add(MetamodelAttributes.CATEGORY_TITLE).addAll(attributes).build();
}

From source file:com.facebook.buck.rules.coercer.DefaultConstructorArgMarshaller.java

@CheckReturnValue
@Override/*from w ww  .ja  va 2s.  c o  m*/
public <T> T populate(CellPathResolver cellRoots, ProjectFilesystem filesystem, BuildTarget buildTarget,
        Class<T> dtoClass, ImmutableSet.Builder<BuildTarget> declaredDeps, Map<String, ?> instance)
        throws ParamInfoException {
    Pair<Object, Function<Object, T>> dtoAndBuild = CoercedTypeCache.instantiateSkeleton(dtoClass, buildTarget);
    ImmutableMap<String, ParamInfo> allParamInfo = CoercedTypeCache.INSTANCE.getAllParamInfo(typeCoercerFactory,
            dtoClass);
    for (ParamInfo info : allParamInfo.values()) {
        info.setFromParams(cellRoots, filesystem, buildTarget, buildTarget.getTargetConfiguration(),
                dtoAndBuild.getFirst(), instance);
    }
    T dto = dtoAndBuild.getSecond().apply(dtoAndBuild.getFirst());
    collectDeclaredDeps(cellRoots, allParamInfo.get("deps"), declaredDeps, dto);
    return dto;
}

From source file:com.nike.cerberus.security.VaultAuthPrincipal.java

private Set<String> buildRoles(VaultClientTokenResponse clientToken) {
    final ImmutableSet.Builder<String> roleSetBuilder = ImmutableSet.builder();
    final Map<String, String> meta = clientToken.getMeta();

    if (meta != null && Boolean.valueOf(meta.get(METADATA_KEY_IS_ADMIN))) {
        roleSetBuilder.add(ROLE_ADMIN);/*  w  ww  .  ja v  a 2  s  .  c om*/
    }

    roleSetBuilder.add(ROLE_USER);

    return roleSetBuilder.build();
}

From source file:net.tridentsdk.server.entity.decorate.DecoratedImpalable.java

@Override
public Collection<Projectile> projectiles() {
    return new ImmutableSet.Builder<Projectile>().addAll(
            Iterators.transform(projectiles.iterator(), new Function<WeakReference<Projectile>, Projectile>() {
                @Nullable//from w w  w.  j ava  2  s . c  om
                @Override
                public Projectile apply(WeakReference<Projectile> projectileWeakReference) {
                    return projectileWeakReference.get();
                }
            })).build();
}

From source file:com.facebook.presto.raptor.storage.CompactionSetCreator.java

private Set<ShardMetadata> getCompactionSet(List<ShardMetadata> shardMetadata) {
    ImmutableSet.Builder<ShardMetadata> shards = ImmutableSet.builder();
    long maxShardSizeBytes = maxShardSize.toBytes();
    long consumedBytes = 0;
    for (ShardMetadata shard : shardMetadata) {
        long uncompressedSize = shard.getUncompressedSize();
        if (consumedBytes + uncompressedSize > maxShardSizeBytes) {
            break;
        }/*from   w ww  .  j a  v a2s  . c om*/
        consumedBytes += uncompressedSize;
        shards.add(shard);
    }
    return shards.build();
}

From source file:io.druid.server.lookup.cache.polling.OffHeapPollingCache.java

public OffHeapPollingCache(final Iterable<Map.Entry<K, V>> entries) {
    synchronized (started) {
        this.cacheName = String.format("cache-%s", UUID.randomUUID());
        this.reverseCacheName = String.format("reverseCache-%s", UUID.randomUUID());
        mapCache = DB.createHashMap(cacheName).make();
        reverseCache = DB.createHashMap(reverseCacheName).make();
        ImmutableSet.Builder<V> setOfValuesBuilder = ImmutableSet.builder();
        for (Map.Entry<K, V> entry : entries) {
            mapCache.put(entry.getKey(), entry.getValue());
            setOfValuesBuilder.add(entry.getValue());
        }//from   www.j  av  a2 s .co m

        final Set<V> setOfValues = setOfValuesBuilder.build();
        reverseCache.putAll(Maps.asMap(setOfValues, new Function<V, List<K>>() {
            @Override
            public List<K> apply(final V input) {
                return Lists.newArrayList(Maps.filterKeys(mapCache, new Predicate<K>() {
                    @Override
                    public boolean apply(K key) {
                        V retVal = mapCache.get(key);
                        if (retVal == null) {
                            return false;
                        }
                        return retVal.equals(input);
                    }
                }).keySet());
            }
        }));
        started.getAndSet(true);
    }
}