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

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

Introduction

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

Prototype

Collection<Map.Entry<K, V>> entries();

Source Link

Document

Returns a view collection of all key-value pairs contained in this multimap, as Map.Entry instances.

Usage

From source file:io.redlink.sdk.impl.analysis.model.Entity.java

/**
 * Get a collection of pairs <language,value> for the property passed by parameter
 *
 * @param property Property URI//from   w w  w  .  j  av a  2 s. c o  m
 * @return
 */
public Multimap<String, String> getValuesByLanguage(String property) {
    Multimap<String, String> result = HashMultimap.create();
    if (properties.containsKey(property)) {
        Multimap<Optional<String>, String> values = properties.get(property);
        for (Entry<Optional<String>, String> entry : values.entries())
            if (entry.getKey().isPresent())
                result.put(entry.getKey().get(), entry.getValue());
    }
    return result;
}

From source file:de.metas.ui.web.window.descriptor.DocumentFieldDependencyMap.java

public String toStringX() {
    final StringBuilder sb = new StringBuilder();

    for (final Map.Entry<DependencyType, Multimap<String, String>> l1 : type2name2dependencies.entrySet()) {
        final DependencyType dependencyType = l1.getKey();
        final Multimap<String, String> name2dependencies = l1.getValue();
        for (final Map.Entry<String, String> l2 : name2dependencies.entries()) {
            final String dependsOnFieldName = l2.getKey();
            final String fieldName = l2.getValue();

            if (sb.length() > 0) {
                sb.append("\n");
            }//from   w w  w  .  j  a v a 2 s  .com
            sb.append(dependencyType).append(": ").append(dependsOnFieldName).append(" -> ").append(fieldName);
        }
    }

    return sb.toString();
}

From source file:com.textocat.textokit.morph.commons.AgreementPredicate.java

private AgreementPredicate(GramModel gm, Multimap<BitSet, BitSet> agreementMap) {
    this.gramModel = gm;
    this.agreementMap = ImmutableMultimap.copyOf(agreementMap);
    categoryMask = new BitSet();
    for (Map.Entry<BitSet, BitSet> e : agreementMap.entries()) {
        categoryMask.or(e.getKey());//  www  . j  ava2 s.  com
        categoryMask.or(e.getValue());
    }
    // done
}

From source file:eu.tomylobo.routes.infrastructure.TransportSystem.java

public void load() {
    routes.clear();// w  w w.j ava2s  .  c  o  m

    final Multimap<String, Multimap<String, String>> sections = Ini
            .load(plugin.getConfigFileName("routes.txt"));
    if (sections == null)
        return;

    for (Entry<String, Multimap<String, String>> entry : sections.entries()) {
        final String sectionName = entry.getKey();
        if (!sectionName.startsWith("route "))
            continue;

        final String routeName = sectionName.substring(6);
        final Route route = new Route(routeName);

        route.load(sections);

        addRoute(route);
    }
}

From source file:com.isotrol.impe3.freemarker.FreeMarker.java

private static String returnUri(URI uri, List<String> args, int index) {
    if (uri == null) {
        return EMPTY;
    }//  w ww.j a va 2s  . c o m
    final Multimap<String, String> map = getParameters(args, index);
    if (map.isEmpty()) {
        return uri.toASCIIString();
    }
    final UriBuilder b = UriBuilder.fromUri(uri);
    for (Entry<String, ?> entry : map.entries()) {
        b.queryParam(entry.getKey(), entry.getValue());
    }
    return b.build().toASCIIString();
}

From source file:io.crate.planner.ReaderAllocations.java

ReaderAllocations(TreeMap<String, Integer> bases, Map<String, Map<Integer, String>> shardNodes,
        Multimap<TableIdent, String> tableIndices) {
    this.bases = bases;
    this.tableIndices = tableIndices;
    this.indicesToIdents = new HashMap<>(tableIndices.values().size());
    for (Map.Entry<TableIdent, String> entry : tableIndices.entries()) {
        indicesToIdents.put(entry.getValue(), entry.getKey());
    }/*  w  ww  .  j a v a2  s . c  o  m*/
    for (Map.Entry<String, Integer> entry : bases.entrySet()) {
        readerIndices.put(entry.getValue(), entry.getKey());
    }
    for (Map.Entry<String, Map<Integer, String>> entry : shardNodes.entrySet()) {
        Integer base = bases.get(entry.getKey());
        if (base == null) {
            continue;
        }
        for (Map.Entry<Integer, String> nodeEntries : entry.getValue().entrySet()) {
            int readerId = base + nodeEntries.getKey();
            IntSet readerIds = nodeReaders.get(nodeEntries.getValue());
            if (readerIds == null) {
                readerIds = new IntHashSet();
                nodeReaders.put(nodeEntries.getValue(), readerIds);
            }
            readerIds.add(readerId);
        }
    }
}

From source file:com.cloudera.flume.master.MasterAdminServer.java

/**
 * Fetch the list of logical to physical mappings and return it as {@link Map}
 * &lt;{@link String}, {@link List}&lt;String&gt;&gt; where the key is the
 * physical node name and the value is a list of logical nodes mapped to it.
 * /* ww  w. j av a  2  s  .c o  m*/
 * @param physicalNode
 *          The physical node for which to fetch mappings or null to fetch
 *          all.
 * @return the node map
 */
public Map<String, List<String>> getMappings(String physicalNode) {
    Map<String, List<String>> resultMap = new HashMap<String, List<String>>();

    if (physicalNode != null) {
        List<String> logicalNodes = master.getSpecMan().getLogicalNode(physicalNode);

        if (logicalNodes != null && logicalNodes.size() > 0) {
            resultMap.put(physicalNode, master.getSpecMan().getLogicalNode(physicalNode));
        }
    } else {
        Multimap<String, String> m = master.getSpecMan().getLogicalNodeMap();

        // Transform the multimap into a map of string => list<string>.
        for (Entry<String, String> entry : m.entries()) {
            if (!resultMap.containsKey(entry.getKey())) {
                resultMap.put(entry.getKey(), new LinkedList<String>());
            }

            resultMap.get(entry.getKey()).add(entry.getValue());
        }
    }

    return resultMap;
}

From source file:org.jclouds.aliyun.ecs.filters.FormSign.java

/**
 * Examines the specified query string parameters and returns a
 * canonicalized form./*from  w  w w.j  ava2  s . co  m*/
 * <p/>
 * The canonicalized query string is formed by first sorting all the query
 * string parameters, then URI encoding both the key and value and then
 * joining them, in order, separating key value pairs with an '&'.
 *
 * @return A canonicalized form for the specified query string parameters.
 */
protected String getCanonicalizedQueryString(Multimap<String, String> params) {
    SortedMap<String, String> sorted = Maps.newTreeMap();
    if (params == null) {
        return "";
    }
    Iterator<Map.Entry<String, String>> pairs = params.entries().iterator();
    while (pairs.hasNext()) {
        Map.Entry<String, String> pair = pairs.next();
        String key = pair.getKey();
        String value = pair.getValue();
        sorted.put(Strings2.urlEncode(key), Strings2.urlEncode(value));
    }

    return Strings2.urlEncode(Joiner.on("&").withKeyValueSeparator("=").join(sorted));
}

From source file:org.apache.cassandra.service.BatchlogEndpointSelector.java

/**
 * @param endpoints nodes in the local datacenter, grouped by rack name
 * @return list of candidates for batchlog hosting.  if possible these will be two nodes from different racks.
 *///from  ww  w . j  a  v  a 2  s . co m
public Collection<InetAddress> chooseEndpoints(Multimap<String, InetAddress> endpoints) {
    // strip out dead endpoints and localhost
    ListMultimap<String, InetAddress> validated = ArrayListMultimap.create();
    for (Map.Entry<String, InetAddress> entry : endpoints.entries()) {
        if (isValid(entry.getValue()))
            validated.put(entry.getKey(), entry.getValue());
    }
    if (validated.size() <= 2)
        return validated.values();

    if ((validated.size() - validated.get(localRack).size()) >= 2) {
        // we have enough endpoints in other racks
        validated.removeAll(localRack);
    }

    if (validated.keySet().size() == 1) {
        // we have only 1 `other` rack
        Collection<InetAddress> otherRack = Iterables.getOnlyElement(validated.asMap().values());
        return Lists.newArrayList(Iterables.limit(otherRack, 2));
    }

    // randomize which racks we pick from if more than 2 remaining
    Collection<String> racks;
    if (validated.keySet().size() == 2) {
        racks = validated.keySet();
    } else {
        racks = Lists.newArrayList(validated.keySet());
        Collections.shuffle((List) racks);
    }

    // grab a random member of up to two racks
    List<InetAddress> result = new ArrayList<>(2);
    for (String rack : Iterables.limit(racks, 2)) {
        List<InetAddress> rackMembers = validated.get(rack);
        result.add(rackMembers.get(getRandomInt(rackMembers.size())));
    }

    return result;
}

From source file:com.isotrol.impe3.freemarker.FreeMarker.java

private static String returnUri(String uri, List<String> args, int index) {
    if (uri == null) {
        return EMPTY;
    }//from  ww  w  .j av a2s  . c om
    final Multimap<String, String> map = getParameters(args, index);
    if (map.isEmpty()) {
        return uri;
    }
    try {
        final UriBuilder b = UriBuilder.fromUri(uri);
        for (Entry<String, ?> entry : map.entries()) {
            b.queryParam(entry.getKey(), entry.getValue());
        }
        return b.build().toASCIIString();
    } catch (IllegalArgumentException e) {
        return uri;
    }
}