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

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

Introduction

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

Prototype

@Override
Set<V> get(@Nullable K key);

Source Link

Document

Because a SetMultimap has unique values for a given key, this method returns a Set , instead of the java.util.Collection specified in the Multimap interface.

Usage

From source file:org.apache.flume.channel.file.EventQueueBackingStoreFile.java

public static void main(String[] args) throws Exception {
    File file = new File(args[0]);
    File inflightTakesFile = new File(args[1]);
    File inflightPutsFile = new File(args[2]);
    if (!file.exists()) {
        throw new IOException("File " + file + " does not exist");
    }// www .j a  v a 2 s  .  co m
    if (file.length() == 0) {
        throw new IOException("File " + file + " is empty");
    }
    int capacity = (int) ((file.length() - (HEADER_SIZE * 8L)) / 8L);
    EventQueueBackingStoreFile backingStore = (EventQueueBackingStoreFile) EventQueueBackingStoreFactory
            .get(file, capacity, "debug", false);
    System.out.println("File Reference Counts" + backingStore.logFileIDReferenceCounts);
    System.out.println("Queue Capacity " + backingStore.getCapacity());
    System.out.println("Queue Size " + backingStore.getSize());
    System.out.println("Queue Head " + backingStore.getHead());
    for (int index = 0; index < backingStore.getCapacity(); index++) {
        long value = backingStore.get(backingStore.getPhysicalIndex(index));
        int fileID = (int) (value >>> 32);
        int offset = (int) value;
        System.out.println(
                index + ":" + Long.toHexString(value) + " fileID = " + fileID + ", offset = " + offset);
    }
    FlumeEventQueue queue = new FlumeEventQueue(backingStore, inflightTakesFile, inflightPutsFile);
    SetMultimap<Long, Long> putMap = queue.deserializeInflightPuts();
    System.out.println("Inflight Puts:");

    for (Long txnID : putMap.keySet()) {
        Set<Long> puts = putMap.get(txnID);
        System.out.println("Transaction ID: " + String.valueOf(txnID));
        for (long value : puts) {
            int fileID = (int) (value >>> 32);
            int offset = (int) value;
            System.out.println(Long.toHexString(value) + " fileID = " + fileID + ", offset = " + offset);
        }
    }
    SetMultimap<Long, Long> takeMap = queue.deserializeInflightTakes();
    System.out.println("Inflight takes:");
    for (Long txnID : takeMap.keySet()) {
        Set<Long> takes = takeMap.get(txnID);
        System.out.println("Transaction ID: " + String.valueOf(txnID));
        for (long value : takes) {
            int fileID = (int) (value >>> 32);
            int offset = (int) value;
            System.out.println(Long.toHexString(value) + " fileID = " + fileID + ", offset = " + offset);
        }
    }
}

From source file:org.jboss.weld.util.collections.ArraySetSupplier.java

/**
 * Helper method which will trim each set in the multimap to its current size.
 *
 * @param <K>      Key type//  w  w  w  .j  av a2s . co  m
 * @param <V>      Value type
 * @param multimap the set multimap using ArraySet<V> as the values
 */
public static <K, V> void trimSetsToSize(SetMultimap<K, V> multimap) {
    for (K key : multimap.keySet()) {
        if (multimap.get(key) instanceof ArraySet<?>) {
            ((ArraySet<?>) multimap.get(key)).trimToSize();
        }
    }
}

From source file:com.google.javascript.refactoring.testing.SuggestedFixes.java

private static void assertReplacements(SuggestedFix fix, Set<CodeReplacement> expectedReplacements) {
    SetMultimap<String, CodeReplacement> replacementMap = fix.getReplacements();
    assertEquals(1, replacementMap.size());
    Set<CodeReplacement> replacements = replacementMap.get("test");
    assertThat(replacements).hasSize(expectedReplacements.size());
    assertEquals(expectedReplacements, replacements);
}

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

private static boolean isWrittenOutsideCfg(Symbol localVar,
        SetMultimap<Symbol, IdentifierTree> localVarIdentifiersInCfg) {
    for (Usage usage : localVar.usages()) {
        if (usage.isWrite() && !localVarIdentifiersInCfg.get(localVar).contains(usage.identifierTree())) {
            return true;
        }/*from w w w .j av a 2  s .com*/
    }
    return false;
}

From source file:org.onosproject.vpls.cli.VplsCommandUtils.java

/**
 * Returns a list of interfaces associated to a VPLS, given a VPLS name.
 *
 * @param vplsName the name of the VPLS//from ww w .  j a va  2  s .  c  o  m
 * @return the set of interfaces associated to the given VPLS; null if the
 * VPLS is not found
 */
protected static Set<String> ifacesFromVplsName(String vplsName) {
    if (!vplsExists(vplsName)) {
        return null;
    }

    SetMultimap<String, Interface> ifacesByVplsName = vplsConfigService.ifacesByVplsName();
    Set<String> ifaceNames = Sets.newHashSet();

    ifacesByVplsName.get(vplsName).forEach(iface -> ifaceNames.add(iface.name()));

    return ifaceNames;
}

From source file:es.usc.citius.composit.core.composition.search.CompositSearch.java

private static <E> SetMultimap<Set<E>, Operation<E>> group(SetMultimap<Operation<E>, E> conceptMap) {
    // Generate groups
    SetMultimap<Set<E>, Operation<E>> matchMap = HashMultimap.create();
    for (Operation<E> op : conceptMap.keys()) {
        matchMap.get(conceptMap.get(op)).add(op);
    }// w  w  w . jav  a2s . co  m
    return matchMap;
}

From source file:edu.cmu.lti.oaqa.baseqa.answer.CavUtil.java

private static boolean isConstituentForest(SetMultimap<Token, Token> head2children,
        Collection<Token> coveredTokens, Token token) {
    return coveredTokens.contains(token) && head2children.get(token).stream()
            .allMatch(child -> isConstituentForest(head2children, coveredTokens, child));
}

From source file:de.bund.bfr.knime.gis.views.regiontoregionvisualizer.RegionToRegionUtils.java

public static Set<String> getSelectedGraphNodeIds(Set<GraphNode> graphNodes, Set<RegionNode> selectedGisNodes) {
    SetMultimap<String, String> graphNodesByRegion = LinkedHashMultimap.create();

    for (GraphNode graphNode : graphNodes) {
        graphNodesByRegion.put(graphNode.getRegion(), graphNode.getId());
    }//ww w.ja  v  a  2s.  com

    return selectedGisNodes.stream().map(n -> graphNodesByRegion.get(n.getId())).flatMap(Set::stream)
            .collect(Collectors.toCollection(LinkedHashSet::new));
}

From source file:com.google.devtools.cyclefinder.ReferenceGraph.java

private static SetMultimap<String, Edge> makeSubgraph(SetMultimap<String, Edge> graph,
        Collection<String> vertices) {
    SetMultimap<String, Edge> subgraph = HashMultimap.create();
    for (String type : vertices) {
        for (Edge e : graph.get(type)) {
            if (vertices.contains(e.getTarget().getKey())) {
                subgraph.put(type, e);//from w  ww.j a v a  2 s  .  c om
            }
        }
    }
    return subgraph;
}

From source file:org.onosproject.vpls.cli.VplsCommand.java

/**
 * Returns a list of interfaces associated to a VPLS, given a VPLS name.
 *
 * @param vplsName the name of the VPLS// w  ww .  ja  v a  2 s  .  c  om
 * @return the set of interfaces associated to the given VPLS; null if the
 * VPLS is not found
 */
private static Set<String> ifacesFromVplsName(String vplsName) {
    if (!vplsExists(vplsName)) {
        return null;
    }
    SetMultimap<String, Interface> ifacesByVplsName = vplsConfigService.ifacesByVplsName();
    Set<String> ifaceNames = Sets.newHashSet();

    ifacesByVplsName.get(vplsName).forEach(iface -> ifaceNames.add(iface.name()));

    return ifaceNames;
}