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

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

Introduction

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

Prototype

Collection<V> get(@Nullable K key);

Source Link

Document

Returns a view collection of the values associated with key in this multimap, if any.

Usage

From source file:org.andrewhitchcock.duwamish.util.Accumulators.java

@SuppressWarnings("unchecked")
public static Map<String, Object> getAccumulations(Map<String, Accumulator> accumulators,
        Multimap<String, Object> accumulationMessages) {
    Map<String, Object> results = Maps.newHashMap();
    for (Map.Entry<String, Accumulator> entry : accumulators.entrySet()) {
        String name = entry.getKey();
        Accumulator accumulator = entry.getValue();
        results.put(name, accumulator.accumulate(accumulationMessages.get(name)));
    }//from  www.j  ava  2 s .c om
    return results;
}

From source file:n3phele.factory.rest.impl.HPCloudExtractor.java

@SuppressWarnings("unchecked")
private static String getPublicAddresses(Object response) {
    String address = "";

    Multimap<String, Address> multimap = (Multimap<String, Address>) response;
    for (String access : multimap.keySet()) {
        //logger.info("multimap key access:" + access);
        Collection<Address> addresses = multimap.get(access);
        //logger.info("Collection size:" + addresses.size());
        for (@SuppressWarnings("rawtypes")
        Iterator iter = addresses.iterator(); iter.hasNext();) {
            Address add = (Address) iter.next();
            address = (add.getAddr());// ww  w .  j a  v  a  2  s  .c o  m

        }
    }

    return address;
}

From source file:com.wrmsr.wava.basic.BasicLoopInfo.java

public static Set<Name> getLoopContents(Name loop, Multimap<Name, Name> inputs,
        Multimap<Name, Name> backEdges) {
    Set<Name> seen = new HashSet<>();
    seen.add(loop);//w  w  w.  ja  va  2s.c  o m
    Queue<Name> queue = new LinkedList<>();
    inputs.get(loop).stream().filter(n -> !n.equals(loop) && backEdges.containsEntry(loop, n))
            .forEach(queue::add);
    queue.forEach(seen::add);
    while (!queue.isEmpty()) {
        Name cur = queue.poll();
        inputs.get(cur).stream().filter(input -> !seen.contains(input)).forEach(input -> {
            seen.add(input);
            queue.add(input);
        });
    }
    return seen;
}

From source file:org.ow2.mind.ui.AdlUIHelper.java

protected static void transitiveClosure(final AbstractDefinition elem,
        final Multimap<URI, AbstractDefinition> graph, final Set<AbstractDefinition> result) {
    final Collection<AbstractDefinition> values = graph.get(EcoreUtil.getURI(elem));
    if (values.isEmpty())
        return;//  w  w  w  .  j a va  2 s . c o  m

    for (final AbstractDefinition value : values) {
        if (result.add(value)) {
            // if the value was not already in the result set, visit it
            transitiveClosure(value, graph, result);
        }
    }
}

From source file:edu.cmu.cs.lti.ark.fn.evaluation.PrepareFullAnnotationJson.java

private static void writeJson(Multimap<Integer, RankedScoredRoleAssignment> predictions,
        List<String> tokenizedLines, Writer output) throws IOException {
    for (int i : xrange(tokenizedLines.size())) {
        final Collection<RankedScoredRoleAssignment> predictionsForSentence = predictions.get(i);
        final List<String> tokens = Arrays.asList(tokenizedLines.get(i).split(" "));
        final SemaforParseResult semaforParseResult = getSemaforParse(predictionsForSentence, tokens);
        output.write(semaforParseResult.toJson() + "\n");
    }/* w  w  w  .  j a  va 2 s . c  o  m*/
}

From source file:ps3joiner.Main.java

public static void mergeFiles(final Multimap<Path, Path> filesToJoin, final boolean dryRun,
        final boolean deleteSplitFiles) throws IOException {
    for (final Path wholeFilePath : filesToJoin.keySet()) {
        logger.trace("Rebuilding file {}", wholeFilePath);

        final Collection<Path> partialFiles = filesToJoin.get(wholeFilePath);

        try (final OutputStream out = new BufferedOutputStream(Files.newOutputStream(wholeFilePath))) {
            for (final Path partialFilePath : partialFiles) {
                logger.trace("Reading file {}", partialFilePath);

                try (final InputStream in = new BufferedInputStream(Files.newInputStream(partialFilePath))) {
                    if (!dryRun) {
                        ByteStreams.copy(in, out);
                    }/*from w  w w  . j a  v  a  2  s  . c  om*/
                }
                if (deleteSplitFiles && !dryRun) {
                    logger.trace("Deleting file {}", partialFilePath);
                    Files.delete(partialFilePath);
                }
            }
        }

        logger.trace("Closing file {}", wholeFilePath);
    }
}

From source file:prm4j.spec.finite.FiniteParametricProperty.java

private static <A, B> Multimap<B, A> reverseSetMultimap(Multimap<A, B> multiMap) {
    SetMultimap<B, A> reversedSetMultimap = HashMultimap.create();
    for (A a : multiMap.keySet()) {
        for (B b : multiMap.get(a)) {
            reversedSetMultimap.put(b, a);
        }//  w ww. j  a  v a2s  . c  o m
    }
    return reversedSetMultimap;
}

From source file:edu.isi.karma.modeling.research.ComputeGED.java

private static void computeGEDApp2() throws Exception {

    File ff = new File(Params.JGRAPHT_DIR);
    File[] files = ff.listFiles();

    DirectedWeightedMultigraph<Node, Link> gMain, gKarmaInitial, gKarmaFinal, gApp2;

    HashSet<File> fileSet = new HashSet<File>(Arrays.asList(files));

    Function<File, String> sameService = new Function<File, String>() {
        @Override/* w  w  w .ja va2s  . c  o m*/
        public String apply(final File s) {
            return s.getName().substring(0, s.getName().indexOf('.'));
        }
    };

    Multimap<String, File> index = Multimaps.index(fileSet, sameService);

    for (String s : index.keySet()) {

        System.out.println(s);
        Collection<File> serviceFiles = index.get(s);
        gMain = null;
        gKarmaInitial = null;
        gKarmaFinal = null;
        gApp2 = null;

        for (File f : serviceFiles) {
            if (f.getName().endsWith(".main.jgraph")) {
                gMain = GraphUtil.deserialize(f.getPath());
            } else if (f.getName().endsWith(".karma.initial.jgraph")) {
                gKarmaInitial = GraphUtil.deserialize(f.getPath());
            } else if (f.getName().endsWith(".karma.final.jgraph")) {
                gKarmaFinal = GraphUtil.deserialize(f.getPath());
            } else if (f.getName().endsWith(".app2.jgraph")) {
                gApp2 = GraphUtil.deserialize(f.getPath());
            }
        }

        if (gMain == null)
            continue;
        String label;
        double distance;

        Map<String, DirectedWeightedMultigraph<Node, Link>> graphs = new TreeMap<String, DirectedWeightedMultigraph<Node, Link>>();

        label = "0- Main";
        graphs.put(label, gMain);

        if (gKarmaInitial != null) {
            distance = Util.getDistance(gMain, gKarmaInitial);
            label = "1-Karma Initial" + "-distance:" + distance;
            graphs.put(label, gKarmaInitial);
        }

        if (gKarmaFinal != null) {
            distance = Util.getDistance(gMain, gKarmaFinal);
            label = "3-Karma Final" + "-distance:" + distance;
            graphs.put(label, gKarmaFinal);
        }

        if (gApp2 != null) {
            distance = Util.getDistance(gMain, gApp2);
            label = "2-Output" + "-distance:" + distance;
            graphs.put(label, gApp2);
        }

        GraphVizUtil.exportJGraphToGraphvizFile(graphs, s, Params.OUTPUT_DIR + s + ".app2.out.dot");
    }
}

From source file:org.semanticweb.owlapi.model.OWLDocumentFormat.java

/**
 * @param punnings//from   www  .  j a v a2  s .c o  m
 *        input punnings
 * @return illegal punnings
 */
static Collection<IRI> computeIllegals(Multimap<IRI, EntityType<?>> punnings) {
    Collection<IRI> illegals = new HashSet<>();
    for (IRI i : punnings.keySet()) {
        Collection<EntityType<?>> puns = punnings.get(i);
        if (puns.contains(EntityType.OBJECT_PROPERTY) && puns.contains(EntityType.ANNOTATION_PROPERTY)) {
            illegals.add(i);
        } else if (puns.contains(EntityType.DATA_PROPERTY) && puns.contains(EntityType.ANNOTATION_PROPERTY)) {
            illegals.add(i);
        } else if (puns.contains(EntityType.DATA_PROPERTY) && puns.contains(EntityType.OBJECT_PROPERTY)) {
            illegals.add(i);
        } else if (puns.contains(EntityType.DATATYPE) && puns.contains(EntityType.CLASS)) {
            illegals.add(i);
        }
    }
    return illegals;
}

From source file:org.apache.james.webadmin.dto.MailDto.java

private static HeadersDto fetchPerRecipientHeader(
        Multimap<MailAddress, PerRecipientHeaders.Header> headersByRecipient, MailAddress address) {
    return new HeadersDto(headersByRecipient.get(address).stream().collect(Guavate.toImmutableListMultimap(
            PerRecipientHeaders.Header::getName, PerRecipientHeaders.Header::getValue)));
}