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:com.google.gerrit.server.account.externalids.ExternalIdCacheImpl.java

private void updateCache(ObjectId oldNotesRev, ObjectId newNotesRev,
        Consumer<Multimap<Account.Id, ExternalId>> update) {
    lock.lock();/*  w  w w.ja  va  2s .  co m*/
    try {
        ListMultimap<Account.Id, ExternalId> m;
        if (!ObjectId.zeroId().equals(oldNotesRev)) {
            m = MultimapBuilder.hashKeys().arrayListValues().build(extIdsByAccount.get(oldNotesRev));
        } else {
            m = MultimapBuilder.hashKeys().arrayListValues().build();
        }
        update.accept(m);
        extIdsByAccount.put(newNotesRev, ImmutableSetMultimap.copyOf(m));
    } catch (ExecutionException e) {
        log.warn("Cannot update external IDs", e);
    } finally {
        lock.unlock();
    }
}

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

/**
 * Indexes map-multibindings by map key (the result of calling
 * {@link AnnotationValue#getValue()} on a single member or the whole {@link AnnotationMirror}
 * itself, depending on {@link MapKey#unwrapValue()}).
 *///from  www .ja  va  2s.  c o m
static ImmutableSetMultimap<Object, ContributionBinding> indexMapBindingsByMapKey(
        Set<ContributionBinding> mapBindings) {
    return ImmutableSetMultimap.copyOf(Multimaps.index(mapBindings, mapBinding -> {
        AnnotationMirror mapKey = mapBinding.mapKey().get();
        return unwrapValue(mapKey).map(AnnotationValue::getValue).orElse(mapKey);
    }));
}

From source file:org.immutables.sequence.Entries.java

public ImmutableSetMultimap<K, V> toSetMultimap() {
    HashMultimap<K, V> buffer = HashMultimap.create();
    forEach(e -> buffer.put(e.getKey(), e.getValue()));
    return ImmutableSetMultimap.copyOf(buffer);
}

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

/**
 * Indexes map-multibindings by map key annotation type.
 *//*w w  w . ja va  2 s . c  om*/
static ImmutableSetMultimap<Wrapper<DeclaredType>, ContributionBinding> indexMapBindingsByAnnotationType(
        Set<ContributionBinding> mapBindings) {
    return ImmutableSetMultimap.copyOf(Multimaps.index(mapBindings,
            mapBinding -> MoreTypes.equivalence().wrap(mapBinding.mapKey().get().getAnnotationType())));
}

From source file:org.sosy_lab.cpachecker.core.algorithm.termination.TerminationAlgorithm.java

public TerminationAlgorithm(Configuration pConfig, LogManager pLogger, ShutdownNotifier pShutdownNotifier,
        CFA pCfa, ReachedSetFactory pReachedSetFactory,
        AggregatedReachedSetManager pAggregatedReachedSetManager, Specification pSpecification,
        Algorithm pSafetyAlgorithm, ConfigurableProgramAnalysis pSafetyCPA)
        throws InvalidConfigurationException {
    pConfig.inject(this);
    logger = checkNotNull(pLogger);/*from  ww  w.  j a  v  a2  s.  co  m*/
    shutdownNotifier = pShutdownNotifier;
    cfa = checkNotNull(pCfa);
    reachedSetFactory = checkNotNull(pReachedSetFactory);
    aggregatedReachedSetManager = checkNotNull(pAggregatedReachedSetManager);
    safetyAlgorithm = checkNotNull(pSafetyAlgorithm);
    safetyCPA = checkNotNull(pSafetyCPA);

    Specification requiredSpecification = loadTerminationSpecification(pCfa, pConfig, pLogger);
    Preconditions.checkArgument(requiredSpecification.equals(pSpecification),
            "%s requires %s, but %s is given.", TerminationAlgorithm.class.getSimpleName(),
            requiredSpecification, pSpecification);

    TerminationCPA terminationCpa = CPAs.retrieveCPA(pSafetyCPA, TerminationCPA.class);
    if (terminationCpa == null) {
        throw new InvalidConfigurationException("TerminationAlgorithm requires TerminationCPA");
    }
    terminationInformation = terminationCpa.getTerminationInformation();

    ARGCPA agrCpa = CPAs.retrieveCPA(pSafetyCPA, ARGCPA.class);
    if (agrCpa == null) {
        throw new InvalidConfigurationException("TerminationAlgorithm requires ARGCPA");
    }

    DeclarationCollectionCFAVisitor visitor = new DeclarationCollectionCFAVisitor();
    for (CFANode function : cfa.getAllFunctionHeads()) {
        CFATraversal.dfs().ignoreFunctionCalls().traverseOnce(function, visitor);
    }
    localDeclarations = ImmutableSetMultimap.copyOf(visitor.localDeclarations);
    globalDeclaration = ImmutableSet.copyOf(visitor.globalDeclarations);

    LoopStructure loopStructure = cfa.getLoopStructure().orElseThrow(() -> new InvalidConfigurationException(
            "Loop structure is not present, but required for termination analysis."));
    statistics = new TerminationStatistics(pConfig, logger, loopStructure.getAllLoops().size());
    lassoAnalysis = LassoAnalysis.create(pLogger, pConfig, pShutdownNotifier, pCfa, statistics);
}

From source file:ome.services.blitz.repo.path.FilePathRestrictions.java

/**
 * Construct a set of rules by which local files may not be named on the file-system.
 * @param transformationMatrix how to make specific characters safe, may be null
 * @param unsafePrefixes which name prefixes are proscribed, may be null
 * @param unsafeSuffixes which name suffixes are proscribed, may be null
 * @param unsafeNames which names are proscribed, may be null
 * @param safeCharacters safe characters that may be used in making file names safe, may <em>not</em> be null
 *//*  w ww  . j  a  v  a2s .c  om*/
public FilePathRestrictions(SetMultimap<Integer, Integer> transformationMatrix, Set<String> unsafePrefixes,
        Set<String> unsafeSuffixes, Set<String> unsafeNames, Set<Character> safeCharacters) {
    this.transformationMatrix = transformationMatrix == null ? ImmutableSetMultimap.<Integer, Integer>of()
            : ImmutableSetMultimap.copyOf(transformationMatrix);
    this.unsafePrefixes = unsafePrefixes == null ? ImmutableSet.<String>of()
            : ImmutableSet.copyOf(unsafePrefixes);
    this.unsafeSuffixes = unsafeSuffixes == null ? ImmutableSet.<String>of()
            : ImmutableSet.copyOf(unsafeSuffixes);
    this.unsafeNames = unsafeNames == null ? ImmutableSet.<String>of() : ImmutableSet.copyOf(unsafeNames);
    this.safeCharacters = ImmutableSet.copyOf(safeCharacters);

    this.safeCharacter = this.safeCharacters.iterator().next();
    int safeCodePoint = FilePathRestrictionInstance.getCodePoint(this.safeCharacter);
    final ImmutableMap.Builder<Integer, Integer> transformationMapBuilder = ImmutableMap.builder();
    for (final Entry<Integer, Collection<Integer>> transformation : this.transformationMatrix.asMap()
            .entrySet()) {
        final Collection<Integer> values = transformation.getValue();
        final Integer selectedValue = values.contains(safeCodePoint) ? safeCodePoint : values.iterator().next();
        transformationMapBuilder.put(transformation.getKey(), selectedValue);
    }
    this.transformationMap = transformationMapBuilder.build();
}

From source file:org.terasology.module.ModuleEnvironment.java

private ImmutableSetMultimap<Name, Name> buildModuleDependencies() {
    SetMultimap<Name, Name> moduleDependenciesBuilder = HashMultimap.create();
    for (Module module : getModulesOrderedByDependencies()) {
        for (DependencyInfo dependency : module.getMetadata().getDependencies()) {
            moduleDependenciesBuilder.put(module.getId(), dependency.getId());
            moduleDependenciesBuilder.putAll(module.getId(), moduleDependenciesBuilder.get(dependency.getId()));
        }//from  w ww  .  j a va2  s  .  com
    }
    return ImmutableSetMultimap.copyOf(moduleDependenciesBuilder);
}

From source file:com.viadeo.kasper.common.exposition.query.QueryBuilder.java

public SetMultimap<String, String> build() {
    return ImmutableSetMultimap.copyOf(map);
}

From source file:edu.buaa.satla.analysis.core.predicate.PredicatePrecision.java

/**
 * Create a new precision which contains all predicates of this precision
 * and a second one.//from   w ww .j  a  v a 2s  .  c  om
 */
public PredicatePrecision mergeWith(PredicatePrecision prec) {
    // create new set of global predicates
    Collection<AbstractionPredicate> newGlobalPredicates = Lists.newArrayList(getGlobalPredicates());
    newGlobalPredicates.addAll(prec.getGlobalPredicates());
    newGlobalPredicates = ImmutableSet.copyOf(newGlobalPredicates);

    // create new multimap of function-specific predicates
    Multimap<String, AbstractionPredicate> newFunctionPredicates = ArrayListMultimap
            .create(getFunctionPredicates());
    newFunctionPredicates.putAll(prec.getFunctionPredicates());

    if (!newGlobalPredicates.isEmpty()) {
        for (String function : newFunctionPredicates.keySet()) {
            newFunctionPredicates.putAll(function, newGlobalPredicates);
        }
    }
    newFunctionPredicates = ImmutableSetMultimap.copyOf(newFunctionPredicates);

    // create new multimap of location-specific predicates
    Multimap<CFANode, AbstractionPredicate> newLocalPredicates = ArrayListMultimap.create(getLocalPredicates());
    newLocalPredicates.putAll(prec.getLocalPredicates());

    if (!newGlobalPredicates.isEmpty() || !newFunctionPredicates.isEmpty()) {
        for (CFANode loc : newLocalPredicates.keySet()) {
            newLocalPredicates.putAll(loc, newGlobalPredicates);
            newLocalPredicates.putAll(loc, newFunctionPredicates.get(loc.getFunctionName()));
        }
    }

    // create new multimap of location-instance-specific predicates
    Multimap<Pair<CFANode, Integer>, AbstractionPredicate> newLocationInstanceSpecificPredicates = ArrayListMultimap
            .create(getLocationInstancePredicates());
    newLocationInstanceSpecificPredicates.putAll(prec.getLocationInstancePredicates());

    if (!newGlobalPredicates.isEmpty() || !newFunctionPredicates.isEmpty() || !newLocalPredicates.isEmpty()) {
        for (Pair<CFANode, Integer> key : newLocationInstanceSpecificPredicates.keySet()) {
            newLocationInstanceSpecificPredicates.putAll(key, newGlobalPredicates);
            newLocationInstanceSpecificPredicates.putAll(key,
                    newFunctionPredicates.get(key.getFirst().getFunctionName()));
            newLocationInstanceSpecificPredicates.putAll(key, newLocalPredicates.get(key.getFirst()));
        }
    }

    return new PredicatePrecision(newLocationInstanceSpecificPredicates, newLocalPredicates,
            newFunctionPredicates, newGlobalPredicates);
}

From source file:org.glowroot.agent.model.Transaction.java

public ImmutableSetMultimap<String, String> getAttributes() {
    if (attributes == null) {
        return ImmutableSetMultimap.of();
    }/*ww  w.j  av  a2 s. co m*/
    SetMultimap<String, String> orderedAttributes = TreeMultimap.create(String.CASE_INSENSITIVE_ORDER,
            String.CASE_INSENSITIVE_ORDER);
    synchronized (attributes) {
        orderedAttributes.putAll(attributes);
    }
    return ImmutableSetMultimap.copyOf(orderedAttributes);
}