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

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

Introduction

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

Prototype

Map<K, Collection<V>> asMap();

Source Link

Document

Returns a view of this multimap as a Map from each distinct key to the nonempty collection of that key's associated values.

Usage

From source file:cuchaz.enigma.translation.Translator.java

default <K extends Translatable, V extends Translatable> Multimap<K, V> translate(Multimap<K, V> translatable) {
    Multimap<K, V> result = HashMultimap.create(translatable.size(), 1);
    for (Map.Entry<K, Collection<V>> entry : translatable.asMap().entrySet()) {
        result.putAll(translate(entry.getKey()), translate(entry.getValue()));
    }// w w w . j  a  va2s  .  c o m
    return result;
}

From source file:com.gwtplatform.dispatch.rest.client.serialization.MultimapJsonSerializer.java

public String serialize(Multimap<?, ?> parameters) {
    if (parameters.isEmpty()) {
        return "{}";
    }/*from ww w.j a  v  a2 s.  co m*/

    return "{\"" + Joiner.on(",\"").withKeyValueSeparator("\":").join(parameters.asMap()) + "}";
}

From source file:org.eclipse.xtext.xbase.typesystem.util.MultimapJoiner.java

/**
 * Appends the string representation of each entry of {@code map}, using the previously configured separator and
 * key-value separator, to {@code builder}. Identical to {@link #appendTo(Appendable, Multimap)}, except that it
 * does not throw {@link IOException}.//from w w  w.  ja v  a2s  .  co  m
 */
public StringBuilder appendTo(StringBuilder builder, Multimap<?, ?> map) {
    return appendTo(builder, map.asMap().entrySet());
}

From source file:de.cosmocode.rendering.MultimapValueRenderer.java

@Override
public void render(@Nullable Multimap<?, ?> value, Renderer r) throws RenderingException {
    if (value == null) {
        r.nullValue();/*from  w w  w.  j  a  va2s . c  om*/
    } else {
        r.value(value.asMap());
    }
}

From source file:com.github.lukaszkusek.xml.comparator.document.XMLDocument.java

private Map<String, Node> createNodeMap(Multimap<String, Node> xpathToNodeMultimap) {
    return Maps.newHashMap(Maps.transformEntries(xpathToNodeMultimap.asMap(),
            (key, nodes) -> nodes.stream().reduce(Node::merge).get()));
}

From source file:de.hzi.helmholtz.Compare.PathwayComparisonUsingModules.java

public static void removemax(Multimap<Integer, Multimap<Double, String>> collections, int key) {
    collections.asMap().remove(key);
}

From source file:com.sun.tools.hat.internal.server.AllRootsQuery.java

@Override
public void run() {
    startHtml("All Members of the Rootset");

    // More interesting values are *higher*
    Multimap<Integer, Root> roots = Multimaps.index(snapshot.getRoots(), Root::getType);
    roots.asMap().entrySet().stream().sorted(Ordering.natural().reverse().onResultOf(entry -> entry.getKey()))
            .forEach(entry -> {/* ww w.ja va  2 s . co  m*/
                out.print("<h2>");
                print(Root.getTypeName(entry.getKey()) + " References");
                out.println("</h2>");
                entry.getValue().stream().sorted(Ordering.natural().onResultOf(Root::getDescription))
                        .forEach(root -> {
                            printRoot(root);
                            if (root.getReferer() != null) {
                                out.print("<small> (from ");
                                printThingAnchorTag(root.getReferer().getId());
                                print(root.getReferer().toString());
                                out.print(")</a></small>");
                            }
                            out.print(" :<br>");

                            JavaThing t = snapshot.findThing(root.getId());
                            if (t != null) { // It should always be
                                print("--> ");
                                printThing(t);
                                out.println("<br>");
                            }
                        });
            });

    out.println("<h2>Other Queries</h2>");
    out.println("<ul>");
    out.println("<li>");
    printAnchorStart();
    out.print("\">");
    print("Show All Classes");
    out.println("</a>");
    out.println("</ul>");

    endHtml();
}

From source file:ch.ethz.bsse.quasirecomb.informationholder.ModelSelectionBootstrapStorage.java

public ModelSelectionBootstrapStorage(Multimap<Integer, Double> map) {
    this.srMap = new HashMap<>();
    for (Map.Entry<Integer, Collection<Double>> e : map.asMap().entrySet()) {
        this.add(e.getValue(), e.getKey());
    }//from w  w  w. jav  a 2  s  .c o m
}

From source file:moa2014.MOAH42014.java

public static int principal(int[][] matrizatual, double c1, double c2, double c3) {
    long startTime = System.currentTimeMillis();
    Multimap<Double, String> open_list = TreeMultimap.create();
    HashMap<String, Estado> processados = new HashMap();

    double h1 = c1 * h1(matrizatual);
    double h2 = c2 * h2(matrizatual);
    double h3 = c3 * h3(matrizatual);
    double difmatrizatual = h1 + h2 + h3;

    String stringmatriz = transformaMatrizString(matrizatual);
    open_list.put(difmatrizatual, stringmatriz);
    Estado estadoatual = new Estado(matrizatual, 0);
    processados.put(stringmatriz, estadoatual);

    int arvoresgeradas = 0;
    int arvoresprocessadas = 0;

    while (!open_list.isEmpty()) {

        Iterator iterator = open_list.keySet().iterator();

        Double key = (Double) iterator.next();
        String matrizatualx1 = open_list.asMap().get(key).iterator().next();
        Estado estadomenor = processados.get(matrizatualx1);
        int altura = estadomenor.getCusto();

        //LOCALIZA O ZERO
        int[] zerot = localizazero(estadomenor.getMatriz());
        int x = zerot[0];
        int y = zerot[1];
        int x0 = x - 1;
        int x1 = x + 1;
        int y0 = y - 1;
        int y1 = y + 1;
        int difmatrizatualx = h1(estadomenor.getMatriz());
        if (difmatrizatualx == 0) {
            long endTime = System.currentTimeMillis();
            System.out.println("---------------------------------------");
            System.out.println("Arvores Geradas: " + arvoresgeradas);
            System.out.println("Arvores Processadas: " + arvoresprocessadas);
            System.out.println("Quantidade de Movimentos: " + estadomenor.getCusto());
            System.out.println("Tempo de processamento " + (endTime - startTime) + " ms");
            System.out.println("---------------------------------------\n\n");
            return 0;
        }/*from  ww w . ja v a2s .c o  m*/
        arvoresprocessadas++;
        int[][] matrizatualx = estadomenor.getMatriz();
        if (x0 >= 0) {

            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x0][y];
            matriz[x0][y] = matrizatualx[x][y];

            String stringmatriz1 = transformaMatrizString(matriz);
            if (!(processados.containsKey(stringmatriz1))) {
                arvoresgeradas++;
                h1 = c1 * h1(matriz);
                h2 = c2 * h2(matriz);
                h3 = c3 * h3(matriz);
                double diferencamatriz = h1 + h2 + h3;
                double custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz1);

                processados.put(stringmatriz1, estadonovo);

            }
        }
        if (x1 <= 3) {
            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x1][y];
            matriz[x1][y] = matrizatualx[x][y];
            String stringmatriz2 = transformaMatrizString(matriz);

            if (!(processados.containsKey(stringmatriz2))) {
                arvoresgeradas++;
                h1 = c1 * h1(matriz);
                h2 = c2 * h2(matriz);
                h3 = c3 * h3(matriz);
                double diferencamatriz = h1 + h2 + h3;
                double custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz2);

                processados.put(stringmatriz2, estadonovo);

            }
        }
        if (y0 >= 0) {
            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x][y0];
            matriz[x][y0] = matrizatualx[x][y];
            String stringmatriz3 = transformaMatrizString(matriz);

            if (!(processados.containsKey(stringmatriz3))) {
                arvoresgeradas++;
                h1 = c1 * h1(matriz);
                h2 = c2 * h2(matriz);
                h3 = c3 * h3(matriz);
                double diferencamatriz = h1 + h2 + h3;
                double custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz3);

                processados.put(stringmatriz3, estadonovo);

            }
        }
        if (y1 <= 3) {
            int[][] matriz;
            matriz = copyarray(matrizatualx);
            matriz[x][y] = matrizatualx[x][y1];
            matriz[x][y1] = matrizatualx[x][y];

            String stringmatriz4 = transformaMatrizString(matriz);

            if (!(processados.containsKey(stringmatriz4))) {
                arvoresgeradas++;
                h1 = c1 * h1(matriz);
                h2 = c2 * h2(matriz);
                h3 = c3 * h3(matriz);
                double diferencamatriz = h1 + h2 + h3;
                double custototal = diferencamatriz + altura + 1;

                Estado estadonovo = new Estado(matriz, altura + 1);
                open_list.put(custototal, stringmatriz4);

                processados.put(stringmatriz4, estadonovo);

            }
        }
        open_list.remove(key, matrizatualx1);
    }
    return 0;

}

From source file:org.sonar.plugins.core.notifications.reviews.NewFalsePositiveReview.java

private void notify(String author, Context context,
        Multimap<String, NotificationChannel> subscribedRecipients) {
    for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients.asMap()
            .entrySet()) {/*from   ww  w .  ja va2 s  . c  o m*/
        String userLogin = channelsByRecipients.getKey();
        if (!StringUtils.equals(author, userLogin)) {
            for (NotificationChannel channel : channelsByRecipients.getValue()) {
                context.addUser(userLogin, channel);
            }
        }
    }
}