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

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

Introduction

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

Prototype

Multiset<K> keys();

Source Link

Document

Returns a view collection containing the key from each key-value pair in this multimap, without collapsing duplicates.

Usage

From source file:io.helixservice.core.util.VertxTypeConverter.java

/**
 * Guava MultiMap to Vert.x  Multimap./*from  w  ww .j  a  va 2 s . c o  m*/
 * Primarily used for request and response headers.
 *
 * @param multimap Guava multimap
 * @return Multimap converted to Vert.x MultiMap
 */
static MultiMap toVertxMultiMap(Multimap<String, String> multimap) {
    MultiMap result = MultiMap.caseInsensitiveMultiMap();

    for (String key : multimap.keys()) {
        result.set(key, multimap.get(key));
    }

    return result;
}

From source file:org.apache.hadoop.hive.ql.exec.FunctionTask.java

public static void addFunctionResources(FunctionResource[] resources) throws HiveException {
    if (resources != null) {
        Multimap<SessionState.ResourceType, String> mappings = HashMultimap.create();
        for (FunctionResource res : resources) {
            mappings.put(res.getResourceType(), res.getResourceURI());
        }/*from   w w w  . j  a  v  a  2  s.com*/
        for (SessionState.ResourceType type : mappings.keys()) {
            SessionState.get().add_resources(type, mappings.get(type));
        }
    }
}

From source file:com.twitter.common.collections.Multimaps.java

/**
 * Returns the set of keys associated with the largest values in the multimap.
 *
 * @param map The multimap to search./*from ww  w .  j  a  v  a 2  s .  c  o  m*/
 * @param topValues Number of groupings to find the keys for.
 * @return The keys associated with the largest groups, of maximum size {@code topValues}.
 */
public static <K> Set<K> getLargestGroups(Multimap<K, ?> map, int topValues) {
    Ordering<Multiset.Entry<K>> groupOrdering = new Ordering<Multiset.Entry<K>>() {
        @Override
        public int compare(Multiset.Entry<K> entry1, Multiset.Entry<K> entry2) {
            return entry1.getCount() - entry2.getCount();
            // overflow-safe, since sizes are nonnegative
        }
    };
    Set<K> topKeys = Sets.newHashSetWithExpectedSize(topValues);
    for (Multiset.Entry<K> entry : groupOrdering.greatestOf(map.keys().entrySet(), topValues)) {
        topKeys.add(entry.getElement());
    }
    return topKeys;
}

From source file:de.cau.cs.kieler.klay.layered.intermediate.SplineSelfLoopPreProcessor.java

/**
 * Finds a set of connected edges. Two edges are connected if they share a port, or if there
 * is a path between them, only containing self-loops.
 * /*from  ww w .  j  a va  2s.co  m*/
 * @param portsToEdges A Multimap holding all connections between the ports. 
 *          ATTENTION: THIS PARAMETER GETS ALTERED: 
 *          All edges included in the return value are removed from the Multimap.
 * @param node The node we are currently working on. 
 * @param isFixedOrder True, if the port-order of the node is at least {@code fixedOrder}. 
 * @return A set of connected edges. 
 */
private static ConnectedSelfLoopComponent findAConnectedComponent(final Multimap<LPort, LEdge> portsToEdges,
        final LNode node, final boolean isFixedOrder) {

    final Multimap<LEdge, LPort> edgeToPort = ArrayListMultimap.create();
    Multimaps.invertFrom(portsToEdges, edgeToPort);

    // The connected components element we are constructing.
    final ConnectedSelfLoopComponent connectedComponent = new ConnectedSelfLoopComponent(node);

    // Create a list of ports we have to check for connected ports. Initially add an arbitrary port.
    final List<LPort> portsToProcess = Lists.newArrayList();
    portsToProcess.add(portsToEdges.keys().iterator().next());

    final List<LPort> portsProcessed = Lists.newArrayList();
    // Check ports for connection to current connected component till no port to check is left.
    while (!portsToProcess.isEmpty()) {
        final LPort currentPort = portsToProcess.iterator().next();
        portsProcessed.add(currentPort);
        final Collection<LEdge> allEdgesOnCurrentPort = portsToEdges.removeAll(currentPort);

        for (final LEdge currentEdge : allEdgesOnCurrentPort) {
            if (connectedComponent.tryAddEdge(currentEdge, isFixedOrder)) {
                final Collection<LPort> portsOfCurrentEdge = edgeToPort.removeAll(currentEdge);
                for (final LPort port : portsOfCurrentEdge) {
                    if (!portsProcessed.contains(port)) {
                        portsToProcess.add(port);
                    }
                }
            }
        }
        portsToProcess.remove(currentPort);
    }
    return connectedComponent;
}

From source file:org.pau.assetmanager.viewmodel.chart.ChartDataModel.java

private static Double getAllPreviousMovementCumulative(Multimap<Integer, Annotation> yearToAnnotationMultimap,
        Integer year) {//w  w  w  . j  a  va  2  s.com
    List<Integer> listOfYears = Lists.newLinkedList(yearToAnnotationMultimap.keys());
    if (listOfYears.size() == 0) {
        return 0.0;
    }
    Collections.sort(listOfYears);
    double allPreviousMovementCumulative = 0.0;
    for (int currentYearIndex = 0; currentYearIndex < listOfYears.size()
            && listOfYears.get(currentYearIndex) < year; currentYearIndex++) {
        for (Annotation annotation : yearToAnnotationMultimap.get(listOfYears.get(currentYearIndex))) {
            allPreviousMovementCumulative += annotation.getSignedAmount();
        }

    }
    return allPreviousMovementCumulative;
}

From source file:org.splevo.ui.handler.vpm.MergeVariationPointsHandler.java

private void buildVariantsInSurvivingVP(VariationPoint survivingVP,
        Multimap<String, SoftwareElement> variantSoftwareElements) {
    for (String variantID : variantSoftwareElements.keys()) {
        Variant variantForId = VPMUtil.getVariantFromVP(survivingVP, variantID);
        if (variantForId == null) {
            variantForId = variabilityFactory.eINSTANCE.createVariant();
        }//from   w w  w.ja  v a 2 s  .c om

        variantForId.getImplementingElements().addAll(variantSoftwareElements.get(variantID));
    }
}

From source file:org.terasology.utilities.gson.MultimapHandler.java

@Override
public JsonElement serialize(Multimap<String, V> src, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject result = new JsonObject();
    List<String> keys = Lists.newArrayList(src.keys());
    Collections.sort(keys);/*from   www .ja  v a  2s .  com*/
    for (String key : keys) {
        Collection<V> values = src.get(key);
        if (values.size() > 1) {
            JsonArray array = new JsonArray();
            for (V value : values) {
                array.add(context.serialize(value));
            }
            result.add(key, array);
        } else if (values.size() == 1) {
            result.add(key, context.serialize(values.iterator().next()));
        } else {
            result.add(key, context.serialize(""));
        }
    }
    return result;
}

From source file:org.javersion.store.jdbc.DocumentVersionStoreJdbc.java

protected void doAppend(Multimap<Id, VersionNode<PropertyPath, Object, M>> versionsByDocId) {
    DocumentUpdateBatch<Id, M, V> batch = updateBatch(versionsByDocId.keys());

    for (Id docId : versionsByDocId.keySet()) {
        for (VersionNode<PropertyPath, Object, M> version : versionsByDocId.get(docId)) {
            batch.addVersion(docId, version);
        }/*  w ww . j  ava  2  s.  c o m*/
    }

    batch.execute();
}

From source file:com.tikal.hudson.plugins.notification.Phase.java

private JobState buildJobState(Job job, Run run, TaskListener listener, Endpoint target)
        throws IOException, InterruptedException {

    Jenkins jenkins = Jenkins.getInstance();
    String rootUrl = jenkins.getRootUrl();
    JobState jobState = new JobState();
    BuildState buildState = new BuildState();
    ScmState scmState = new ScmState();
    Result result = run.getResult();
    ParametersAction paramsAction = run.getAction(ParametersAction.class);
    EnvVars environment = run.getEnvironment(listener);
    StringBuilder log = this.getLog(run, target);

    jobState.setName(job.getName());/*from   ww w.j  a va2s . com*/
    jobState.setUrl(job.getUrl());
    jobState.setBuild(buildState);

    buildState.setNumber(run.number);
    buildState.setUrl(run.getUrl());
    buildState.setPhase(this);
    buildState.setScm(scmState);
    buildState.setLog(log);

    if (result != null) {
        buildState.setStatus(result.toString());
    }

    if (rootUrl != null) {
        buildState.setFullUrl(rootUrl + run.getUrl());
    }

    buildState.updateArtifacts(job, run);

    if (paramsAction != null) {
        EnvVars env = new EnvVars();
        for (ParameterValue value : paramsAction.getParameters()) {
            if (!value.isSensitive()) {
                value.buildEnvironment(run, env);
            }
        }
        buildState.setParameters(env);
    }

    if (environment.get("GIT_URL") != null) {
        scmState.setUrl(environment.get("GIT_URL"));
    }

    if (environment.get("GIT_BRANCH") != null) {
        scmState.setBranch(environment.get("GIT_BRANCH"));
    }

    if (environment.get("GIT_COMMIT") != null) {
        scmState.setCommit(environment.get("GIT_COMMIT"));
    }

    if (run instanceof AbstractBuild) {
        Multimap<Entry, AbstractBuild> allChanges = getAllChanges((AbstractBuild) run);
        Iterator<Entry> iterator = allChanges.keys().iterator();
        String msg = "", paths = "";
        while (iterator.hasNext()) {
            Entry entry = iterator.next();
            msg += entry.getMsg() + "\n";
            paths += entry.getAffectedPaths().toString() + "\n";
        }
        scmState.setChanges(msg);
        scmState.setAffectedPaths(paths);
    }

    return jobState;
}

From source file:com.dmdirc.ui.input.TabCompleter.java

/**
 * Attempts to complete the partial string.
 *
 * @param partial     The string to tab complete
 * @param additionals A list of additional strings to use
 *
 * @return A TabCompleterResult containing any matches found
 *//*from  w w w  .ja v a 2  s  .  c  om*/
public TabCompletionMatches complete(final String partial, @Nullable final AdditionalTabTargets additionals) {
    final TabCompletionMatches result = new TabCompletionMatches();

    final boolean caseSensitive = configManager.getOptionBool("tabcompletion", "casesensitive");
    final boolean allowEmpty = configManager.getOptionBool("tabcompletion", "allowempty");

    if (partial.isEmpty() && !allowEmpty) {
        return result;
    }

    final Multimap<TabCompletionType, String> targets = ArrayListMultimap.create(entries);
    if (additionals != null) {
        targets.putAll(TabCompletionType.ADDITIONAL, additionals);
    }

    targets.keys().stream()
            // Filter out keys that aren't allowed by the additional argument (if present)
            .filter(k -> additionals == null || additionals.shouldInclude(k))
            // Select all values for the valid keys
            .flatMap(k -> targets.get(k).stream())
            // Filter out values that don't case sensitively match, if case sensitivity is on
            .filter(v -> !caseSensitive || v.startsWith(partial))
            // Filter out values that don't case INsensitively match, if case sensitivity is off
            .filter(v -> caseSensitive || v.toLowerCase().startsWith(partial.toLowerCase()))
            // Filter out duplicates
            .distinct()
            // Add them all to the result
            .forEach(result::addResult);

    if (parent != null) {
        if (additionals != null) {
            additionals.clear();
        }

        result.merge(parent.complete(partial, additionals));
    }

    return result;
}