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.zip.ZipDirectoryWithMaxDeflateStep.java

@Override
public int execute(ExecutionContext context) {
    ProjectFilesystem filesystem = context.getProjectFilesystem();
    File inputDirectory = filesystem.getFileForRelativePath(inputDirectoryPath);
    Preconditions.checkState(inputDirectory.exists() && inputDirectory.isDirectory(), "%s must be a directory.",
            inputDirectoryPath);//  w  ww  . jav a2  s  .  c  o  m

    try {
        ImmutableMap.Builder<File, ZipEntry> zipEntriesBuilder = ImmutableMap.builder();
        addDirectoryToZipEntryList(inputDirectory, "", zipEntriesBuilder);
        ImmutableMap<File, ZipEntry> zipEntries = zipEntriesBuilder.build();

        if (!zipEntries.isEmpty()) {
            File outputZipFile = filesystem.getFileForRelativePath(outputZipPath);
            try (CustomZipOutputStream outputStream = ZipOutputStreams.newOutputStream(outputZipFile)) {
                for (Map.Entry<File, ZipEntry> zipEntry : zipEntries.entrySet()) {
                    outputStream.putNextEntry(zipEntry.getValue());
                    ByteStreams.copy(Files.newInputStreamSupplier(zipEntry.getKey()), outputStream);
                    outputStream.closeEntry();
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace(context.getStdErr());
        return 1;
    }
    return 0;
}

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

@Override
public Optional<ImmutableWorkerInfo> findWorkerForTask(final WorkerTaskRunnerConfig config,
        final ImmutableMap<String, ImmutableWorkerInfo> 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, ImmutableWorkerInfo> builder = new ImmutableMap.Builder<>();
    for (String workerHost : zkWorkers.keySet()) {
        if (!affinityWorkerHosts.contains(workerHost)) {
            builder.put(workerHost, zkWorkers.get(workerHost));
        }/*from ww  w. j a  va 2  s . c om*/
    }
    ImmutableMap<String, ImmutableWorkerInfo> eligibleWorkers = builder.build();

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

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

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

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

From source file:org.apache.gobblin.runtime.LimitingExtractorDecorator.java

private void submitLimiterStopMetadataEvents() {
    ImmutableMap<String, String> metaData = this.getLimiterStopMetadata();
    if (!metaData.isEmpty()) {
        this.eventSubmitter.submit(LIMITER_STOP_EVENT_NAME, metaData);
    }//from ww w  . j  a va 2  s.  com
}

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

/**
 * Create a map of {@link BuildTarget} base paths to aliases. Note that there may be more than one
 * alias to a base path, so the first one listed in the .buckconfig will be chosen.
 *//*from   w  w  w .ja va2s  .c  o  m*/
public ImmutableMap<Path, String> getBasePathToAliasMap() {
    ImmutableMap<String, String> aliases = getEntries();
    if (aliases.isEmpty()) {
        return ImmutableMap.of();
    }

    // Build up the Map with an ordinary HashMap because we need to be able to check whether the Map
    // already contains the key before inserting.
    Map<Path, String> basePathToAlias = new HashMap<>();
    for (Map.Entry<String, BuildTarget> entry : getAliases().entries()) {
        String alias = entry.getKey();
        BuildTarget buildTarget = entry.getValue();

        Path basePath = buildTarget.getBasePath();
        if (!basePathToAlias.containsKey(basePath)) {
            basePathToAlias.put(basePath, alias);
        }
    }
    return ImmutableMap.copyOf(basePathToAlias);
}

From source file:com.facebook.buck.step.fs.ZipDirectoryWithMaxDeflateStep.java

@Override
public int execute(ExecutionContext context) {
    File inputDirectory = new File(inputDirectoryPath);
    Preconditions.checkState(inputDirectory.exists() && inputDirectory.isDirectory());

    Closer closer = Closer.create();// ww  w .  j a  v  a 2s  .com
    try {
        ImmutableMap.Builder<File, ZipEntry> zipEntriesBuilder = ImmutableMap.builder();
        addDirectoryToZipEntryList(inputDirectory, "", zipEntriesBuilder);
        ImmutableMap<File, ZipEntry> zipEntries = zipEntriesBuilder.build();

        if (!zipEntries.isEmpty()) {
            ZipOutputStream outputStream = closer.register(
                    new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outputZipPath))));

            for (Map.Entry<File, ZipEntry> zipEntry : zipEntries.entrySet()) {
                outputStream.putNextEntry(zipEntry.getValue());
                ByteStreams.copy(Files.newInputStreamSupplier(zipEntry.getKey()), outputStream);
                outputStream.closeEntry();
            }
        }
    } catch (IOException e) {
        e.printStackTrace(context.getStdErr());
        return 1;
    } finally {
        try {
            closer.close();
        } catch (IOException e) {
            Throwables.propagate(e);
        }
    }
    return 0;
}

From source file:org.grycap.gpf4med.rest.Gpf4MedApplication.java

public Gpf4MedApplication() {
    // load configuration
    ConfigurationManager.INSTANCE.getRootDir();
    // create a proxy to the Gpf4Med JAX-RS resource implementation      
    final Gpf4MedResource gpf4medProxy = newGpf4MedResourceProxy(executorService);
    instances.add(gpf4medProxy);//  ww w.j  a  va 2  s . c om
    // scan for connectors and create proxies to their JAX-RS resources
    final ImmutableMap<String, GraphConnector> connectors = GraphConnectorManager.INSTANCE.listConnectors();
    if (connectors != null && !connectors.isEmpty()) {
        instances.addAll(
                transform(connectors.entrySet(), new Function<Map.Entry<String, GraphConnector>, Object>() {
                    @Override
                    public Object apply(final Entry<String, GraphConnector> entry) {
                        final Class<?> type = entry.getValue().restResourceDefinition();
                        return newResourceProxy(type, executorService);
                    }
                }));
    }
    // start service
    final Gpf4MedEnactor service = SingletonService.INSTANCE.service();
    // register shutdown hook
    shutdownHook.register(service);
    LOGGER.info(SERVICE_NAME + " initialized successfully, registered resources: "
            + Arrays.toString(instances.toArray()));
}

From source file:com.sourceclear.headlines.impl.CspDirectives.java

private String formatDirectives(ImmutableMap<String, ImmutableList<String>> directives) {

    // In the case of an empty map return the empty string:
    if (directives.isEmpty()) {
        return "";
    }/*from   w  ww.j  av a2  s  .  c o m*/

    StringBuilder sb = new StringBuilder();

    // Outer loop - loop through each directive
    for (String directive : directives.keySet()) {

        // Don't add a directive if it has zero elements
        if (directives.get(directive).size() == 0) {
            continue;
        }

        StringBuilder elements = new StringBuilder();

        // Inner loop = for each directive build up the element String
        for (String element : directives.get(directive)) {
            elements.append(element).append(" ");
        }

        if (sb.length() > 0) {
            sb.append(" ; ");
        }

        sb.append(directive).append(" ").append(elements.toString().trim());
    }

    return sb.toString().trim();
}

From source file:org.cyclop.web.components.column.WidgetFactory.java

private Component createForMap(Row row, CqlPartitionKeyValue cqlPartitionKeyValue, CqlExtendedColumnName column,
        String componentId) {//w  w  w. ja  v a2s  .  c  om
    ImmutableMap<CqlColumnValue, CqlColumnValue> displayMap = extractor.extractMap(row, column);
    Component comp;
    if (displayMap.isEmpty()) {
        comp = createForEmptyColumn(componentId);
    } else {
        comp = new MapViewPanel(componentId, cqlPartitionKeyValue, displayMap);
    }

    return comp;
}

From source file:org.elasticsearch.action.admin.indices.exists.types.TransportTypesExistsAction.java

@Override
protected TypesExistsResponse masterOperation(TypesExistsRequest request, ClusterState state)
        throws ElasticSearchException {
    String[] concreteIndices = state.metaData().concreteIndices(request.indices(), request.ignoreIndices(),
            false);/*from   ww w .j a v  a 2 s.  co m*/
    if (concreteIndices.length == 0) {
        return new TypesExistsResponse(false);
    }

    for (String concreteIndex : concreteIndices) {
        if (!state.metaData().hasConcreteIndex(concreteIndex)) {
            return new TypesExistsResponse(false);
        }

        ImmutableMap<String, MappingMetaData> mappings = state.metaData().getIndices().get(concreteIndex)
                .mappings();
        if (mappings.isEmpty()) {
            return new TypesExistsResponse(false);
        }

        for (String type : request.types()) {
            if (!mappings.containsKey(type)) {
                return new TypesExistsResponse(false);
            }
        }
    }

    return new TypesExistsResponse(true);
}

From source file:org.eigenbase.rel.metadata.ReflectiveRelMetadataProvider.java

/**
 * Creates a ReflectiveRelMetadataProvider.
 *
 * @param map Map//  w w  w  . ja  va  2 s  .c o m
 * @param metadataClass0 Metadata class
 */
protected ReflectiveRelMetadataProvider(ImmutableMap<Class<RelNode>, Function<RelNode, Metadata>> map,
        Class<?> metadataClass0) {
    assert !map.isEmpty() : "are your methods named wrong?";
    this.map = map;
    this.metadataClass0 = metadataClass0;
}