Example usage for com.google.common.collect ImmutableSetMultimap copyOf

List of usage examples for com.google.common.collect ImmutableSetMultimap copyOf

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSetMultimap copyOf.

Prototype

@Beta
public static <K, V> ImmutableSetMultimap<K, V> copyOf(
        Iterable<? extends Entry<? extends K, ? extends V>> entries) 

Source Link

Document

Returns an immutable multimap containing the specified entries.

Usage

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

/** Indexes {@code bindingDeclarations} by {@link BindingDeclaration#key()}. */
private static <T extends BindingDeclaration> ImmutableSetMultimap<Key, T> indexBindingDeclarationsByKey(
        Iterable<T> declarations) {
    return ImmutableSetMultimap.copyOf(Multimaps.index(declarations, BindingDeclaration::key));
}

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

/**
 * Transform a map from scheme name to `TargetNode` to scheme name to the associated `PBXProject`.
 *
 * @param schemeToTargetNodes Map to transform.
 * @return Map of scheme name to associated `PXBProject`s.
 *//*ww  w.j av  a2s .com*/
private static ImmutableSetMultimap<String, PBXTarget> mapFromSchemeToPBXProject(
        ImmutableSetMultimap<String, ? extends TargetNode<?>> schemeToTargetNodes,
        ImmutableMap<BuildTarget, PBXTarget> buildTargetToPBXTarget) {
    ImmutableSetMultimap<String, PBXTarget> schemeToPBXProject = ImmutableSetMultimap
            .copyOf(schemeToTargetNodes.entries().stream()
                    .map(stringTargetNodeEntry -> Maps.immutableEntry(stringTargetNodeEntry.getKey(),
                            buildTargetToPBXTarget.get(stringTargetNodeEntry.getValue().getBuildTarget())))
                    .filter(stringPBXTargetEntry -> {
                        return stringPBXTargetEntry.getValue() != null;
                    }).collect(Collectors.toList()));
    return schemeToPBXProject;
}

From source file:grakn.core.graql.reasoner.query.ReasonerQueryImpl.java

@Override
public ImmutableSetMultimap<Variable, Type> getVarTypeMap(boolean inferTypes) {
    if (!inferTypes)
        return ImmutableSetMultimap.copyOf(getVarTypeMap(getAtoms(IsaAtomBase.class)));
    return getVarTypeMap();
}

From source file:grakn.core.graql.reasoner.query.ReasonerQueryImpl.java

@Override
public ImmutableSetMultimap<Variable, Type> getVarTypeMap(ConceptMap sub) {
    return ImmutableSetMultimap
            .copyOf(getVarTypeMap(Stream.concat(getAtoms(IsaAtomBase.class), inferEntityTypes(sub))));
}

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

/**
 * Transform a map from scheme name to `TargetNode` to scheme name to the associated `PBXProject`.
 * This wraps `mapFromSchemeToPBXProject` with added functionality filters out null target nodes.
 *
 * @param schemeToOptionalTargetNodes Map to transform.
 * @return Map of scheme name to associated `PXBProject`s.
 *///from  w  ww.  j  a va  2  s . com
private static ImmutableSetMultimap<String, PBXTarget> mapFromOptionalSchemeToPBXProject(
        ImmutableSetMultimap<String, Optional<TargetNode<?>>> schemeToOptionalTargetNodes,
        ImmutableMap<BuildTarget, PBXTarget> buildTargetToPBXTarget) {
    // filter out map entries that are null
    ImmutableSetMultimap<String, TargetNode<?>> schemeToTargetNodes = ImmutableSetMultimap
            .copyOf(schemeToOptionalTargetNodes.entries().stream().filter(stringOptionalEntry -> { // removes scheme mapped to null
                return stringOptionalEntry.getValue().isPresent();
            }).map(stringOptionalEntry -> {
                // force map to non-Optional value since those values are filtered above
                return Maps.immutableEntry(stringOptionalEntry.getKey(), stringOptionalEntry.getValue().get());
            }).collect(Collectors.toList()));

    return mapFromSchemeToPBXProject(schemeToTargetNodes, buildTargetToPBXTarget);
}

From source file:org.joda.beans.gen.ImmGuava.java

/**
 * Creates an instance./*from   w w  w.j av  a  2s  .  c  o m*/
 * @param collection  the value of the property, not null
 * @param list  the value of the property, not null
 * @param set  the value of the property, not null
 * @param sortedSet  the value of the property, not null
 * @param map  the value of the property, not null
 * @param sortedMap  the value of the property, not null
 * @param biMap  the value of the property, not null
 * @param multimap  the value of the property, not null
 * @param listMultimap  the value of the property, not null
 * @param setMultimap  the value of the property, not null
 * @param multiset  the value of the property, not null
 * @param sortedMultiset  the value of the property, not null
 * @param collectionInterface  the value of the property, not null
 * @param listInterface  the value of the property, not null
 * @param setInterface  the value of the property, not null
 * @param sortedSetInterface  the value of the property, not null
 * @param mapInterface  the value of the property, not null
 * @param sortedMapInterface  the value of the property, not null
 * @param biMapInterface  the value of the property, not null
 * @param multimapInterface  the value of the property, not null
 * @param listMultimapInterface  the value of the property, not null
 * @param setMultimapInterface  the value of the property, not null
 * @param multisetInterface  the value of the property, not null
 * @param sortedMultisetInterface  the value of the property, not null
 * @param listWildExtendsT  the value of the property, not null
 * @param listWildExtendsNumber  the value of the property, not null
 * @param listWildExtendsComparable  the value of the property, not null
 * @param setWildExtendsT  the value of the property, not null
 * @param setWildExtendsNumber  the value of the property, not null
 * @param setWildExtendsComparable  the value of the property, not null
 * @param listWildBuilder1  the value of the property, not null
 * @param listWildBuilder2  the value of the property, not null
 * @param mapWildBuilder1  the value of the property, not null
 */
public ImmGuava(Collection<T> collection, List<T> list, Set<T> set, SortedSet<T> sortedSet, Map<T, String> map,
        SortedMap<T, String> sortedMap, BiMap<T, String> biMap, Multimap<T, String> multimap,
        ListMultimap<T, String> listMultimap, SetMultimap<T, String> setMultimap, Multiset<T> multiset,
        SortedMultiset<T> sortedMultiset, Collection<T> collectionInterface, List<T> listInterface,
        Set<T> setInterface, SortedSet<T> sortedSetInterface, Map<T, String> mapInterface,
        SortedMap<T, String> sortedMapInterface, BiMap<T, String> biMapInterface,
        Multimap<T, String> multimapInterface, ListMultimap<T, String> listMultimapInterface,
        SetMultimap<T, String> setMultimapInterface, Multiset<T> multisetInterface,
        SortedMultiset<T> sortedMultisetInterface, List<? extends T> listWildExtendsT,
        List<? extends Number> listWildExtendsNumber, List<? extends Comparable<?>> listWildExtendsComparable,
        Set<? extends T> setWildExtendsT, Set<? extends Number> setWildExtendsNumber,
        Set<? extends Comparable<?>> setWildExtendsComparable, List<?> listWildBuilder1,
        List<? extends Address> listWildBuilder2, Map<String, ? extends Address> mapWildBuilder1) {
    JodaBeanUtils.notNull(collection, "collection");
    JodaBeanUtils.notNull(list, "list");
    JodaBeanUtils.notNull(set, "set");
    JodaBeanUtils.notNull(sortedSet, "sortedSet");
    JodaBeanUtils.notNull(map, "map");
    JodaBeanUtils.notNull(sortedMap, "sortedMap");
    JodaBeanUtils.notNull(biMap, "biMap");
    JodaBeanUtils.notNull(multimap, "multimap");
    JodaBeanUtils.notNull(listMultimap, "listMultimap");
    JodaBeanUtils.notNull(setMultimap, "setMultimap");
    JodaBeanUtils.notNull(multiset, "multiset");
    JodaBeanUtils.notNull(sortedMultiset, "sortedMultiset");
    JodaBeanUtils.notNull(collectionInterface, "collectionInterface");
    JodaBeanUtils.notNull(listInterface, "listInterface");
    JodaBeanUtils.notNull(setInterface, "setInterface");
    JodaBeanUtils.notNull(sortedSetInterface, "sortedSetInterface");
    JodaBeanUtils.notNull(mapInterface, "mapInterface");
    JodaBeanUtils.notNull(sortedMapInterface, "sortedMapInterface");
    JodaBeanUtils.notNull(biMapInterface, "biMapInterface");
    JodaBeanUtils.notNull(multimapInterface, "multimapInterface");
    JodaBeanUtils.notNull(listMultimapInterface, "listMultimapInterface");
    JodaBeanUtils.notNull(setMultimapInterface, "setMultimapInterface");
    JodaBeanUtils.notNull(multisetInterface, "multisetInterface");
    JodaBeanUtils.notNull(sortedMultisetInterface, "sortedMultisetInterface");
    JodaBeanUtils.notNull(listWildExtendsT, "listWildExtendsT");
    JodaBeanUtils.notNull(listWildExtendsNumber, "listWildExtendsNumber");
    JodaBeanUtils.notNull(listWildExtendsComparable, "listWildExtendsComparable");
    JodaBeanUtils.notNull(setWildExtendsT, "setWildExtendsT");
    JodaBeanUtils.notNull(setWildExtendsNumber, "setWildExtendsNumber");
    JodaBeanUtils.notNull(setWildExtendsComparable, "setWildExtendsComparable");
    JodaBeanUtils.notNull(listWildBuilder1, "listWildBuilder1");
    JodaBeanUtils.notNull(listWildBuilder2, "listWildBuilder2");
    JodaBeanUtils.notNull(mapWildBuilder1, "mapWildBuilder1");
    this.collection = ImmutableList.copyOf(collection);
    this.list = ImmutableList.copyOf(list);
    this.set = ImmutableSet.copyOf(set);
    this.sortedSet = ImmutableSortedSet.copyOfSorted(sortedSet);
    this.map = ImmutableMap.copyOf(map);
    this.sortedMap = ImmutableSortedMap.copyOfSorted(sortedMap);
    this.biMap = ImmutableBiMap.copyOf(biMap);
    this.multimap = ImmutableMultimap.copyOf(multimap);
    this.listMultimap = ImmutableListMultimap.copyOf(listMultimap);
    this.setMultimap = ImmutableSetMultimap.copyOf(setMultimap);
    this.multiset = ImmutableMultiset.copyOf(multiset);
    this.sortedMultiset = ImmutableSortedMultiset.copyOfSorted(sortedMultiset);
    this.collectionInterface = ImmutableList.copyOf(collectionInterface);
    this.listInterface = ImmutableList.copyOf(listInterface);
    this.setInterface = ImmutableSet.copyOf(setInterface);
    this.sortedSetInterface = ImmutableSortedSet.copyOfSorted(sortedSetInterface);
    this.mapInterface = ImmutableMap.copyOf(mapInterface);
    this.sortedMapInterface = ImmutableSortedMap.copyOfSorted(sortedMapInterface);
    this.biMapInterface = ImmutableBiMap.copyOf(biMapInterface);
    this.multimapInterface = ImmutableMultimap.copyOf(multimapInterface);
    this.listMultimapInterface = ImmutableListMultimap.copyOf(listMultimapInterface);
    this.setMultimapInterface = ImmutableSetMultimap.copyOf(setMultimapInterface);
    this.multisetInterface = ImmutableMultiset.copyOf(multisetInterface);
    this.sortedMultisetInterface = ImmutableSortedMultiset.copyOfSorted(sortedMultisetInterface);
    this.listWildExtendsT = ImmutableList.copyOf(listWildExtendsT);
    this.listWildExtendsNumber = ImmutableList.copyOf(listWildExtendsNumber);
    this.listWildExtendsComparable = ImmutableList.copyOf(listWildExtendsComparable);
    this.setWildExtendsT = ImmutableSet.copyOf(setWildExtendsT);
    this.setWildExtendsNumber = ImmutableSet.copyOf(setWildExtendsNumber);
    this.setWildExtendsComparable = ImmutableSet.copyOf(setWildExtendsComparable);
    this.listWildBuilder1 = ImmutableList.copyOf(listWildBuilder1);
    this.listWildBuilder2 = ImmutableList.copyOf(listWildBuilder2);
    this.mapWildBuilder1 = ImmutableMap.copyOf(mapWildBuilder1);
}

From source file:org.xbib.tools.merge.zdb.licenseinfo.WithHoldingsAndLicensesPipeline.java

private void indexManifestation(Manifestation m, Set<String> visited) throws IOException {
    String id = m.externalID();/*from  w  w  w. j  av  a  2s  .  com*/
    // protection against recursion (should not happen)
    if (visited.contains(id)) {
        return;
    }
    visited.add(id);
    // make sure at other threads that we do never index a manifestation twice
    if (service.indexed().contains(id)) {
        return;
    }
    service.indexed().add(id);
    String tag = service.settings().get("tag");

    // first, index related volumes (conference/proceedings/abstracts/...)
    List<String> vids = newArrayList();
    if (!m.getVolumes().isEmpty()) {
        final ImmutableList<Volume> volumes;
        synchronized (m.getVolumes()) {
            volumes = ImmutableList.copyOf(m.getVolumes());
        }
        for (Volume volume : volumes) {
            XContentBuilder builder = jsonBuilder();
            String vid = volume.build(builder, tag, null);
            service.ingest().index(manifestationsIndex, manifestationsIndexType, vid, builder.string());
            vids.add(vid);
            for (VolumeHolding volumeHolding : volume.getHoldings()) {
                builder = jsonBuilder();
                vid = volumeHolding.build(builder, tag);
                // by holding
                service.ingest().index(holdingsIndex, holdingsIndexType, vid, builder.string());
                // extra entry by date
                service.ingest().index(dateHoldingsIndex, dateHoldingsIndexType,
                        vid + "." + volumeHolding.dates().get(0), builder.string());
            }
            int n = 1 + 2 * volume.getHoldings().size();
            service.indexMetric().mark(n);
        }
        int n = m.getVolumes().size();
        service.indexMetric().mark(n);
    }
    m.addVolumeIDs(vids);

    // index this manifestation
    XContentBuilder builder = jsonBuilder();
    String docid = m.build(builder, tag, null);
    service.ingest().index(manifestationsIndex, manifestationsIndexType, docid, builder.string());
    service.indexMetric().mark(1);
    // holdings by date and the services for them
    if (!m.getVolumesByDate().isEmpty()) {
        SetMultimap<Integer, Holding> volumesByDate;
        synchronized (m.getVolumesByDate()) {
            volumesByDate = ImmutableSetMultimap.copyOf(m.getVolumesByDate());
        }
        for (Integer date : volumesByDate.keySet()) {
            String identifier = (tag != null ? tag + "." : "") + m.externalID()
                    + (date != -1 ? "." + date : "");
            Set<Holding> holdings = volumesByDate.get(date);
            if (holdings != null && !holdings.isEmpty()) {
                builder = jsonBuilder();
                docid = m.buildHoldingsByDate(builder, tag, m.externalID(), date, holdings);
                service.ingest().index(dateHoldingsIndex, dateHoldingsIndexType, identifier, builder.string());
                service.indexMetric().mark(1);
                logger.debug("indexed volume {} date {}", docid, date);
            }
        }
    }
    // holdings (list of institutions)
    if (!m.getVolumesByHolder().isEmpty()) {
        final SetMultimap<String, Holding> holdings;
        synchronized (m.getVolumesByHolder()) {
            holdings = ImmutableSetMultimap.copyOf(m.getVolumesByHolder());
        }
        builder = jsonBuilder();
        builder.startObject().startArray("holdings");
        for (String holder : holdings.keySet()) {
            docid = m.buildHoldingsByISIL(builder, tag, m.externalID(), holder, holdings.get(holder));
        }
        builder.endArray().endObject();
        service.ingest().index(holdingsIndex, holdingsIndexType, docid, builder.string());
        service.indexMetric().mark(1);
        logger.debug("indexed {} holdings for {}", holdings.size(), docid);
    }
    // index related manifestations
    if (!m.getRelatedManifestations().isEmpty()) {
        SetMultimap<String, Manifestation> rels;
        synchronized (m.getRelatedManifestations()) {
            rels = ImmutableSetMultimap.copyOf(m.getRelatedManifestations());
        }
        for (String rel : rels.keys()) {
            for (Manifestation mm : rels.get(rel)) {
                indexManifestation(mm, visited);
            }
        }
    }
}

From source file:com.facebook.buck.config.BuckConfig.java

/**
 * In a {@link BuckConfig}, an alias can either refer to a fully-qualified build target, or an
 * alias defined earlier in the {@code alias} section. The mapping produced by this method
 * reflects the result of resolving all aliases as values in the {@code alias} section.
 *///  w  w w.j a  va 2 s  .com
private ImmutableSetMultimap<String, BuildTarget> createAliasToBuildTargetMap(
        ImmutableMap<String, String> rawAliasMap) {
    // We use a LinkedHashMap rather than an ImmutableMap.Builder because we want both (1) order to
    // be preserved, and (2) the ability to inspect the Map while building it up.
    SetMultimap<String, BuildTarget> aliasToBuildTarget = LinkedHashMultimap.create();
    for (Map.Entry<String, String> aliasEntry : rawAliasMap.entrySet()) {
        String alias = aliasEntry.getKey();
        validateAliasName(alias);

        // Determine whether the mapping is to a build target or to an alias.
        List<String> values = Splitter.on(' ').splitToList(aliasEntry.getValue());
        for (String value : values) {
            Set<BuildTarget> buildTargets;
            if (isValidAliasName(value)) {
                buildTargets = aliasToBuildTarget.get(value);
                if (buildTargets.isEmpty()) {
                    throw new HumanReadableException("No alias for: %s.", value);
                }
            } else if (value.isEmpty()) {
                continue;
            } else {
                // Here we parse the alias values with a BuildTargetParser to be strict. We could be
                // looser and just grab everything between "//" and ":" and assume it's a valid base path.
                buildTargets = ImmutableSet.of(BuildTargetParser.INSTANCE.parse(value,
                        BuildTargetPatternParser.fullyQualified(), getCellPathResolver()));
            }
            aliasToBuildTarget.putAll(alias, buildTargets);
        }
    }
    return ImmutableSetMultimap.copyOf(aliasToBuildTarget);
}

From source file:org.xbib.tools.merge.zdb.licenseinfo.timeline.WithHoldingsAndLicensesInTimelinePipeline.java

private void indexManifestation(Manifestation m, Set<String> visited) throws IOException {
    String id = m.externalID();/*w  w w .  jav a  2  s  .  co m*/
    // protection against recursion (should not happen)
    if (visited.contains(id)) {
        return;
    }
    visited.add(id);
    // make sure at other threads that we do never index a manifestation twice
    if (service.indexed().contains(id)) {
        return;
    }
    service.indexed().add(id);

    // index this manifestation
    String tag = service.settings().get("tag");
    XContentBuilder builder = jsonBuilder();
    String docid = m.build(builder, tag, null);
    if (docid != null) {
        service.ingest().index(manifestationsIndex, manifestationsIndexType, docid, builder.string());
    }
    // volumes by date and the services for them
    Integer volumeHoldingsCount = 0;
    if (!m.getVolumesByDate().isEmpty()) {
        SetMultimap<Integer, Holding> volumesByDate;
        synchronized (m.getVolumesByDate()) {
            volumesByDate = ImmutableSetMultimap.copyOf(m.getVolumesByDate());
        }
        for (Integer date : volumesByDate.keySet()) {
            String identifier = (tag != null ? tag + "." : "") + m.externalID()
                    + (date != -1 ? "." + date : "");
            Set<Holding> holdings = volumesByDate.get(date);
            if (holdings != null && !holdings.isEmpty()) {
                builder = jsonBuilder();
                docid = m.buildHoldingsByDate(builder, tag, m.externalID(), date, holdings);
                if (docid != null) {
                    service.ingest().index(volumesIndex, volumesIndexType, identifier, builder.string());
                    serviceMetric.mark(1);
                    if (logger.isDebugEnabled()) {
                        logger.debug("indexed volume identifier {}, date {}", docid, date);
                    }
                    volumeHoldingsCount++;
                }
            }
        }
    }
    // holdings (list of institutions)
    if (!m.getVolumesByHolder().isEmpty()) {
        SetMultimap<String, Holding> holdings;
        synchronized (m.getVolumesByHolder()) {
            holdings = ImmutableSetMultimap.copyOf(m.getVolumesByHolder());
        }
        builder = jsonBuilder();
        builder.startObject().startArray("holdings");
        for (String holder : holdings.keySet()) {
            docid = m.buildHoldingsByISIL(builder, tag, m.externalID(), holder, holdings.get(holder));
        }
        builder.endArray().endObject();
        if (docid != null) {
            service.ingest().index(holdingsIndex, holdingsIndexType, docid, builder.string());
        }
        volumeHoldingsCount++;
        serviceMetric.mark(holdings.size());
        if (logger.isDebugEnabled()) {
            logger.debug("indexed {} holdings for {}", holdings.size(), docid);
        }
        if (volumeHoldingsCount == 0) {
            logger.warn("no volumes/holdings indexed for {}", m.externalID());
        }
    }
    // index related manifestations
    if (!m.getRelatedManifestations().isEmpty()) {
        SetMultimap<String, Manifestation> rels;
        synchronized (m.getRelatedManifestations()) {
            rels = ImmutableSetMultimap.copyOf(m.getRelatedManifestations());
        }
        for (String rel : rels.keys()) {
            for (Manifestation mm : rels.get(rel)) {
                indexManifestation(mm, visited);
            }
        }
    }
}

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

/**
 * Indexes {@code haveKeys} by {@link HasKey#key()}.
 *//*from   w ww.  j  a  v a 2s . c  om*/
static <T extends HasKey> ImmutableSetMultimap<Key, T> indexByKey(Iterable<T> haveKeys) {
    return ImmutableSetMultimap.copyOf(Multimaps.index(haveKeys, HasKey::key));
}