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

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

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this set contains no elements.

Usage

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

private TargetGraph getProjectGraphForIde(ImmutableSet<BuildTarget> passedInTargets)
        throws InterruptedException, BuildFileParseException, IOException {

    if (passedInTargets.isEmpty()) {
        return parser.buildTargetGraphWithConfigurationTargets(parsingContext,
                ImmutableList.of(ImmutableTargetNodePredicateSpec
                        .of(BuildFileSpec.fromRecursivePath(Paths.get(""), cell.getRoot()))),
                targetConfiguration).getTargetGraph();
    }//from w ww.  j a  va 2  s.co  m
    Preconditions.checkState(!passedInTargets.isEmpty());
    return parser.buildTargetGraph(parsingContext, passedInTargets);
}

From source file:com.facebook.buck.cli.AuditFlavorsCommand.java

@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
    ImmutableSet<BuildTarget> targets = getArgumentsFormattedAsBuildTargets(params.getBuckConfig())
            .stream().map(input -> BuildTargetParser.INSTANCE.parse(input,
                    BuildTargetPatternParser.fullyQualified(), params.getCell().getCellPathResolver()))
            .collect(MoreCollectors.toImmutableSet());

    if (targets.isEmpty()) {
        params.getBuckEventBus().post(ConsoleEvent.severe("Please specify at least one build target."));
        return 1;
    }/*w  ww  .  ja  v  a2 s .co  m*/

    ImmutableList.Builder<TargetNode<?, ?>> builder = ImmutableList.builder();
    try (CommandThreadManager pool = new CommandThreadManager("Audit",
            getConcurrencyLimit(params.getBuckConfig()))) {
        for (BuildTarget target : targets) {
            TargetNode<?, ?> targetNode = params.getParser().getTargetNode(params.getBuckEventBus(),
                    params.getCell(), getEnableParserProfiling(), pool.getExecutor(), target);
            builder.add(targetNode);
        }
    } catch (BuildFileParseException | BuildTargetException e) {
        params.getBuckEventBus()
                .post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
        return 1;
    }
    ImmutableList<TargetNode<?, ?>> targetNodes = builder.build();

    if (shouldGenerateJsonOutput()) {
        printJsonFlavors(targetNodes, params);
    } else {
        printFlavors(targetNodes, params);
    }

    return 0;
}

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

/** Run intellij specific project generation actions. */
private ExitCode runIntellijProjectGenerator(TargetGraphAndTargets targetGraphAndTargets)
        throws IOException, InterruptedException {
    ImmutableSet<BuildTarget> requiredBuildTargets = writeProjectAndGetRequiredBuildTargets(
            targetGraphAndTargets);//w  w w  .  j av  a 2 s .c o  m

    if (requiredBuildTargets.isEmpty()) {
        return ExitCode.SUCCESS;
    }

    if (projectConfig.isSkipBuildEnabled()) {
        ConsoleEvent.severe("Please remember to buck build --deep the targets you intent to work with.");
        return ExitCode.SUCCESS;
    }

    return processAnnotations
            ? buildRequiredTargetsWithoutUsingCacheForAnnotatedTargets(targetGraphAndTargets,
                    requiredBuildTargets)
            : runBuild(requiredBuildTargets);
}

From source file:com.olacabs.fabric.compute.pipeline.NotificationBus.java

public synchronized void publish(PipelineMessage message, int from, boolean forward) {
    switch (message.getMessageType()) {
    case TIMER://  ww w. ja va2  s  .  c o m
        // It is a timer message, ACKing is disabled
        comms.get(from).commsChannel.publish(message);
        break;

    case USERSPACE:
        // It is a userspace message, ACKing is enabled
        PipelineMessage actionableMessage = message;
        ImmutableSet.Builder<EventSet> ackCandidatesBuilder = ImmutableSet.builder();
        if (!message.getMessages().isAggregate()) {
            // Find out the oldest ancestor of this event set
            while (true) {
                if (null == actionableMessage.getParent()) {
                    break;
                }
                actionableMessage = actionableMessage.getParent();
            }

            if (!tracker.containsKey(actionableMessage.getMessages().getId())) {
                // Set up the tracker for this event set since it is sent from a source for the first time
                // Add this event set to the tracker with an empty bitset
                tracker.put(actionableMessage.getMessages().getId(), new SimpleBitSet(64));
            }
            SimpleBitSet msgBitSet = tracker.get(actionableMessage.getMessages().getId());
            try {
                // If the event set is being sent forward and the sender sends normal message, set bits
                // for each of the receivers based on the auto incremented id assigned to them
                if (forward && connections.containsKey(from)
                        && ((comms.containsKey(from) && comms.get(from).pipelineStage.sendsNormalMessage())
                                || !comms.containsKey(from))) {
                    connections.get(from).pipelineStages.stream().forEach(msgBitSet::set);
                }
            } catch (Exception e) {
                LOGGER.error("Error setting tracking bits for generator: {}", from, e);
            }

            // unset the bit corresponding to the sender
            msgBitSet.unset(from);
            // if all the bits are unset and if this event set is generated by a source, mark the
            // event set as a candidate for ACKing
            if (!msgBitSet.hasSetBits() && actionableMessage.getMessages().isSourceGenerated()) {
                ackCandidatesBuilder.add(actionableMessage.getMessages());
            }
        }
        try {
            // publish the message to each of the receivers
            if (forward && connections.containsKey(from)) {
                connections.get(from).pipelineStages.stream()
                        .forEach(pipeLineStage -> comms.get(pipeLineStage).commsChannel.publish(message));
            }
        } catch (Throwable t) {
            LOGGER.error("Error sending event to children for {}", from, t);
        }
        // event sets which are eligible for ACKing
        ImmutableSet<EventSet> ackSet = ackCandidatesBuilder.build();

        // ACK all the event sets
        ackSet.stream().forEach(eventSet -> sources.get(eventSet.getSourceId()).ackMessage(eventSet));
        // No event set to ACK, hence we can remove the tracker entry for this event set
        if (!ackSet.isEmpty()) {
            tracker.remove(actionableMessage.getMessages().getId());
        }

        break;
    default:
        break;

    }

}

From source file:dagger.model.BindingGraph.java

/**
 * Returns the edges for entry points that transitively depend on a binding or missing binding for
 * a key. Never returns an empty set.//from  w w  w .  jav a  2s.  c  om
 */
public final ImmutableSet<DependencyEdge> entryPointEdgesDependingOnBinding(MaybeBinding binding) {
    ImmutableNetwork<Node, DependencyEdge> dependencyGraph = dependencyGraph();
    Network<Node, DependencyEdge> subgraphDependingOnBinding = inducedSubgraph(dependencyGraph,
            reachableNodes(transpose(dependencyGraph).asGraph(), binding));
    ImmutableSet<DependencyEdge> entryPointEdges = intersection(entryPointEdges(),
            subgraphDependingOnBinding.edges()).immutableCopy();
    verify(!entryPointEdges.isEmpty(), "No entry points depend on binding %s", binding);
    return entryPointEdges;
}

From source file:com.google.caliper.runner.ExperimentingRunnerModule.java

@Provides
ImmutableSet<Instrumentation> provideInstrumentations(CaliperOptions options, BenchmarkClass benchmarkClass,
        ImmutableSet<Instrument> instruments) throws InvalidBenchmarkException {
    ImmutableSet.Builder<Instrumentation> builder = ImmutableSet.builder();
    ImmutableSet<String> benchmarkMethodNames = options.benchmarkMethodNames();
    Set<String> unusedBenchmarkNames = new HashSet<String>(benchmarkMethodNames);
    for (Instrument instrument : instruments) {
        for (Method method : findAllBenchmarkMethods(benchmarkClass.benchmarkClass(), instrument)) {
            if (benchmarkMethodNames.isEmpty() || benchmarkMethodNames.contains(method.getName())) {
                builder.add(instrument.createInstrumentation(method));
                unusedBenchmarkNames.remove(method.getName());
            }/*www .j  a v a  2s  .  co  m*/
        }
    }
    if (!unusedBenchmarkNames.isEmpty()) {
        throw new InvalidBenchmarkException(
                "Invalid benchmark method(s) specified in options: " + unusedBenchmarkNames);
    }
    return builder.build();
}

From source file:com.google.javascript.jscomp.JsChecker.java

private boolean run() throws IOException {
    final JsCheckerState state = new JsCheckerState(label, legacy, testonly, roots, mysterySources);
    final Set<String> actuallySuppressed = new HashSet<>();

    // read provided files created by this program on deps
    for (String dep : deps) {
        state.provided.addAll(JsCheckerHelper.loadClosureJsLibraryInfo(Paths.get(dep)).getNamespaceList());
    }/*from ww w  .  j a  va2 s. c  o m*/

    Map<String, String> labels = new HashMap<>();
    labels.put("", label);
    Set<String> modules = new LinkedHashSet<>();
    for (String source : sources) {
        for (String module : convertPathToModuleName(source, state.roots).asSet()) {
            modules.add(module);
            labels.put(module, label);
            state.provides.add(module);
        }
    }

    for (String source : mysterySources) {
        for (String module : convertPathToModuleName(source, state.roots).asSet()) {
            checkArgument(!module.startsWith("blaze-out/"), "oh no: %s", state.roots);
            modules.add(module);
            state.provided.add(module);
        }
    }

    // configure compiler
    Compiler compiler = new Compiler();
    CompilerOptions options = new CompilerOptions();
    options.setLanguage(LanguageMode.ECMASCRIPT_2017);
    options.setStrictModeInput(true);
    options.setIncrementalChecks(IncrementalCheckMode.GENERATE_IJS);
    options.setCodingConvention(convention.convention);
    options.setSkipTranspilationAndCrash(true);
    options.setContinueAfterErrors(true);
    options.setPrettyPrint(true);
    options.setPreserveTypeAnnotations(true);
    options.setPreserveDetailedSourceInfo(true);
    options.setEmitUseStrict(false);
    options.setParseJsDocDocumentation(Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE);
    JsCheckerErrorFormatter errorFormatter = new JsCheckerErrorFormatter(compiler, state.roots, labels);
    errorFormatter.setColorize(true);
    JsCheckerErrorManager errorManager = new JsCheckerErrorManager(errorFormatter);
    compiler.setErrorManager(errorManager);

    // configure which error messages appear
    if (!legacy) {
        for (String error : Iterables.concat(Diagnostics.JSCHECKER_ONLY_ERRORS,
                Diagnostics.JSCHECKER_EXTRA_ERRORS)) {
            options.setWarningLevel(Diagnostics.GROUPS.forName(error), CheckLevel.ERROR);
        }
    }
    final Set<DiagnosticType> suppressions = Sets.newHashSetWithExpectedSize(256);
    for (String code : suppress) {
        ImmutableSet<DiagnosticType> types = Diagnostics.getDiagnosticTypesForSuppressCode(code);
        if (types.isEmpty()) {
            System.err.println("ERROR: Bad --suppress value: " + code);
            return false;
        }
        suppressions.addAll(types);
    }

    options.addWarningsGuard(new WarningsGuard() {
        @Override
        public CheckLevel level(JSError error) {
            // TODO(jart): Figure out how to support this.
            if (error.getType().key.equals("JSC_CONSTANT_WITHOUT_EXPLICIT_TYPE")) {
                return CheckLevel.OFF;
            }

            // Closure Rules will always ignore these checks no matter what.
            if (Diagnostics.IGNORE_ALWAYS.contains(error.getType())) {
                return CheckLevel.OFF;
            }

            // Disable warnings specific to conventions other than the one we're using.
            if (!convention.diagnostics.contains(error.getType())) {
                for (JsCheckerConvention conv : JsCheckerConvention.values()) {
                    if (!conv.equals(convention)) {
                        if (conv.diagnostics.contains(error.getType())) {
                            suppressions.add(error.getType());
                            return CheckLevel.OFF;
                        }
                    }
                }
            }
            // Disable warnings we've suppressed.
            Collection<String> groupNames = Diagnostics.DIAGNOSTIC_GROUPS.get(error.getType());
            if (suppressions.contains(error.getType())) {
                actuallySuppressed.add(error.getType().key);
                actuallySuppressed.addAll(groupNames);
                return CheckLevel.OFF;
            }
            // Ignore linter warnings on generated sources.
            if (groupNames.contains("lintChecks") && JsCheckerHelper.isGeneratedPath(error.sourceName)) {
                return CheckLevel.OFF;
            }
            return null;
        }
    });

    // Run the compiler.
    compiler.setPassConfig(new JsCheckerPassConfig(state, options));
    compiler.disableThreads();
    compiler.compile(ImmutableList.<SourceFile>of(), getSourceFiles(Iterables.concat(sources, mysterySources)),
            options);

    // In order for suppress to be maintainable, we need to make sure the suppress codes relating to
    // linting were actually suppressed. However we can only offer this safety on the checks over
    // which JsChecker has sole dominion. Other suppress codes won't actually be suppressed until
    // they've been propagated up to the closure_js_binary rule.
    if (!suppress.contains("superfluousSuppress")) {
        Set<String> useless = Sets.intersection(
                Sets.difference(ImmutableSet.copyOf(suppress), actuallySuppressed),
                Diagnostics.JSCHECKER_ONLY_SUPPRESS_CODES);
        if (!useless.isEmpty()) {
            errorManager.report(CheckLevel.ERROR,
                    JSError.make(Diagnostics.SUPERFLUOUS_SUPPRESS, label, Joiner.on(", ").join(useless)));
        }
    }

    // TODO: Make compiler.compile() package private so we don't have to do this.
    errorManager.stderr.clear();
    errorManager.generateReport();

    // write errors
    if (!expectFailure) {
        for (String line : errorManager.stderr) {
            System.err.println(line);
        }
    }
    if (!outputErrors.isEmpty()) {
        Files.write(Paths.get(outputErrors), errorManager.stderr, UTF_8);
    }

    // write .i.js type summary for this library
    if (!outputIjsFile.isEmpty()) {
        Files.write(Paths.get(outputIjsFile), compiler.toSource().getBytes(UTF_8));
    }

    // write file full of information about these sauces
    if (!output.isEmpty()) {
        ClosureJsLibrary.Builder info = ClosureJsLibrary.newBuilder().setLabel(label).setLegacy(legacy)
                .addAllNamespace(state.provides).addAllModule(modules);
        if (!legacy) {
            for (DiagnosticType suppression : suppressions) {
                if (!Diagnostics.JSCHECKER_ONLY_SUPPRESS_CODES.contains(suppression.key)) {
                    info.addSuppress(suppression.key);
                }
            }
        }
        Files.write(Paths.get(output), info.build().toString().getBytes(UTF_8));
    }

    return errorManager.getErrorCount() == 0;
}

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.j  a v  a 2s.  co 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.facebook.buck.features.project.intellij.IjProjectTemplateDataPreparer.java

private void addAndroidAssetPaths(Map<String, Object> androidProperties, IjModule module,
        IjModuleAndroidFacet androidFacet) {
    if (androidFacet.isAndroidLibrary()) {
        return;//from   w  w w . j a va 2s.c o  m
    }
    ImmutableSet<Path> assetPaths = androidFacet.getAssetPaths();
    if (assetPaths.isEmpty()) {
        return;
    }
    Set<Path> relativeAssetPaths = new HashSet<>(assetPaths.size());
    for (Path assetPath : assetPaths) {
        relativeAssetPaths.add(projectPaths.getModuleRelativePath(assetPath, module));
    }
    androidProperties.put(ASSETS_FOLDER_TEMPLATE_PARAMETER, "/" + Joiner.on(";/").join(relativeAssetPaths));
}

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 ww  w  .j a v a2 s  .  com*/
        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));
    }
}