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

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

Introduction

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

Prototype

public ImmutableCollection<V> values() 

Source Link

Usage

From source file:org.opendaylight.infrautils.caches.baseimpl.DelegatingNullSafeCache.java

@Override
public ImmutableMap<K, V> get(Iterable<? extends K> keys) throws BadCacheFunctionRuntimeException {
    Objects.requireNonNull(keys, "null keys (not supported)");
    for (K key : keys) {
        Objects.requireNonNull(key, "null key in keys (not supported)");
    }/*from  www  .j a  v  a  2s . co m*/
    ImmutableMap<K, V> map = delegate.get(keys);
    if (map == null) {
        throw new BadCacheFunctionRuntimeException("Cache's function returned null value instead of Map");
    }
    for (V value : map.values()) {
        if (value == null) {
            throw new BadCacheFunctionRuntimeException("Cache's function returned a null value");
        }
    }
    return map;
}

From source file:org.opendaylight.infrautils.caches.baseimpl.DelegatingNullSafeCheckedCache.java

@Override
public ImmutableMap<K, V> get(Iterable<? extends K> keys) throws BadCacheFunctionRuntimeException, E {
    Objects.requireNonNull(keys, "null keys (not supported)");
    for (K key : keys) {
        Objects.requireNonNull(key, "null key in keys (not supported)");
    }/*from   www .ja  va  2s  . c o m*/
    ImmutableMap<K, V> map = delegate.get(keys);
    if (map == null) {
        throw new BadCacheFunctionRuntimeException("Cache's function returned null value instead of Map");
    }
    for (V value : map.values()) {
        if (value == null) {
            throw new BadCacheFunctionRuntimeException("Cache's function returned a null value");
        }
    }
    return map;
}

From source file:com.facebook.buck.rules.coercer.DefaultConstructorArgMarshaller.java

@Override
public <T> T populateWithConfiguringAttributes(CellPathResolver cellPathResolver, ProjectFilesystem filesystem,
        SelectorListResolver selectorListResolver, SelectableConfigurationContext configurationContext,
        BuildTarget buildTarget, Class<T> dtoClass, ImmutableSet.Builder<BuildTarget> declaredDeps,
        ImmutableMap<String, ?> attributes) throws CoerceFailedException {
    Pair<Object, Function<Object, T>> dtoAndBuild = CoercedTypeCache.instantiateSkeleton(dtoClass, buildTarget);
    ImmutableMap<String, ParamInfo> allParamInfo = CoercedTypeCache.INSTANCE.getAllParamInfo(typeCoercerFactory,
            dtoClass);// w  w w  .j  a  v  a2 s  . co m
    for (ParamInfo info : allParamInfo.values()) {
        Object attribute = attributes.get(info.getName());
        if (attribute == null) {
            continue;
        }
        Object attributeWithSelectableValue = createCoercedAttributeWithSelectableValue(cellPathResolver,
                filesystem, buildTarget, buildTarget.getTargetConfiguration(), info, attribute);
        Object configuredAttributeValue = configureAttributeValue(configurationContext, selectorListResolver,
                buildTarget, info.getName(), attributeWithSelectableValue);
        if (configuredAttributeValue != null) {
            info.setCoercedValue(dtoAndBuild.getFirst(), configuredAttributeValue);
        }
    }
    T dto = dtoAndBuild.getSecond().apply(dtoAndBuild.getFirst());
    collectDeclaredDeps(cellPathResolver, allParamInfo.get("deps"), declaredDeps, dto);
    return dto;
}

From source file:com.github.caofangkun.bazelipse.classpath.BazelClasspathContainer.java

@Override
public IClasspathEntry[] getClasspathEntries() {
    try {/*from   www .j  a  va  2 s  .c  om*/
        ImmutableList<String> targets = Activator.getTargets(project.getProject());
        ImmutableMap<String, IdeBuildInfo> infos = instance.getIdeInfo(targets);
        Set<Jars> jars = new HashSet<>();
        for (IdeBuildInfo s : infos.values()) {
            jars.addAll(s.getGeneratedJars());
            if (!isSourceInPaths(s.getSources())) {
                jars.addAll(s.getJars());
            }
        }
        return jarsToClasspathEntries(jars);
    } catch (JavaModelException | BackingStoreException | IOException | InterruptedException e) {
        Activator.error("Unable to compute classpath containers entries.", e);
        return new IClasspathEntry[] {};
    }
}

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

/**
 * @param projectConfig the project config used
 * @param targetGraph input graph./*from  www.  ja  va 2s . co  m*/
 * @param libraryFactory library factory.
 * @param moduleFactory module factory.
 * @return module graph corresponding to the supplied {@link TargetGraph}. Multiple targets from
 *     the same base path are mapped to a single module, therefore an IjModuleGraph edge exists
 *     between two modules (Ma, Mb) if a TargetGraph edge existed between a pair of nodes (Ta, Tb)
 *     and Ma contains Ta and Mb contains Tb.
 */
public static IjModuleGraph from(ProjectFilesystem projectFilesystem, IjProjectConfig projectConfig,
        TargetGraph targetGraph, IjLibraryFactory libraryFactory, IjModuleFactory moduleFactory,
        AggregationModuleFactory aggregationModuleFactory) {
    ImmutableSet<String> ignoredTargetLabels = projectConfig.getIgnoredTargetLabels();
    ImmutableMap<BuildTarget, IjModule> rulesToModules = createModules(projectFilesystem, projectConfig,
            targetGraph, moduleFactory, aggregationModuleFactory,
            projectConfig.getAggregationMode().getGraphMinimumDepth(targetGraph.getNodes().size()),
            ignoredTargetLabels);
    ExportedDepsClosureResolver exportedDepsClosureResolver = new ExportedDepsClosureResolver(targetGraph,
            ignoredTargetLabels);
    TransitiveDepsClosureResolver transitiveDepsClosureResolver = new TransitiveDepsClosureResolver(targetGraph,
            ignoredTargetLabels);
    ImmutableMap.Builder<IjProjectElement, ImmutableMap<IjProjectElement, DependencyType>> depsBuilder = ImmutableMap
            .builder();
    Set<IjLibrary> referencedLibraries = new HashSet<>();
    Optional<Path> extraCompileOutputRootPath = projectConfig.getExtraCompilerOutputModulesPath();

    for (IjModule module : ImmutableSet.copyOf(rulesToModules.values())) {
        Map<IjProjectElement, DependencyType> moduleDeps = new LinkedHashMap<>();

        if (!module.getExtraClassPathDependencies().isEmpty()) {
            IjLibrary extraClassPathLibrary = IjLibrary.builder()
                    .setBinaryJars(module.getExtraClassPathDependencies()).setTargets(ImmutableSet.of())
                    .setName("library_" + module.getName() + "_extra_classpath").build();
            moduleDeps.put(extraClassPathLibrary, DependencyType.PROD);
        }

        if (extraCompileOutputRootPath.isPresent() && !module.getExtraModuleDependencies().isEmpty()) {
            IjModule extraModule = createExtraModuleForCompilerOutput(module, extraCompileOutputRootPath.get());
            moduleDeps.put(extraModule, DependencyType.PROD);
            depsBuilder.put(extraModule, ImmutableMap.of());
        }

        for (Map.Entry<BuildTarget, DependencyType> entry : module.getDependencies().entrySet()) {
            BuildTarget depBuildTarget = entry.getKey();
            TargetNode<?> depTargetNode = targetGraph.get(depBuildTarget);

            CommonDescriptionArg arg = (CommonDescriptionArg) depTargetNode.getConstructorArg();
            if (arg.labelsContainsAnyOf(ignoredTargetLabels)) {
                continue;
            }

            DependencyType depType = entry.getValue();
            ImmutableSet<IjProjectElement> depElements;
            ImmutableSet<IjProjectElement> transitiveDepElements = ImmutableSet.of();

            if (depType.equals(DependencyType.COMPILED_SHADOW)) {
                Optional<IjLibrary> library = libraryFactory.getLibrary(depTargetNode);
                if (library.isPresent()) {
                    depElements = ImmutableSet.of(library.get());
                } else {
                    depElements = ImmutableSet.of();
                }
            } else {
                depElements = getProjectElementFromBuildTargets(targetGraph, libraryFactory, rulesToModules,
                        module,
                        Stream.concat(
                                exportedDepsClosureResolver.getExportedDepsClosure(depBuildTarget).stream(),
                                Stream.of(depBuildTarget)));
                if (projectConfig.isIncludeTransitiveDependency()) {
                    transitiveDepElements = getProjectElementFromBuildTargets(targetGraph, libraryFactory,
                            rulesToModules, module,
                            Stream.concat(transitiveDepsClosureResolver.getTransitiveDepsClosure(depBuildTarget)
                                    .stream(), Stream.of(depBuildTarget)));
                }
            }

            for (IjProjectElement depElement : transitiveDepElements) {
                Preconditions.checkState(!depElement.equals(module));
                DependencyType.putWithMerge(moduleDeps, depElement, DependencyType.RUNTIME);
            }
            for (IjProjectElement depElement : depElements) {
                Preconditions.checkState(!depElement.equals(module));
                DependencyType.putWithMerge(moduleDeps, depElement, depType);
            }
        }

        moduleDeps.keySet().stream().filter(dep -> dep instanceof IjLibrary).map(library -> (IjLibrary) library)
                .forEach(referencedLibraries::add);

        depsBuilder.put(module, ImmutableMap.copyOf(moduleDeps));
    }

    referencedLibraries.forEach(library -> depsBuilder.put(library, ImmutableMap.of()));

    return new IjModuleGraph(depsBuilder.build());
}

From source file:org.grycap.gpf4med.DocumentManager.java

public ImmutableCollection<Document> listDocuments() {
    final ImmutableMap<String, Document> documents = documents(-1, null);
    return documents != null ? documents.values() : new ImmutableList.Builder<Document>().build();
}

From source file:org.grycap.gpf4med.DocumentManager.java

public ImmutableCollection<Document> listDocuments(int idCenter) {
    final ImmutableMap<String, Document> documents = documents(idCenter, null);
    return documents != null ? documents.values() : new ImmutableList.Builder<Document>().build();
}

From source file:org.grycap.gpf4med.DocumentManager.java

public ImmutableCollection<Document> listDocuments(String idOntology) {
    final ImmutableMap<String, Document> documents = documents(-1, idOntology);
    return documents != null ? documents.values() : new ImmutableList.Builder<Document>().build();
}

From source file:org.grycap.gpf4med.DocumentManager.java

public ImmutableCollection<Document> listDocuments(int idCenter, String idOntology) {
    final ImmutableMap<String, Document> documents = documents(idCenter, idOntology);
    return documents != null ? documents.values() : new ImmutableList.Builder<Document>().build();
}

From source file:org.elasticsearch.gateway.blobstore.BlobStoreGateway.java

private int findLatestIndex() throws IOException {
    ImmutableMap<String, BlobMetaData> blobs = metaDataBlobContainer.listBlobsByPrefix("metadata-");

    int index = -1;
    for (BlobMetaData md : blobs.values()) {
        if (logger.isTraceEnabled()) {
            logger.trace("[findLatestMetadata]: Processing [" + md.name() + "]");
        }/*w  w w  . j  a va  2  s  . c o  m*/
        String name = md.name();
        int fileIndex = Integer.parseInt(name.substring(name.indexOf('-') + 1));
        if (fileIndex >= index) {
            // try and read the meta data
            byte[] data = null;
            try {
                data = metaDataBlobContainer.readBlobFully(name);
                readMetaData(data);
                index = fileIndex;
            } catch (IOException e) {
                logger.warn(
                        "[findLatestMetadata]: failed to read metadata from [{}], data_length [{}] ignoring...",
                        e, name, data == null ? "na" : data.length);
            }
        }
    }

    return index;
}