Example usage for com.google.common.collect SetMultimap put

List of usage examples for com.google.common.collect SetMultimap put

Introduction

In this page you can find the example usage for com.google.common.collect SetMultimap put.

Prototype

boolean put(@Nullable K key, @Nullable V value);

Source Link

Document

Stores a key-value pair in this multimap.

Usage

From source file:tiger.Utils.java

public static <K, V> SetMultimap<V, K> reverseSetMultimap(SetMultimap<K, V> map) {
    SetMultimap<V, K> result = HashMultimap.create();
    for (Map.Entry<K, V> entry : map.entries()) {
        result.put(entry.getValue(), entry.getKey());
    }/*w w  w  . j  a va2s .  co  m*/
    return result;
}

From source file:uk.ac.ebi.atlas.solr.query.conditions.BaselineConditionsSearchService.java

public SetMultimap<String, String> findAssayGroupsPerExperiment(String queryString) {

    try {//from   w ww.  j  a va  2 s  . c  o  m
        SolrQuery solrQuery = queryBuilder.build(queryString);
        QueryResponse queryResponse = baselineConditionsSolrServer.query(solrQuery, SolrRequest.METHOD.POST);
        List<Condition> beans = queryResponse.getBeans(Condition.class);

        SetMultimap<String, String> result = HashMultimap.create();
        for (Condition condition : beans) {
            result.put(condition.getExperimentAccession(), condition.getAssayGroupId());
        }

        return result;
    } catch (SolrServerException e) {
        throw new IllegalStateException("Conditions index query failed!", e);
    }
}

From source file:org.eclipse.gef4.zest.fx.parts.EdgeLabelPart.java

@Override
public SetMultimap<? extends Object, String> getContentAnchorages() {
    SetMultimap<Object, String> contentAnchorages = HashMultimap.create();
    contentAnchorages.put(getContent().getKey(), getContent().getValue());
    return contentAnchorages;
}

From source file:tiger.Utils.java

/**
 * Changes give tree to {@link SetMultimap} from parent to children.
 *//*  www.  j av a  2s.c om*/
public static <T> SetMultimap<T, T> reverseTree(Map<T, T> childToParentMap) {
    SetMultimap<T, T> parentToChildrenMap = HashMultimap.create();
    for (Map.Entry<T, T> entry : childToParentMap.entrySet()) {
        parentToChildrenMap.put(entry.getValue(), entry.getKey());
    }
    return parentToChildrenMap;
}

From source file:dupfitwo.Summarizer.java

@Override
public boolean execute(final long size, final Collection<FileEntry> group) {
    /* If there is only 1 file of size 'size', a clash is impossible. */
    if (group.size() > 1) {
        final SetMultimap<Long, Path> inodeFile = clashBuf.getColl();
        for (final FileEntry fe : group) {
            inodeFile.put(fe.getInode(), fe.getPath());
        }/* w w  w  .j a  v a2  s.  com*/
        /*
         * If all files are actually the same inode, then no clash has to be
         * resolved (it's already handled efficiently by the filesystem).
         */
        if (clashBuf.getBacking().size() > 1) {
            actualSizeCounter += handler.handle(size, inodeFile.asMap().entrySet());
        }
        /* Prepare for re-use */
        clashBuf.getColl().clear();
    }
    return true;
}

From source file:io.usethesource.criterion.impl.immutable.guava.ImmutableGuavaSetMultimap.java

@Override
public JmhSetMultimap insert(JmhValue key, JmhValue value) {
    final SetMultimap<JmhValue, JmhValue> tmpContent = HashMultimap.create(content);
    tmpContent.put(key, value);

    final ImmutableSetMultimap<JmhValue, JmhValue> newContent = ImmutableSetMultimap.copyOf(tmpContent);

    return new ImmutableGuavaSetMultimap(newContent);

    //    final ImmutableSetMultimap<JmhValue, JmhValue> newContent =
    //        ImmutableSetMultimap.<JmhValue, JmhValue>builder().putAll(content).put(key, value).build();
    ////from www .j  av a  2 s. com
    //    return new ImmutableGuavaSetMultimap(newContent);
}

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

/**
 * Combine sets of rules to form a set that satisfies them all.
 * @param rules at least one set of rules
 * @return the intersection of the given rules
 *//*from  w w w  .  j  av a 2s.  c om*/
private static FilePathRestrictions combineRules(FilePathRestrictions... rules) {
    if (rules.length == 0) {
        throw new IllegalArgumentException("cannot combine an empty list of rules");
    }

    int index = 0;
    FilePathRestrictions product = rules[index++];

    while (index < rules.length) {
        final FilePathRestrictions toCombine = rules[index++];

        final Set<Character> safeCharacters = Sets.intersection(product.safeCharacters,
                toCombine.safeCharacters);

        if (safeCharacters.isEmpty()) {
            throw new IllegalArgumentException("cannot combine safe characters");
        }

        final Set<Integer> allKeys = Sets.union(product.transformationMatrix.keySet(),
                toCombine.transformationMatrix.keySet());
        final ImmutableMap<Integer, Collection<Integer>> productMatrixMap = product.transformationMatrix
                .asMap();
        final ImmutableMap<Integer, Collection<Integer>> toCombineMatrixMap = toCombine.transformationMatrix
                .asMap();
        final SetMultimap<Integer, Integer> newTransformationMatrix = HashMultimap.create();

        for (final Integer key : allKeys) {
            final Collection<Integer> values;
            if (!productMatrixMap.containsKey(key)) {
                values = toCombineMatrixMap.get(key);
            } else if (!toCombineMatrixMap.containsKey(key)) {
                values = productMatrixMap.get(key);
            } else {
                final Set<Integer> valuesSet = new HashSet<Integer>(productMatrixMap.get(key));
                valuesSet.retainAll(toCombineMatrixMap.get(key));
                if (valuesSet.isEmpty()) {
                    throw new IllegalArgumentException(
                            "cannot combine transformations for Unicode code point " + key);
                }
                values = valuesSet;
            }
            for (final Integer value : values) {
                newTransformationMatrix.put(key, value);
            }
        }

        final SetMultimap<Integer, Integer> entriesRemoved = HashMultimap.create();
        boolean transitiveClosing;
        do {
            transitiveClosing = false;
            for (final Entry<Integer, Integer> transformation : newTransformationMatrix.entries()) {
                final int to = transformation.getValue();
                if (newTransformationMatrix.containsKey(to)) {
                    final int from = transformation.getKey();
                    if (!entriesRemoved.put(from, to)) {
                        throw new IllegalArgumentException(
                                "cyclic transformation involving Unicode code point " + from);
                    }
                    newTransformationMatrix.remove(from, to);
                    newTransformationMatrix.putAll(from, newTransformationMatrix.get(to));
                    transitiveClosing = true;
                    break;
                }
            }
        } while (transitiveClosing);

        product = new FilePathRestrictions(newTransformationMatrix,
                Sets.union(product.unsafePrefixes, toCombine.unsafePrefixes),
                Sets.union(product.unsafeSuffixes, toCombine.unsafeSuffixes),
                Sets.union(product.unsafeNames, toCombine.unsafeNames), safeCharacters);
    }
    return product;
}

From source file:org.sonar.core.notification.DefaultNotificationManager.java

private void addUsersToRecipientListForChannel(List<String> users,
        SetMultimap<String, NotificationChannel> recipients, NotificationChannel channel) {
    for (String username : users) {
        recipients.put(username, channel);
    }//from w  w  w .  j ava 2s.  co  m
}

From source file:org.onosproject.net.intent.impl.LinkCollectionIntentInstaller.java

private List<FlowRuleBatchOperation> generateBatchOperations(LinkCollectionIntent intent,
        FlowRuleOperation operation) {//from ww w  .  java  2 s .  c  o m

    SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();

    for (Link link : intent.links()) {
        outputPorts.put(link.src().deviceId(), link.src().port());
    }

    for (ConnectPoint egressPoint : intent.egressPoints()) {
        outputPorts.put(egressPoint.deviceId(), egressPoint.port());
    }

    FlowRuleBatchOperation batchOperation = new FlowRuleBatchOperation(outputPorts.keys().stream()
            .map(deviceId -> createBatchEntry(operation, intent, deviceId, outputPorts.get(deviceId)))
            .collect(Collectors.toList()));

    return Collections.singletonList(batchOperation);
}

From source file:org.sonar.javascript.se.LocalVariables.java

private void add(IdentifierTree identifier, SetMultimap<Symbol, IdentifierTree> localVarIdentifiersInCfg) {
    Symbol symbol = identifier.symbol();
    if (symbol != null && isLocalVariable(symbol)) {
        localVarIdentifiersInCfg.put(identifier.symbol(), identifier);
    }//from www . j a  v  a 2  s.c o m
}