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:com.googlecode.blaisemath.graph.mod.metrics.BetweenCentrality.java

/**
 * Breadth-first search algorithm for an unweighted graph to generate
 * betweenness scores, with specified starting vertex. From <i>Brandes</i>,
 * "A Faster Algorithm for Betweenness Centrality"
 *
 * @param graph the graph/*  w w w.j  a  v a 2s.  c  o  m*/
 * @param start the start vertex
 * @param between data structure storing existing betweenness centrality values
 * @param multiplier applied to all elements of resulting map
 * @return data structure encoding the result
 */
static <V> Map<V, Double> brandes(Graph<V> graph, V start, Map<V, Double> between, double multiplier) {
    Set<V> nodes = graph.nodes();
    if (!nodes.contains(start)) {
        return new HashMap<V, Double>();
    }

    // number of shortest paths to each vertex
    Multiset<V> numShortest = HashMultiset.create();
    // length of shortest paths to each vertex
    Map<V, Integer> lengths = new HashMap<V, Integer>();
    // tracks elements in non-increasing order for later use
    Deque<V> deque = Queues.newArrayDeque();
    // tracks vertex predecessors in resulting tree
    Multimap<V, V> pred = HashMultimap.create();

    GraphUtils.breadthFirstSearch(graph, start, numShortest, lengths, deque, pred);

    // compute betweenness
    Map<V, Double> dependencies = new HashMap<V, Double>();
    for (V v : nodes) {
        dependencies.put(v, 0.0);
    }
    while (!deque.isEmpty()) {
        V w = deque.pollLast();
        for (V v : pred.get(w)) {
            dependencies.put(v, dependencies.get(v)
                    + (double) numShortest.count(v) / numShortest.count(w) * (1 + dependencies.get(w)));
        }
        if (w != start) {
            between.put(w, between.get(w) + multiplier * dependencies.get(w));
        }
    }

    return between;

}

From source file:org.icgc.dcc.release.job.annotate.converter.SnpEffVCFToICGCConverter.java

/**
 * Returns a set of effects sorted by priority and limited by 1
 *///from  w  w  w. ja  va2s  . c om
private static Set<SnpEffect> getFilteredEffects(Multimap<String, SnpEffect> transcriptIdMap) {
    val result = new ImmutableSet.Builder<SnpEffect>();
    for (val transcriptId : transcriptIdMap.keySet()) {
        val effectGroup = Lists.newArrayList(transcriptIdMap.get(transcriptId));
        // order by importance
        Collections.sort(effectGroup, Collections.reverseOrder());
        // limit by 1
        result.add(effectGroup.get(0));
    }

    return result.build();
}

From source file:de.unisb.cs.st.javalanche.mutation.runtime.testDriver.junit.Junit4Util.java

private static Runner getMethodsRunner(String testMethods) throws ClassNotFoundException, InitializationError {
    String[] testMethodsSplit = testMethods.split(":");
    final Multimap<String, String> methods = getMethodMap(testMethodsSplit);
    RunnerBuilder runnerBuilder = new RunnerBuilder() {
        @Override/*from ww  w.  j  ava  2 s . c  om*/
        public Runner runnerForClass(Class<?> testClass) throws Throwable {
            Request aClass = Request.aClass(testClass);
            final Collection<String> methodNames = methods.get(testClass.getName());
            Request filtered = aClass.filterWith(new Filter() {

                @Override
                public String describe() {
                    return "Javalanche test filter";
                }

                @Override
                public boolean shouldRun(Description description) {
                    String name = description.getClassName() + "." + description.getMethodName();
                    logger.debug("Testname: " + name);
                    boolean var = methodNames.contains(name);
                    return var;
                }
            });
            return filtered.getRunner();
        }
    };
    Class<?>[] classes = getClasses(methods);
    return new Suite(runnerBuilder, classes);
}

From source file:org.crypto.sse.Partition.java

public static Multimap<Integer, String> partitioning(Multimap<String, String> lookup) {

    // Partitions Creation
    Set<String> keys = lookup.keySet();

    int partitionId = 0;
    Multimap<Integer, String> partitions = ArrayListMultimap.create();
    int counter2 = 0;

    for (String key : keys) {
        Set<Integer> keys2 = partitions.keySet();
        List<String> inter = (List<String>) lookup.get(key);
        List<String> interTMP = new ArrayList<String>(inter);

        Printer.debugln("Step number: " + counter2++ + "Number of keywords " + keys.size());

        Set<String> set = new HashSet<String>(interTMP);
        Multimap<Integer, String> partitionsTMP = ArrayListMultimap.create();

        for (Integer key2 : keys2) {

            if (!set.isEmpty()) {
                Set<String> tmp = new HashSet<String>(partitions.get(key2));

                Set<String> intersection = Sets.intersection(tmp, set);

                Set<String> difference;

                if (intersection.isEmpty()) {
                    difference = tmp;//from   ww w  .j a  va 2 s  .  c o  m
                } else {
                    difference = Sets.difference(tmp, intersection);
                    set = Sets.difference(set, intersection);

                }

                if (!difference.isEmpty()) {
                    partitionId = partitionId + 1;
                    partitionsTMP.putAll(partitionId, difference);
                }

                if (!intersection.isEmpty()) {
                    partitionId = partitionId + 1;
                    partitionsTMP.putAll(partitionId, intersection);
                }

            } else {
                partitionId = partitionId + 1;
                partitionsTMP.putAll(partitionId, new HashSet<String>(partitions.get(key2)));
            }

        }

        interTMP = new ArrayList<String>(set);

        if (!interTMP.isEmpty()) {

            partitionId = partitionId + 1;
            partitionsTMP.putAll(partitionId, interTMP);

        }

        partitions = ArrayListMultimap.create(partitionsTMP);
        partitionsTMP.clear();
        interTMP.clear();

    }

    Printer.debugln("Partitions size " + partitions.keySet().size());
    Printer.debugln("\n");

    return partitions;
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.xmi.exporter.ecore.EntityClassStore.java

public static List<EObject> getPersistentObjects(List<EObject> eObjects) {
    Multimap<Class<? extends IdEntity>, EObject> orderedObjects = groupEObjects(eObjects);
    LinkedList<EObject> objects = Lists.newLinkedList();

    objects.addAll(orderedObjects.get(AttributeTypeGroup.class));

    objects.addAll(orderedObjects.get(NumberAT.class));
    objects.addAll(orderedObjects.get(DateAT.class));
    objects.addAll(orderedObjects.get(TextAT.class));
    objects.addAll(orderedObjects.get(ResponsibilityAT.class));
    objects.addAll(orderedObjects.get(EnumAT.class));

    objects.addAll(orderedObjects.get(NumberAV.class));
    objects.addAll(orderedObjects.get(DateAV.class));
    objects.addAll(orderedObjects.get(TextAV.class));
    objects.addAll(orderedObjects.get(EnumAV.class));
    objects.addAll(orderedObjects.get(ResponsibilityAV.class));
    objects.addAll(orderedObjects.get(RangeValue.class));

    objects.addAll(orderedObjects.get(DateInterval.class));

    objects.addAll(orderedObjects.get(BusinessObject.class));
    objects.addAll(orderedObjects.get(BusinessProcess.class));
    objects.addAll(orderedObjects.get(Product.class));
    objects.addAll(orderedObjects.get(BusinessDomain.class));
    objects.addAll(orderedObjects.get(BusinessFunction.class));
    objects.addAll(orderedObjects.get(BusinessUnit.class));
    objects.addAll(orderedObjects.get(InformationSystemDomain.class));
    objects.addAll(orderedObjects.get(Project.class));
    objects.addAll(orderedObjects.get(ArchitecturalDomain.class));
    objects.addAll(orderedObjects.get(TechnicalComponent.class));
    objects.addAll(orderedObjects.get(InformationSystem.class));
    objects.addAll(orderedObjects.get(InformationSystemRelease.class));
    objects.addAll(orderedObjects.get(InformationSystemInterface.class));
    objects.addAll(orderedObjects.get(TechnicalComponentRelease.class));
    objects.addAll(orderedObjects.get(InfrastructureElement.class));
    objects.addAll(orderedObjects.get(Transport.class));
    objects.addAll(orderedObjects.get(BusinessMapping.class));
    objects.addAll(orderedObjects.get(Tcr2IeAssociation.class));
    objects.addAll(orderedObjects.get(Isr2BoAssociation.class));

    objects.addAll(orderedObjects.get(CustomDashboardInstance.class));
    objects.addAll(orderedObjects.get(CustomDashboardTemplate.class));

    return objects;
}

From source file:com.eucalyptus.cloudwatch.domain.metricdata.MetricManager.java

private static void addManyMetrics(Multimap<Class, MetricEntity> metricMap) {
    for (Class c : metricMap.keySet()) {
        EntityTransaction db = Entities.get(c);
        try {//w w  w .  j ava 2  s .  c  o m
            for (MetricEntity me : metricMap.get(c)) {
                Entities.persist(me);
            }
            db.commit();
        } catch (RuntimeException ex) {
            Logs.extreme().error(ex, ex);
            throw ex;
        } finally {
            if (db.isActive())
                db.rollback();
        }
    }
}

From source file:ca.sqlpower.dao.PersisterUtils.java

/**
 * Returns true if there is a boolean property persisted on the given UUID
 * with the given property name and the property is being set to true.
 * Returns false if there is a boolean property persisted on the given UUID
 * with the given property name and the property is being set to false.
 * Returns null if the persist call does not exist.
 * /*from w w  w .ja  v  a2  s. com*/
 * @param persistedProperties
 *            The list of properties that have been persisted to search for
 *            the persist call.
 * @param parentUUID
 *            The UUID of the object we are looking for the boolean property
 *            of.
 * @param propName
 *            The property name that describes a boolean property. The
 *            property if it exists must represent a boolean.
 * @return
 */
public static Boolean findPersistedBooleanProperty(Multimap<String, PersistedSPOProperty> persistedProperties,
        String parentUUID, String propName) {
    Collection<PersistedSPOProperty> properties = persistedProperties.get(parentUUID);
    if (properties == null || properties.isEmpty())
        return null;
    for (PersistedSPOProperty property : properties) {
        if (property.getPropertyName().equals(propName)) {
            return (Boolean) property.getNewValue();
        }
    }
    return null;
}

From source file:org.sonar.plsqlopen.checks.verifier.PlSqlCheckVerifier.java

private static void validateIssue(Multimap<Integer, Map<IssueAttribute, String>> expected,
        List<Integer> unexpectedLines, AnalyzerMessage issue) {
    int line = issue.getLine();
    if (expected.containsKey(line)) {
        Map<IssueAttribute, String> attrs = Iterables.getLast(expected.get(line));
        assertEquals(issue.getText(Locale.ENGLISH), attrs, IssueAttribute.MESSAGE);
        validateAnalyzerMessage(attrs, issue);
        expected.remove(line, attrs);/*from  w w w.j a  v  a 2s.c om*/
    } else {
        unexpectedLines.add(line);
    }
}

From source file:ezbake.common.http.request.Request.java

private static String getFirst(Multimap<String, String> m, String name) {
    Collection<String> values = m.get(name.toUpperCase());
    if (values == null || values.isEmpty())
        return null;
    return Iterables.getFirst(values, null);
}

From source file:nova.core.wrapper.mc.forge.v18.asm.lib.ASMHelper.java

public static byte[] writeMethods(String name, byte[] bytes, Multimap<String, MethodWriter> writers) {
    if (writers.containsKey(name)) {
        ClassNode cnode = createClassNode(bytes);

        for (MethodWriter mw : writers.get(name)) {
            MethodNode mv = findMethod(mw.method, cnode);
            if (mv == null) {
                mv = (MethodNode) cnode.visitMethod(mw.access, mw.method.s_name, mw.method.s_desc, null,
                        mw.exceptions);//from   w  w w.  j a  va 2  s  . co m
            }

            mv.access = mw.access;
            mv.instructions.clear();
            mw.write(mv);
        }

        bytes = createBytes(cnode, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
    }
    return bytes;
}