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.github.rinde.rinsim.core.model.pdp.RandomVehicle.java

Optional<Parcel> findTarget() {
    final Collection<Parcel> available = pm.get().getParcels(ParcelState.AVAILABLE);
    final ImmutableSet<Parcel> contents = pm.get().getContents(this);
    if (available.isEmpty() && contents.isEmpty()) {
        return Optional.absent();
    }/* w  w  w.  j ava  2s.  c o  m*/
    boolean pickup;
    if (!available.isEmpty() && !contents.isEmpty()) {
        pickup = rng.get().nextBoolean();
    } else {
        pickup = !available.isEmpty();
    }
    if (pickup) {
        return Optional.of(newArrayList(available).get(rng.get().nextInt(available.size())));
    }
    return Optional.of(contents.asList().get(rng.get().nextInt(contents.size())));
}

From source file:com.google.devtools.build.lib.runtime.BuildEventStreamerModule.java

@VisibleForTesting
Optional<BuildEventStreamer> tryCreateStreamer(OptionsProvider optionsProvider,
        ModuleEnvironment moduleEnvironment) {
    try {/*  ww  w  .ja v  a2  s  .c  om*/
        PathConverter pathConverter;
        if (commandEnvironment == null) {
            pathConverter = new PathConverter() {
                @Override
                public String apply(Path path) {
                    return path.getPathString();
                }
            };
        } else {
            pathConverter = commandEnvironment.getRuntime().getPathToUriConverter();
        }
        BuildEventStreamOptions besOptions = checkNotNull(
                optionsProvider.getOptions(BuildEventStreamOptions.class),
                "Could not get BuildEventStreamOptions");
        ImmutableSet<BuildEventTransport> buildEventTransports = createFromOptions(besOptions, pathConverter);
        if (!buildEventTransports.isEmpty()) {
            BuildEventStreamer streamer = new BuildEventStreamer(buildEventTransports);
            return Optional.of(streamer);
        }
    } catch (IOException e) {
        moduleEnvironment.exit(new AbruptExitException(ExitCode.LOCAL_ENVIRONMENTAL_ERROR, e));
    }
    return Optional.absent();
}

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

@Override
public void visitGraph(BindingGraph bindingGraph, DiagnosticReporter diagnosticReporter) {
    if (bindingGraph.isModuleBindingGraph() || bindingGraph.isPartialBindingGraph()) {
        // We don't know all the modules that might be owned by the child until we know the root.
        return;// w  w w . j  ava  2 s .  c  o  m
    }
    bindingGraph.network().edges().stream().flatMap(instancesOf(ChildFactoryMethodEdge.class)).forEach(edge -> {
        ImmutableSet<TypeElement> missingModules = findMissingModules(edge, bindingGraph);
        if (!missingModules.isEmpty()) {
            reportMissingModuleParameters(edge, missingModules, bindingGraph, diagnosticReporter);
        }
    });
}

From source file:com.palantir.lock.client.LockRefreshingRemoteLockService.java

private void refreshLocks() {
    ImmutableSet<LockRefreshToken> refreshCopy = ImmutableSet.copyOf(toRefresh);
    if (refreshCopy.isEmpty()) {
        return;//ww w .java  2  s.  c o m
    }
    Set<LockRefreshToken> refreshedTokens = delegate().refreshLockRefreshTokens(refreshCopy);
    for (LockRefreshToken token : refreshCopy) {
        if (!refreshedTokens.contains(token) && toRefresh.contains(token)) {
            log.error("failed to refresh lock: " + token);
            toRefresh.remove(token);
        }
    }
}

From source file:com.github.jsdossier.CompilerModule.java

@Provides
CompilerOptions provideCompilerOptions(AliasTransformListener transformListener,
        ProvidedSymbolPass providedSymbolPass, TypeCollectionPass typeCollectionPass, @Input LanguageMode mode,
        @Modules ImmutableSet<Path> modulePaths) throws IOException {
    CompilerOptions options = new CompilerOptions();

    if (!modulePaths.isEmpty()) {
        // Prevents browser-specific externs from being loaded.
        options.setEnvironment(CompilerOptions.Environment.CUSTOM);
    }/*from  w  w  w. j av a 2  s  .  co m*/

    options.setModuleRoots(ImmutableList.<String>of());

    options.setLanguageIn(mode);
    options.setLanguageOut(LanguageMode.ECMASCRIPT5);

    options.setCodingConvention(new ClosureCodingConvention());
    CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
    CompilationLevel.ADVANCED_OPTIMIZATIONS.setTypeBasedOptimizationOptions(options);

    // IDE mode must be enabled or all of the jsdoc info will be stripped from the AST.
    options.setIdeMode(true);
    options.setPreserveJsDocWhitespace(true);

    // For easier debugging.
    options.setPrettyPrint(true);

    options.setAliasTransformationHandler(transformListener);

    options.addCustomPass(CustomPassExecutionTime.BEFORE_CHECKS, providedSymbolPass);
    options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, typeCollectionPass);

    return options;
}

From source file:org.gradle.api.internal.tasks.compile.incremental.deps.ClassSetAnalysis.java

private DependentsSet getDependents(String className) {
    DependentsSet dependents = classAnalysis.getDependents(className);
    if (dependents.isDependencyToAll()) {
        return dependents;
    }/*  www .java2s.  c o m*/
    ImmutableSet<String> additionalDeps = dependenciesFromAnnotationProcessing.get(className);
    if (additionalDeps.isEmpty()) {
        return dependents;
    }
    return DependentsSet.dependents(Sets.union(dependents.getDependentClasses(), additionalDeps));
}

From source file:com.facebook.buck.features.apple.project.XCodeProjectCommandHelper.java

@VisibleForTesting
static ImmutableSet<BuildTarget> generateWorkspacesForTargets(BuckEventBus buckEventBus,
        PluginManager pluginManager, Cell cell, BuckConfig buckConfig,
        RuleKeyConfiguration ruleKeyConfiguration, ListeningExecutorService executorService,
        TargetGraphAndTargets targetGraphAndTargets, ImmutableSet<BuildTarget> passedInTargetsSet,
        ProjectGeneratorOptions options, ImmutableSet<Flavor> appleCxxFlavors,
        FocusedModuleTargetMatcher focusModules, Map<Path, ProjectGenerator> projectGenerators,
        boolean combinedProject, PathOutputPresenter presenter,
        Optional<ImmutableMap<BuildTarget, TargetNode<?>>> sharedLibraryToBundle)
        throws IOException, InterruptedException {
    ImmutableSet<BuildTarget> targets;
    if (passedInTargetsSet.isEmpty()) {
        targets = targetGraphAndTargets.getProjectRoots().stream().map(TargetNode::getBuildTarget)
                .collect(ImmutableSet.toImmutableSet());
    } else {//www  .  j  a v  a  2s.  co  m
        targets = passedInTargetsSet;
    }

    LazyActionGraph lazyActionGraph = new LazyActionGraph(targetGraphAndTargets.getTargetGraph(),
            cell.getCellProvider());

    XCodeDescriptions xcodeDescriptions = XCodeDescriptionsFactory.create(pluginManager);

    LOG.debug("Generating workspace for config targets %s", targets);
    ImmutableSet.Builder<BuildTarget> requiredBuildTargetsBuilder = ImmutableSet.builder();
    for (BuildTarget inputTarget : targets) {
        TargetNode<?> inputNode = targetGraphAndTargets.getTargetGraph().get(inputTarget);
        XcodeWorkspaceConfigDescriptionArg workspaceArgs;
        if (inputNode.getDescription() instanceof XcodeWorkspaceConfigDescription) {
            TargetNode<XcodeWorkspaceConfigDescriptionArg> castedWorkspaceNode = castToXcodeWorkspaceTargetNode(
                    inputNode);
            workspaceArgs = castedWorkspaceNode.getConstructorArg();
        } else if (canGenerateImplicitWorkspaceForDescription(inputNode.getDescription())) {
            workspaceArgs = createImplicitWorkspaceArgs(inputNode);
        } else {
            throw new HumanReadableException(
                    "%s must be a xcode_workspace_config, apple_binary, apple_bundle, or apple_library",
                    inputNode);
        }

        AppleConfig appleConfig = buckConfig.getView(AppleConfig.class);
        HalideBuckConfig halideBuckConfig = new HalideBuckConfig(buckConfig);
        CxxBuckConfig cxxBuckConfig = new CxxBuckConfig(buckConfig);
        SwiftBuckConfig swiftBuckConfig = new SwiftBuckConfig(buckConfig);

        CxxPlatformsProvider cxxPlatformsProvider = cell.getToolchainProvider()
                .getByName(CxxPlatformsProvider.DEFAULT_NAME, CxxPlatformsProvider.class);

        CxxPlatform defaultCxxPlatform = cxxPlatformsProvider.getDefaultUnresolvedCxxPlatform()
                .getLegacyTotallyUnsafe();
        Cell workspaceCell = cell.getCell(inputTarget);
        WorkspaceAndProjectGenerator generator = new WorkspaceAndProjectGenerator(xcodeDescriptions,
                workspaceCell, targetGraphAndTargets.getTargetGraph(), workspaceArgs, inputTarget, options,
                combinedProject, focusModules, !appleConfig.getXcodeDisableParallelizeBuild(),
                defaultCxxPlatform, appleCxxFlavors, buckConfig.getView(ParserConfig.class).getBuildFileName(),
                lazyActionGraph::getActionGraphBuilderWhileRequiringSubgraph, buckEventBus,
                ruleKeyConfiguration, halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig,
                sharedLibraryToBundle);
        Objects.requireNonNull(executorService, "CommandRunnerParams does not have executor for PROJECT pool");
        Path outputPath = generator.generateWorkspaceAndDependentProjects(projectGenerators, executorService);

        ImmutableSet<BuildTarget> requiredBuildTargetsForWorkspace = generator.getRequiredBuildTargets();
        LOG.debug("Required build targets for workspace %s: %s", inputTarget, requiredBuildTargetsForWorkspace);
        requiredBuildTargetsBuilder.addAll(requiredBuildTargetsForWorkspace);

        Path absolutePath = workspaceCell.getFilesystem().resolve(outputPath);
        Path relativePath = cell.getFilesystem().relativize(absolutePath);
        presenter.present(inputTarget.getFullyQualifiedName(), relativePath);
    }

    return requiredBuildTargetsBuilder.build();
}

From source file:com.opengamma.strata.collect.result.Result.java

/**
 * Creates a failed result combining multiple failed results.
 * <p>/*from w  w w .j  a v  a  2  s.c  o m*/
 * The input results can be successes or failures, only the failures will be included in the created result.
 * Intended to be used with {@link #anyFailures(Iterable)}.
 * <blockquote><pre>
 *   if (Result.anyFailures(results) {
 *     return Result.failure(results);
 *   }
 * </pre></blockquote>
 *
 * @param <R> the expected type of the result
 * @param results  multiple results, of which at least one must be a failure, not empty
 * @return a failed result wrapping multiple other failed results
 * @throws IllegalArgumentException if results is empty or contains nothing but successes
 */
public static <R> Result<R> failure(Iterable<? extends Result<?>> results) {
    ArgChecker.notEmpty(results, "results");
    ImmutableSet<FailureItem> items = Guavate.stream(results).filter(Result::isFailure).map(Result::getFailure)
            .flatMap(f -> f.getItems().stream()).collect(Guavate.toImmutableSet());
    if (items.isEmpty()) {
        throw new IllegalArgumentException("All results were successes");
    }
    return new Result<>(Failure.of(items));
}

From source file:com.facebook.buck.core.config.AbstractAliasConfig.java

public ImmutableSet<String> getBuildTargetForAliasAsString(String possiblyFlavoredAlias) {
    String[] parts = possiblyFlavoredAlias.split("#", 2);
    String unflavoredAlias = parts[0];
    ImmutableSet<BuildTarget> buildTargets = getBuildTargetsForAlias(unflavoredAlias);
    if (buildTargets.isEmpty()) {
        return ImmutableSet.of();
    }//  w  w  w. ja v a  2  s.  c om
    String suffix = parts.length == 2 ? "#" + parts[1] : "";
    return buildTargets.stream().map(buildTarget -> buildTarget.getFullyQualifiedName() + suffix)
            .collect(ImmutableSet.toImmutableSet());
}

From source file:com.google.devtools.build.xcode.xcodegen.PBXBuildFiles.java

private PBXBuildFile aggregateBuildFile(ImmutableSet<Path> paths, PBXReference reference) {
    Preconditions.checkArgument(!paths.isEmpty(), "paths must be non-empty");
    for (PBXBuildFile cached : Mapping.of(aggregateBuildFiles, paths).asSet()) {
        return cached;
    }/*from  w w w .  j  a  va2 s. c om*/
    PBXBuildFile buildFile = new PBXBuildFile(reference);
    mainGroupReferences.add(reference);
    aggregateBuildFiles.put(paths, buildFile);
    return buildFile;
}