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:de.cosmocode.palava.ipc.json.rpc.JsonRpc2Protocol.java

@Override
public boolean supports(Map<?, ?> request) {
    final int size = request.size();
    final Set<?> keys = request.keySet();
    for (ImmutableSet<String> set : KEYS) {
        if (size == set.size() && keys.containsAll(set)) {
            return true;
        }/* w ww . j  ava2  s.  com*/
    }
    return false;
}

From source file:com.facebook.buck.apple.simulator.AppleCoreSimulatorServiceController.java

/**
 * Returns the path on disk to the running Core Simulator service, if any.
 * Returns {@code Optional.empty()} unless exactly one Core Simulator service is running.
 *///ww  w.j  ava 2s  . c om
public Optional<Path> getCoreSimulatorServicePath(UserIdFetcher userIdFetcher)
        throws IOException, InterruptedException {
    ImmutableSet<String> coreSimulatorServiceNames = getMatchingServiceNames(CORE_SIMULATOR_SERVICE_PATTERN);

    if (coreSimulatorServiceNames.size() != 1) {
        LOG.debug("Could not get core simulator service name (got %s)", coreSimulatorServiceNames);
        return Optional.empty();
    }

    String coreSimulatorServiceName = Iterables.getOnlyElement(coreSimulatorServiceNames);

    ImmutableList<String> launchctlPrintCommand = ImmutableList.of("launchctl", "print",
            String.format("user/%d/%s", userIdFetcher.getUserId(), coreSimulatorServiceName));

    LOG.debug("Getting status of service %s with %s", coreSimulatorServiceName, launchctlPrintCommand);
    ProcessExecutorParams launchctlPrintParams = ProcessExecutorParams.builder()
            .setCommand(launchctlPrintCommand).build();
    ProcessExecutor.LaunchedProcess launchctlPrintProcess = processExecutor.launchProcess(launchctlPrintParams);
    Optional<Path> result = Optional.empty();
    try (InputStreamReader stdoutReader = new InputStreamReader(launchctlPrintProcess.getInputStream(),
            StandardCharsets.UTF_8); BufferedReader bufferedStdoutReader = new BufferedReader(stdoutReader)) {
        String line;
        while ((line = bufferedStdoutReader.readLine()) != null) {
            Matcher matcher = LAUNCHCTL_PRINT_PATH_PATTERN.matcher(line);
            if (matcher.matches()) {
                String path = matcher.group(1);
                LOG.debug("Found path of service %s: %s", coreSimulatorServiceName, path);
                result = Optional.of(Paths.get(path));
                break;
            }
        }
    } finally {
        processExecutor.destroyLaunchedProcess(launchctlPrintProcess);
        processExecutor.waitForLaunchedProcess(launchctlPrintProcess);
    }

    return result;
}

From source file:com.facebook.buck.versions.VersionedTargetGraph.java

@Nullable
@Override/*  w w  w . j  a  va  2 s .  c om*/
protected TargetNode<?, ?> getInternal(BuildTarget target) {

    // If this node is in the graph under the given name, return it.
    TargetNode<?, ?> node = targetsToNodes.get(target);
    if (node != null) {
        return node;
    }

    ImmutableList<ImmutableSet<Flavor>> flavorList = flavorMap.get(target.getUnflavoredBuildTarget());
    if (flavorList == null) {
        return null;
    }

    // Otherwise, see if this node exists in the graph with a "less" flavored name.  We initially
    // select all targets which contain a subset of the original flavors, which should be sorted by
    // from largest flavor set to smallest.  We then use the first match, and verify the subsequent
    // matches are subsets.
    ImmutableList<ImmutableSet<Flavor>> matches = RichStream.from(flavorList)
            .filter(target.getFlavors()::containsAll).toImmutableList();
    if (!matches.isEmpty()) {
        ImmutableSet<Flavor> firstMatch = matches.get(0);
        for (ImmutableSet<Flavor> subsequentMatch : matches.subList(1, matches.size())) {
            Preconditions.checkState(firstMatch.size() > subsequentMatch.size());
            Preconditions.checkState(firstMatch.containsAll(subsequentMatch),
                    "Found multiple disjoint flavor matches for %s: %s and %s",
                    target.getUnflavoredBuildTarget(), firstMatch, subsequentMatch);
        }
        return Preconditions.checkNotNull(targetsToNodes.get(target.withFlavors(firstMatch)))
                .withFlavors(target.getFlavors());
    }

    // Otherwise, return `null` to indicate this node isn't in the target graph.
    return null;
}

From source file:com.google.errorprone.bugpatterns.ProtoTruthMixedDescriptors.java

@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
    if (!IGNORING.matches(tree, state)) {
        return Description.NO_MATCH;
    }/*from ww  w  .  j a v  a 2 s.c  o m*/
    List<? extends ExpressionTree> arguments = tree.getArguments();
    ImmutableSet<TypeSymbol> types = arguments.stream().map(t -> protoType(t, state))
            .filter(Optional::isPresent).map(Optional::get).collect(toImmutableSet());
    if (types.size() > 1) {
        return describeMatch(tree);
    }
    if (types.size() != 1) {
        return Description.NO_MATCH;
    }
    TypeSymbol type = getOnlyElement(types);
    for (ExpressionTree receiver = getReceiver(
            tree); receiver instanceof MethodInvocationTree; receiver = getReceiver(receiver)) {
        if (ASSERT_THAT.matches(receiver, state)) {
            return validateReceiver(tree, (MethodInvocationTree) receiver, type, state);
        }
    }
    return Description.NO_MATCH;
}

From source file:org.sosy_lab.cpachecker.cpa.validvars.ValidVars.java

public ValidVars mergeWith(ValidVars pOther) throws CPAException {
    if (!pOther.localValidVars.keySet().containsAll(localValidVars.keySet())) {
        throw new CPAException(
                "Require Callstack CPA to separate different function calls and Location CPA to separate different locations.");
    }//from w w w  . j  a v a2 s  . c  o  m

    boolean changed = false;

    // merge global vars
    ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    builder.addAll(pOther.globalValidVars);
    builder.addAll(globalValidVars);

    ImmutableSet<String> newGlobals = builder.build();
    if (newGlobals.size() != pOther.globalValidVars.size()) {
        changed = true;
    }

    // merge local vars
    ImmutableSet<String> newLocalsForFun;
    ImmutableMap.Builder<String, ImmutableSet<String>> builderMap = ImmutableMap.builder();
    for (String funName : localValidVars.keySet()) {
        checkArgument(numFunctionCalled.get(funName).equals(pOther.numFunctionCalled.get(funName)),
                "Require Callstack CPA to separate different function calls.");
        builder = ImmutableSet.builder();
        builder.addAll(pOther.localValidVars.get(funName));
        builder.addAll(localValidVars.get(funName));

        newLocalsForFun = builder.build();
        if (newLocalsForFun.size() != pOther.localValidVars.get(funName).size()) {
            changed = true;
        }

        builderMap.put(funName, newLocalsForFun);
    }

    if (changed) {
        return new ValidVars(newGlobals, builderMap.build(), numFunctionCalled);
    }

    return pOther;
}

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

private ValidationReport<ExecutableElement> validateUncached(ExecutableElement method) {
    ValidationReport.Builder<ExecutableElement> report = ValidationReport.about(method);
    ImmutableSet<? extends Class<? extends Annotation>> bindingMethodAnnotations = methodAnnotations().stream()
            .filter(annotation -> isAnnotationPresent(method, annotation)).collect(toImmutableSet());
    switch (bindingMethodAnnotations.size()) {
    case 0:/*from  w  w  w  . j  a  v a2s.  c om*/
        throw new IllegalArgumentException(String.format("%s has no binding method annotation", method));

    case 1:
        report.addSubreport(validators.get(getOnlyElement(bindingMethodAnnotations)).validate(method));
        break;

    default:
        report.addError(tooManyBindingMethodAnnotations(method, methodAnnotations()), method);
        break;
    }
    return report.build();
}

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

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params,
        BuildRuleResolver buildRuleResolver, A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);

    ImmutableSet<Flavor> flavors = params.getBuildTarget().getFlavors();
    if (flavors.contains(AAR_UNZIP_FLAVOR)) {
        Preconditions.checkState(flavors.size() == 1);
        BuildRuleParams unzipAarParams = params.copyWithDeps(Suppliers.ofInstance(ImmutableSortedSet.of()),
                Suppliers.ofInstance(ImmutableSortedSet.copyOf(ruleFinder.filterBuildRuleInputs(args.aar))));
        return new UnzipAar(unzipAarParams, args.aar);
    }//  w  ww  . jav a 2  s  . c  om

    BuildRule unzipAarRule = buildRuleResolver
            .requireRule(params.getBuildTarget().withFlavors(AAR_UNZIP_FLAVOR));
    Preconditions.checkState(unzipAarRule instanceof UnzipAar,
            "aar_unzip flavor created rule of unexpected type %s for target %s", unzipAarRule.getClass(),
            params.getBuildTarget());
    UnzipAar unzipAar = (UnzipAar) unzipAarRule;

    if (flavors.contains(CalculateAbi.FLAVOR)) {
        return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params,
                new BuildTargetSourcePath(unzipAar.getBuildTarget(), unzipAar.getPathToClassesJar()));
    }

    Iterable<PrebuiltJar> javaDeps = Iterables.concat(
            Iterables.filter(buildRuleResolver.getAllRules(args.deps), PrebuiltJar.class),
            Iterables.transform(
                    Iterables.filter(buildRuleResolver.getAllRules(args.deps), AndroidPrebuiltAar.class),
                    AndroidPrebuiltAar::getPrebuiltJar));

    BuildTarget abiJarTarget = params.getBuildTarget().withAppendedFlavors(CalculateAbi.FLAVOR);

    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);

    PrebuiltJar prebuiltJar = buildRuleResolver.addToIndex(createPrebuiltJar(unzipAar, params, pathResolver,
            abiJarTarget, ImmutableSortedSet.copyOf(javaDeps)));

    BuildRuleParams androidLibraryParams = params.copyWithDeps(
            /* declaredDeps */ Suppliers.ofInstance(ImmutableSortedSet.of(prebuiltJar)),
            /* extraDeps */ Suppliers.ofInstance(ImmutableSortedSet.of(unzipAar)));
    return new AndroidPrebuiltAar(androidLibraryParams, /* resolver */ pathResolver, ruleFinder,
            /* proguardConfig */ new BuildTargetSourcePath(unzipAar.getBuildTarget(),
                    unzipAar.getProguardConfig()),
            /* nativeLibsDirectory */ new BuildTargetSourcePath(unzipAar.getBuildTarget(),
                    unzipAar.getNativeLibsDirectory()),
            /* prebuiltJar */ prebuiltJar, /* unzipRule */ unzipAar, /* javacOptions */ javacOptions,
            new JavacToJarStepFactory(javacOptions, new BootClasspathAppender()), /* exportedDeps */ javaDeps,
            abiJarTarget, JavaLibraryRules.getAbiInputs(buildRuleResolver, androidLibraryParams.getDeps()));
}

From source file:com.facebook.buck.doctor.AbstractReport.java

private ImmutableMap<String, String> getConfigOverrides(ImmutableSet<BuildLogEntry> entries) {
    if (entries.size() != 1) {
        return ImmutableMap.of();
    }/*w w  w.j  av a2s  . c o m*/
    BuildLogEntry entry = entries.asList().get(0);
    if (!entry.getCommandArgs().isPresent()) {
        return ImmutableMap.of();
    }
    List<String> args = entry.getCommandArgs().get();
    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
    for (int i = 0; i < args.size(); i++) {
        if (args.get(i).equals("--config") || args.get(i).equals("-c")) {
            i++;
            if (i >= args.size()) {
                break;
            }
            String[] pieces = args.get(i).split("=", 2);
            builder.put(pieces[0], pieces.length == 2 ? pieces[1] : "");
        }
    }
    return builder.build();
}

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

public ModuleConfiguration process(ASTType moduleType, ASTType moduleScanTarget, ASTMethod astMethod,
        ASTAnnotation astAnnotation) {//from   w  w  w.  ja v a2s  .  c  om

    ImmutableSet<ASTAnnotation> qualifierAnnotations = FluentIterable.from(astMethod.getAnnotations())
            .filter(qualifierPredicate).toSet();

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

    ASTAnnotation scope = null;
    if (scopeAnnotations.size() > 0) {
        scope = scopeAnnotations.iterator().next();
    }

    validate(astMethod, astMethod.getAnnotations());

    return new ProvidesModuleConfiguration(moduleType, qualifierAnnotations, astMethod, scope);
}

From source file:org.jclouds.sqs.options.ReceiveMessageOptions.java

/**
 * {@inheritDoc}/*from   w  w w  .j a  v  a 2  s.c  o  m*/
 */
@Override
public String toString() {
    ImmutableSet<String> attributes = this.attributes.build();
    return Objects.toStringHelper(this).omitNullValues().add("visibilityTimeout", visibilityTimeout)
            .add("attributes", attributes.size() > 0 ? attributes : null).toString();
}