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

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

Introduction

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

Prototype

int size();

Source Link

Document

Returns the number of elements in this set (its cardinality).

Usage

From source file:org.jclouds.ec2.compute.options.EC2TemplateOptions.java

@Override
public ToStringHelper string() {
    ToStringHelper toString = super.string();
    if (groupNames.size() != 0)
        toString.add("groupNames", groupNames);
    if (noKeyPair)
        toString.add("noKeyPair", noKeyPair);
    toString.add("keyPair", keyPair);
    if (userData != null && userData.size() > 0)
        toString.add("userDataCksum", Hashing.crc32().hashBytes(Bytes.toArray(userData)));
    ImmutableSet<BlockDeviceMapping> mappings = blockDeviceMappings.build();
    if (mappings.size() != 0)
        toString.add("blockDeviceMappings", mappings);
    return toString;
}

From source file:com.proofpoint.http.client.MediaType.java

/**
 * Returns an optional charset for the value of the charset parameter if it is specified.
 *
 * @throws IllegalStateException if multiple charset values have been set for this media type
 * @throws IllegalCharsetNameException if a charset value is present, but illegal
 * @throws UnsupportedCharsetException if a charset value is present, but no support is available
 * in this instance of the Java virtual machine
 *//*from   www  .  ja va 2s .c o  m*/
public Optional<Charset> charset() {
    ImmutableSet<String> charsetValues = ImmutableSet.copyOf(parameters.get(CHARSET_ATTRIBUTE));
    switch (charsetValues.size()) {
    case 0:
        return Optional.absent();
    case 1:
        return Optional.of(Charset.forName(Iterables.getOnlyElement(charsetValues)));
    default:
        throw new IllegalStateException("Multiple charset values defined: " + charsetValues);
    }
}

From source file:org.locationtech.geogig.api.RevTreeBuilder.java

private Map<Integer, RevTree> getBucketTrees(ImmutableSet<Integer> changedBucketIndexes) {
    Map<Integer, RevTree> bucketTrees = new HashMap<>();
    List<Integer> missing = new ArrayList<>(changedBucketIndexes.size());
    for (Integer bucketIndex : changedBucketIndexes) {
        Bucket bucket = bucketTreesByBucket.get(bucketIndex);
        RevTree cached = bucket == null ? RevTree.EMPTY : pendingWritesCache.get(bucket.id());
        if (cached == null) {
            missing.add(bucketIndex);/*w w w  .  j a v a2s .co  m*/
        } else {
            bucketTrees.put(bucketIndex, cached);
        }
    }
    if (!missing.isEmpty()) {
        Map<ObjectId, Integer> ids = Maps.uniqueIndex(missing, new Function<Integer, ObjectId>() {
            @Override
            public ObjectId apply(Integer index) {
                return bucketTreesByBucket.get(index).id();
            }
        });
        Iterator<RevObject> all = db.getAll(ids.keySet());
        while (all.hasNext()) {
            RevObject next = all.next();
            bucketTrees.put(ids.get(next.getId()), (RevTree) next);
        }
    }
    return bucketTrees;
}

From source file:com.facebook.buck.jvm.java.intellij.IjProjectTemplateDataPreparer.java

private void addAndroidAssetPaths(Map<String, Object> androidProperties, IjModule module,
        IjModuleAndroidFacet androidFacet) {
    ImmutableSet<Path> assetPaths = androidFacet.getAssetPaths();
    if (assetPaths.isEmpty()) {
        androidProperties.put(ASSETS_FOLDER_TEMPLATE_PARAMETER, "/assets");
    } else {//from   w  w  w .  ja  va2s.c  o  m
        Set<Path> relativeAssetPaths = new HashSet<>(assetPaths.size());
        Path moduleBase = module.getModuleBasePath();
        for (Path assetPath : assetPaths) {
            relativeAssetPaths.add(moduleBase.relativize(assetPath));
        }
        androidProperties.put(ASSETS_FOLDER_TEMPLATE_PARAMETER, "/" + Joiner.on(";/").join(relativeAssetPaths));
    }
}

From source file:com.google.devtools.build.lib.remote.GrpcActionCache.java

/** Upload all results of a locally executed action to the cache. */
@Override//from  w ww .jav  a2s  . c  om
public void uploadAllResults(Path execRoot, Collection<Path> files, ActionResult.Builder result)
        throws IOException, InterruptedException {
    ArrayList<ContentDigest> digests = new ArrayList<>();
    for (Path file : files) {
        digests.add(ContentDigests.computeDigest(file));
    }
    ImmutableSet<ContentDigest> missing = getMissingDigests(digests);
    if (!missing.isEmpty()) {
        uploadChunks(missing.size(), new BlobChunkFileIterator(missing, files.iterator()));
    }
    int index = 0;
    for (Path file : files) {
        if (file.isDirectory()) {
            // TODO(olaola): to implement this for a directory, will need to create or pass a
            // TreeNodeRepository to call uploadTree.
            throw new UnsupportedOperationException("Storing a directory is not yet supported.");
        }
        // Add to protobuf.
        result.addOutputBuilder().setPath(file.relativeTo(execRoot).getPathString()).getFileMetadataBuilder()
                .setDigest(digests.get(index++)).setExecutable(file.isExecutable());
    }
}

From source file:com.google.devtools.build.lib.skyframe.serialization.ObjectCodecRegistry.java

private ObjectCodecRegistry(ImmutableSet<ObjectCodec<?>> memoizingCodecs,
        ImmutableList<Object> referenceConstants, ImmutableSortedSet<String> classNames,
        ImmutableList<String> blacklistedClassNamePrefixes, boolean allowDefaultCodec) {
    this.allowDefaultCodec = allowDefaultCodec;

    int nextTag = 1; // 0 is reserved for null.
    this.classMappedCodecs = new ConcurrentHashMap<>(memoizingCodecs.size(), 0.75f,
            Runtime.getRuntime().availableProcessors());
    ImmutableList.Builder<CodecDescriptor> tagMappedMemoizingCodecsBuilder = ImmutableList
            .builderWithExpectedSize(memoizingCodecs.size());
    nextTag = processCodecs(memoizingCodecs, nextTag, tagMappedMemoizingCodecsBuilder, classMappedCodecs);
    this.tagMappedCodecs = tagMappedMemoizingCodecsBuilder.build();

    referenceConstantsStartTag = nextTag;
    referenceConstantsMap = new IdentityHashMap<>();
    for (Object constant : referenceConstants) {
        referenceConstantsMap.put(constant, nextTag++);
    }/*from  w  w w  . j av a  2 s . c  o m*/
    this.referenceConstants = referenceConstants;

    this.classNames = classNames.stream().filter((str) -> isAllowed(str, blacklistedClassNamePrefixes))
            .collect(ImmutableList.toImmutableList());
    this.dynamicCodecs = createDynamicCodecs(this.classNames, nextTag);
}

From source file:com.google.devtools.build.lib.remote.GrpcActionCache.java

@Override
public ImmutableList<ContentDigest> uploadBlobs(Iterable<byte[]> blobs) throws InterruptedException {
    ArrayList<ContentDigest> digests = new ArrayList<>();
    for (byte[] blob : blobs) {
        digests.add(ContentDigests.computeDigest(blob));
    }/* ww  w. j ava2s . c o m*/
    ImmutableSet<ContentDigest> missing = getMissingDigests(digests);
    try {
        if (!missing.isEmpty()) {
            uploadChunks(missing.size(), new BlobChunkInlineIterator(missing, blobs.iterator()));
        }
        return ImmutableList.copyOf(digests);
    } catch (IOException e) {
        // This will never happen.
        throw new RuntimeException(e);
    }
}

From source file:com.facebook.buck.jvm.java.intellij.IjProjectTemplateDataPreparer.java

private void addAndroidResourcePaths(Map<String, Object> androidProperties, IjModule module,
        IjModuleAndroidFacet androidFacet) {
    ImmutableSet<Path> resourcePaths = androidFacet.getResourcePaths();
    if (resourcePaths.isEmpty()) {
        androidProperties.put(RESOURCES_RELATIVE_PATH_TEMPLATE_PARAMETER, EMPTY_STRING);
    } else {/*from w  ww. ja va 2 s  .  co  m*/
        Set<Path> relativeResourcePaths = new HashSet<>(resourcePaths.size());
        Path moduleBase = module.getModuleBasePath();
        for (Path resourcePath : resourcePaths) {
            relativeResourcePaths.add(moduleBase.relativize(resourcePath));
        }

        androidProperties.put(RESOURCES_RELATIVE_PATH_TEMPLATE_PARAMETER,
                "/" + Joiner.on(";/").join(relativeResourcePaths));
    }
}

From source file:org.androidtransfuse.analysis.module.ProvidesProcessor.java

private void validate(ASTMethod astMethod, Collection<ASTAnnotation> annotations) {
    ImmutableSet<ASTAnnotation> nonQualifierAnnotations = FluentIterable.from(annotations)
            .filter(Predicates.and(Predicates.not(qualifierPredicate), Predicates.not(scopePredicate),
                    Predicates.not(javaAnnotationPredicate)))
            .toSet();//from  w ww. j  a  v a  2s  .com

    ImmutableSet<ASTAnnotation> scopeAnnotations = FluentIterable.from(annotations).filter(scopePredicate)
            .toSet();

    ASTType providesType = astClassFactory.getType(Provides.class);

    for (ASTAnnotation annotation : nonQualifierAnnotations) {
        if (!annotation.getASTType().equals(providesType)) {
            //error
            validator.error(
                    "@Provides methods may only be annotated with scope, qualifier or standard Java annotations")
                    .element(astMethod).annotation(annotation).build();
        }
    }

    if (scopeAnnotations.size() > 1) {
        for (ASTAnnotation scopeAnnotation : scopeAnnotations) {
            validator.error("Only one scope annotation is allowed per @Provides method").element(astMethod)
                    .annotation(scopeAnnotation).build();
        }
    }
}

From source file:com.facebook.buck.features.project.intellij.IjProjectTemplateDataPreparer.java

private void addAndroidResourcePaths(Map<String, Object> androidProperties, IjModule module,
        IjModuleAndroidFacet androidFacet) {
    ImmutableSet<Path> resourcePaths = androidFacet.getResourcePaths();
    if (resourcePaths.isEmpty()) {
        androidProperties.put(RESOURCES_RELATIVE_PATH_TEMPLATE_PARAMETER, EMPTY_STRING);
    } else {//from w w w  . j av a  2 s . c  om
        Set<String> relativeResourcePaths = new HashSet<>(resourcePaths.size());
        for (Path resourcePath : resourcePaths) {
            relativeResourcePaths
                    .add(IjProjectPaths.toRelativeString(resourcePath, module.getModuleBasePath()));
        }

        androidProperties.put(RESOURCES_RELATIVE_PATH_TEMPLATE_PARAMETER,
                Joiner.on(";").join(relativeResourcePaths));
    }
}