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

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

Introduction

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

Prototype

@Override
    public boolean isEmpty() 

Source Link

Usage

From source file:com.facebook.buck.cxx.CxxLibraryDescription.java

/**
 * Create all build rules needed to generate the static library.
 *
 * @return build rule that builds the static library version of this C/C++ library.
 *///from   www. j  a  va  2 s.c o  m
private static BuildRule createStaticLibraryBuildRule(BuildRuleParams params, BuildRuleResolver resolver,
        CxxBuckConfig cxxBuckConfig, CxxPlatform cxxPlatform, Arg args, CxxSourceRuleFactory.PicType pic)
        throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);

    // Create rules for compiling the object files.
    ImmutableMap<CxxPreprocessAndCompile, SourcePath> objects = CxxDescriptionEnhancer.requireObjects(params,
            resolver, sourcePathResolver, ruleFinder, cxxBuckConfig, cxxPlatform, pic, args);

    // Write a build rule to create the archive for this C/C++ library.
    BuildTarget staticTarget = CxxDescriptionEnhancer.createStaticLibraryBuildTarget(params.getBuildTarget(),
            cxxPlatform.getFlavor(), pic);

    if (objects.isEmpty()) {
        return new NoopBuildRule(new BuildRuleParams(staticTarget,
                Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of()),
                params.getProjectFilesystem(), params.getCellRoots()), sourcePathResolver);
    }

    Path staticLibraryPath = CxxDescriptionEnhancer.getStaticLibraryPath(params.getProjectFilesystem(),
            params.getBuildTarget(), cxxPlatform.getFlavor(), pic, cxxPlatform.getStaticLibraryExtension());
    return Archive.from(staticTarget, params, sourcePathResolver, ruleFinder, cxxPlatform,
            cxxBuckConfig.getArchiveContents(), staticLibraryPath, ImmutableList.copyOf(objects.values()));
}

From source file:com.google.shipshape.analyzers.CheckstyleGoogleAnalyzer.java

@Override
public ImmutableList<Note> analyze(ShipshapeContext context) throws AnalyzerException {
    ImmutableMap<String, String> javaFiles = CheckstyleUtils.getJavaFiles(context);
    if (javaFiles.isEmpty()) {
        return ImmutableList.of();
    }//ww  w . ja  v a 2  s.c  o  m
    return CheckstyleUtils.runCheckstyle(context, getCategory(), javaFiles, "/google_checks.xml");
}

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

/**
 * Returns a {@link VmSpec} based on the data gathered by this visitor.
 *
 * @throws IllegalStateException if not all the data has been gathered.
 *//*from ww  w.j  a v a  2s.  c om*/
VmSpec vmSpec() {
    ImmutableMap<String, String> options = vmOptionsBuilder.build();
    checkState(!options.isEmpty());
    return new VmSpec.Builder().addAllProperties(vmProperties.get()).addAllOptions(options).build();
}

From source file:org.apache.lens.api.error.ErrorMap.java

public ErrorMap(@NonNull final ImmutableMap<Integer, LensError> errors) {

    checkArgument(!errors.isEmpty());
    this.errors = errors;

    /* All error pay load classes in error objects should be unique.
     * If two error objects are having same error code, then error pay load passed by them should also be same. */

    checkState(getErrorPayloadClassesList().size() == getErrorPayloadClasses().size(),
            "In error conf files, error objects defined with different error codes must have different"
                    + " error payload class.");
}

From source file:org.jclouds.ec2.suppliers.DescribeAvailabilityZonesInRegion.java

@Override
public Map<String, Supplier<Set<String>>> get() {
    Builder<String, Set<String>> map = ImmutableMap.builder();
    HttpResponseException exception = null;
    // TODO: this should be parallel
    for (String region : regions.get()) {
        try {//  w  w w. ja va  2 s  .co m
            ImmutableSet<String> zones = ImmutableSet
                    .copyOf(Iterables.transform(client.describeAvailabilityZonesInRegion(region),
                            new Function<AvailabilityZoneInfo, String>() {

                                @Override
                                public String apply(AvailabilityZoneInfo arg0) {
                                    return arg0.getZone();
                                }

                            }));
            if (zones.size() > 0)
                map.put(region, zones);
        } catch (HttpResponseException e) {
            // TODO: this should be in retry handler, not here.
            if (e.getMessage().contains("Unable to tunnel through proxy")) {
                exception = e;
                logger.error(e, "Could not describe availability zones in Region: %s", region);
            } else {
                throw e;
            }
        }
    }
    ImmutableMap<String, Set<String>> result = map.build();
    if (result.isEmpty() && exception != null) {
        throw exception;
    }
    return Maps.transformValues(result, Suppliers2.<Set<String>>ofInstanceFunction());
}

From source file:org.spongepowered.common.data.processor.value.entity.RespawnLocationValueProcessor.java

@Override
public DataTransactionResult removeFrom(ValueContainer<?> container) {
    if (container instanceof ISpongeUser) {
        ImmutableMap<UUID, Vector3d> removed = ((ISpongeUser) container).removeAllBeds();
        if (!removed.isEmpty()) {
            return DataTransactionResult.builder().result(DataTransactionResult.Type.SUCCESS)
                    .replace(constructImmutableValue(removed)).build();
        } else {//w  w  w .  j  av a2s  .  co  m
            return DataTransactionResult.successNoData();
        }
    }
    return DataTransactionResult.failNoData();
}

From source file:com.astonish.dropwizard.routing.hibernate.AbstractHibernateDAORouter.java

/**
 * @param sessionFactoryMap//ww  w.ja  v  a 2  s . com
 *            map of route keys to their corresponding {@link SessionFactory}.
 * @throws NullPointerException
 *             if sessionFactoryMap is null or any {@link Entry} in sessionFactoryMap has a null value with a
 *             non-null key
 * @throws IllegalStateException
 *             if sessionFactoryMap is empty
 */
public AbstractHibernateDAORouter(final ImmutableMap<String, SessionFactory> sessionFactoryMap) {
    checkNotNull(sessionFactoryMap);
    checkState(!sessionFactoryMap.isEmpty());

    final Map<String, ImmutableMap<Class<?>, Object>> daosByRoute = new LinkedHashMap<>();
    for (Entry<String, SessionFactory> e : sessionFactoryMap.entrySet()) {
        SessionFactory factory = checkNotNull(e.getValue());
        daosByRoute.put(e.getKey(), constructDAOs(factory));
    }

    this.daosByRoute = ImmutableMap.copyOf(daosByRoute);
}

From source file:org.spongepowered.common.data.processor.data.entity.RespawnLocationDataProcessor.java

@Override
public DataTransactionResult removeFrom(ValueContainer<?> container) {
    if (container instanceof ISpongeUser) {
        ImmutableMap<UUID, RespawnLocation> removed = ((ISpongeUser) container).removeAllBeds();
        if (!removed.isEmpty()) {
            return DataTransactionResult.successRemove(constructImmutableValue(removed));
        } else {/*from w w  w  .  ja  v  a 2 s. co  m*/
            return DataTransactionResult.successNoData();
        }
    }
    return DataTransactionResult.failNoData();
}

From source file:com.facebook.buck.core.files.FileTreeTransformer.java

@Override
public FileTree transform(FileTreeKey key, TransformationEnvironment env) {

    DirectoryList currentDir = env.getDep(ImmutableDirectoryListKey.of(key.getPath()));
    ImmutableMap<FileTreeKey, FileTree> children = env.getDeps(FileTreeKey.class);

    ImmutableMap<Path, FileTree> deps;
    if (children.isEmpty()) {
        deps = ImmutableMap.of();//from   w  w w  . j  a v  a 2 s  .  c  o m
    } else {
        // Convert Map<FileTreeKey, FileTree> to Map<Path, FileTree>
        // Not using streams etc. for performance
        // May be instead have FileTree object to have Map<FileTreeKey, FileTree> instead of
        // Map<Path, FileTree>? The interface is less cleaner then, but we can reuse collections

        deps = MoreMaps.transformKeys(children, k -> k.getPath());
    }

    return ImmutableFileTree.of(key.getPath(), currentDir, deps);
}

From source file:io.druid.indexing.overlord.setup.FillCapacityWithAffinityWorkerSelectStrategy.java

@Override
public Optional<ImmutableZkWorker> findWorkerForTask(final RemoteTaskRunnerConfig config,
        final ImmutableMap<String, ImmutableZkWorker> zkWorkers, final Task task) {
    // don't run other datasources on affinity workers; we only want our configured datasources to run on them
    ImmutableMap.Builder<String, ImmutableZkWorker> builder = new ImmutableMap.Builder<>();
    for (String workerHost : zkWorkers.keySet()) {
        if (!affinityWorkerHosts.contains(workerHost)) {
            builder.put(workerHost, zkWorkers.get(workerHost));
        }//  w  w  w .  j  a  v  a  2 s  .c o  m
    }
    ImmutableMap<String, ImmutableZkWorker> eligibleWorkers = builder.build();

    List<String> workerHosts = affinityConfig.getAffinity().get(task.getDataSource());
    if (workerHosts == null) {
        return super.findWorkerForTask(config, eligibleWorkers, task);
    }

    ImmutableMap.Builder<String, ImmutableZkWorker> affinityBuilder = new ImmutableMap.Builder<>();
    for (String workerHost : workerHosts) {
        ImmutableZkWorker zkWorker = zkWorkers.get(workerHost);
        if (zkWorker != null) {
            affinityBuilder.put(workerHost, zkWorker);
        }
    }
    ImmutableMap<String, ImmutableZkWorker> affinityWorkers = affinityBuilder.build();

    if (!affinityWorkers.isEmpty()) {
        Optional<ImmutableZkWorker> retVal = super.findWorkerForTask(config, affinityWorkers, task);
        if (retVal.isPresent()) {
            return retVal;
        }
    }

    return super.findWorkerForTask(config, eligibleWorkers, task);
}