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:com.facebook.buck.artifact_cache.HttpArtifactCacheBinaryProtocol.java

@VisibleForTesting
static byte[] createMetadataHeader(ImmutableSet<RuleKey> ruleKeys, ImmutableMap<String, String> metadata,
        ByteSource data) throws IOException {

    ByteArrayOutputStream rawOut = new ByteArrayOutputStream();
    Hasher hasher = HASH_FUNCTION.newHasher();
    try (DataOutputStream out = new DataOutputStream(new HasherOutputStream(hasher, rawOut))) {

        // Write the rule keys to the raw metadata, including them in the end-to-end checksum.
        out.writeInt(ruleKeys.size());
        for (RuleKey ruleKey : ruleKeys) {
            out.writeUTF(ruleKey.toString());
        }//from www .  j a v  a2s  .c o  m

        // Write out the metadata map to the raw metadata, including it in the end-to-end checksum.
        out.writeInt(metadata.size());
        for (Map.Entry<String, String> ent : metadata.entrySet()) {
            out.writeUTF(ent.getKey());
            byte[] val = ent.getValue().getBytes(Charsets.UTF_8);
            out.writeInt(val.length);
            out.write(val);
            if (out.size() > MAX_METADATA_HEADER_SIZE) {
                throw new IOException("Metadata header too big.");
            }
        }
    }

    // Add the file data contents to the end-to-end checksum.
    data.copyTo(new HasherOutputStream(hasher, ByteStreams.nullOutputStream()));

    // Finish the checksum, adding it to the raw metadata
    rawOut.write(hasher.hash().asBytes());

    // Finally, base64 encode the raw bytes to make usable in a HTTP header.
    byte[] bytes = rawOut.toByteArray();
    if (bytes.length > MAX_METADATA_HEADER_SIZE) {
        throw new IOException("Metadata header too big.");
    }
    return bytes;
}

From source file:paperparcel.Utils.java

private static Optional<AnnotationMirror> findOptionsMirror(TypeElement element) {
    Optional<AnnotationMirror> result = MoreElements.getAnnotationMirror(element, PaperParcel.Options.class);
    if (!result.isPresent()) {
        ImmutableSet<? extends AnnotationMirror> annotatedAnnotations = AnnotationMirrors
                .getAnnotatedAnnotations(element, PaperParcel.Options.class);
        if (annotatedAnnotations.size() > 1) {
            throw new IllegalStateException("PaperParcel options applied twice.");
        } else if (annotatedAnnotations.size() == 1) {
            AnnotationMirror annotatedAnnotation = annotatedAnnotations.iterator().next();
            result = MoreElements.getAnnotationMirror(annotatedAnnotation.getAnnotationType().asElement(),
                    PaperParcel.Options.class);
        } else {//from w  ww .  j a v  a 2 s  . c o  m
            TypeMirror superType = element.getSuperclass();
            if (superType.getKind() != TypeKind.NONE) {
                TypeElement superElement = asType(asDeclared(superType).asElement());
                result = findOptionsMirror(superElement);
            }
        }
    }
    return result;
}

From source file:org.sosy_lab.cpachecker.util.expressions.And.java

public static <LeafType> ExpressionTree<LeafType> of(Iterable<ExpressionTree<LeafType>> pOperands) {
    // If one of the operands is false, return false
    if (Iterables.contains(pOperands, ExpressionTrees.getFalse())) {
        return ExpressionTrees.getFalse();
    }/*from w  ww .j a  v  a 2s  .c o  m*/
    // Filter out trivial operands and flatten the hierarchy
    ImmutableSet<ExpressionTree<LeafType>> operands = FluentIterable.from(pOperands)
            .filter(Predicates.not(Predicates.equalTo(ExpressionTrees.<LeafType>getTrue())))
            .transformAndConcat(new Function<ExpressionTree<LeafType>, Iterable<ExpressionTree<LeafType>>>() {

                @Override
                public Iterable<ExpressionTree<LeafType>> apply(ExpressionTree<LeafType> pOperand) {
                    if (pOperand instanceof And) {
                        return (And<LeafType>) pOperand;
                    }
                    return Collections.singleton(pOperand);
                }
            }).toSet();
    // If there are no operands, return the neutral element
    if (operands.isEmpty()) {
        return ExpressionTrees.getTrue();
    }
    // If there is only one operand, return it
    if (operands.size() == 1) {
        return operands.iterator().next();
    }
    return new And<>(operands);
}

From source file:io.atomix.utils.serializer.serializers.ImmutableSetSerializer.java

@Override
public void write(Kryo kryo, Output output, ImmutableSet<?> object) {
    output.writeInt(object.size());
    for (Object e : object) {
        kryo.writeClassAndObject(output, e);
    }/*ww  w.  j  a v  a2 s .  c  om*/
}

From source file:org.springframework.ide.eclipse.boot.dash.views.OpenNgrokAdminUi.java

private NGROKClient getClient(BootDashElement bde) {
    if (isLocalApp(bde)) {
        ImmutableSet<ILaunchConfiguration> launchConfigs = bde.getLaunchConfigs();
        if (launchConfigs.size() == 1) {
            return NGROKLaunchTracker.get(launchConfigs.iterator().next().getName());
        }/*from w w w  .j a va2  s.c om*/
    }
    return null;
}

From source file:com.brighttag.agathon.service.impl.PerDataCenterSeedService.java

/**
 * Return the first {@code numSeeds} seeds from the {@code instancesInDC} collection
 * for the given {@code dataCenter}./*from ww w .j a v  a  2s . c o  m*/
 *
 * @param dataCenter the data center name
 * @param instancesInDC a collection of instances in the data center
 * @return the public DNS names or IP addresses of the first {@code numSeeds} hosts
 */
private Iterable<String> getSeeds(String dataCenter, ImmutableSet<CassandraInstance> instancesInDC) {
    int size = instancesInDC.size();
    if (size < numSeeds) {
        LOG.warn("Too few seeds for data center '{}'. Continuing with {} seeds.", dataCenter, size);
    }

    return Iterables.transform(Iterables.limit(instancesInDC, numSeeds), INSTANCE_TO_SEED);
}

From source file:dagger2.internal.codegen.InjectFieldValidator.java

@Override
public ValidationReport<VariableElement> validate(VariableElement fieldElement) {
    ValidationReport.Builder<VariableElement> builder = ValidationReport.Builder.about(fieldElement);
    Set<Modifier> modifiers = fieldElement.getModifiers();
    if (modifiers.contains(FINAL)) {
        builder.addItem(FINAL_INJECT_FIELD, fieldElement);
    }//from   w ww .j  av a  2s  . c  om

    if (modifiers.contains(PRIVATE)) {
        builder.addItem(PRIVATE_INJECT_FIELD, fieldElement);
    }

    ImmutableSet<? extends AnnotationMirror> qualifiers = getQualifiers(fieldElement);
    if (qualifiers.size() > 1) {
        for (AnnotationMirror qualifier : qualifiers) {
            builder.addItem(MULTIPLE_QUALIFIERS, fieldElement, qualifier);
        }
    }

    return builder.build();
}

From source file:org.elasticsearch.test.ElasticsearchAllocationTestCase.java

public static AllocationDeciders randomAllocationDeciders(Settings settings,
        NodeSettingsService nodeSettingsService, Random random) {
    final ImmutableSet<Class<? extends AllocationDecider>> defaultAllocationDeciders = AllocationDecidersModule.DEFAULT_ALLOCATION_DECIDERS;
    final List<AllocationDecider> list = new ArrayList<>();
    for (Class<? extends AllocationDecider> deciderClass : defaultAllocationDeciders) {
        try {/*from www  . j  a  v  a  2s  .co m*/
            try {
                Constructor<? extends AllocationDecider> constructor = deciderClass
                        .getConstructor(Settings.class, NodeSettingsService.class);
                list.add(constructor.newInstance(settings, nodeSettingsService));
            } catch (NoSuchMethodException e) {
                Constructor<? extends AllocationDecider> constructor = null;
                constructor = deciderClass.getConstructor(Settings.class);
                list.add(constructor.newInstance(settings));
            }
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
    assertThat(list.size(), equalTo(defaultAllocationDeciders.size()));
    for (AllocationDecider d : list) {
        assertThat(defaultAllocationDeciders.contains(d.getClass()), is(true));
    }
    Collections.shuffle(list, random);
    return new AllocationDeciders(settings, list.toArray(new AllocationDecider[0]));

}

From source file:dagger2.internal.codegen.InjectMethodValidator.java

@Override
public ValidationReport<ExecutableElement> validate(ExecutableElement methodElement) {
    ValidationReport.Builder<ExecutableElement> builder = ValidationReport.Builder.about(methodElement);
    Set<Modifier> modifiers = methodElement.getModifiers();
    if (modifiers.contains(ABSTRACT)) {
        builder.addItem(ABSTRACT_INJECT_METHOD, methodElement);
    }/* w w  w  . j  av  a 2 s .  c  om*/

    if (modifiers.contains(PRIVATE)) {
        builder.addItem(PRIVATE_INJECT_METHOD, methodElement);
    }

    if (!methodElement.getTypeParameters().isEmpty()) {
        builder.addItem(GENERIC_INJECT_METHOD, methodElement);
    }

    for (VariableElement parameter : methodElement.getParameters()) {
        ImmutableSet<? extends AnnotationMirror> qualifiers = getQualifiers(parameter);
        if (qualifiers.size() > 1) {
            for (AnnotationMirror qualifier : qualifiers) {
                builder.addItem(MULTIPLE_QUALIFIERS, methodElement, qualifier);
            }
        }
    }

    return builder.build();
}

From source file:dagger.internal.codegen.InjectFieldValidator.java

ValidationReport<VariableElement> validate(VariableElement fieldElement) {
    ValidationReport.Builder<VariableElement> builder = ValidationReport.about(fieldElement);
    Set<Modifier> modifiers = fieldElement.getModifiers();
    if (modifiers.contains(FINAL)) {
        builder.addError(FINAL_INJECT_FIELD, fieldElement);
    }//from   w  w w. ja  v  a  2 s  . co m

    if (modifiers.contains(PRIVATE)) {
        builder.addItem(PRIVATE_INJECT_FIELD, privateMemberValidationKind, fieldElement);
    }

    if (modifiers.contains(STATIC)) {
        builder.addItem(STATIC_INJECT_FIELD, staticMemberValidationKind, fieldElement);
    }

    ImmutableSet<? extends AnnotationMirror> qualifiers = getQualifiers(fieldElement);
    if (qualifiers.size() > 1) {
        for (AnnotationMirror qualifier : qualifiers) {
            builder.addError(MULTIPLE_QUALIFIERS, fieldElement, qualifier);
        }
    }

    return builder.build();
}