Example usage for com.google.common.collect TreeMultimap create

List of usage examples for com.google.common.collect TreeMultimap create

Introduction

In this page you can find the example usage for com.google.common.collect TreeMultimap create.

Prototype

public static <K extends Comparable, V extends Comparable> TreeMultimap<K, V> create() 

Source Link

Document

Creates an empty TreeMultimap ordered by the natural ordering of its keys and values.

Usage

From source file:org.jetbrains.android.util.InstantAppUrlFinder.java

/**
 * Returns all instant app URLs found in this manifest
 *//* ww  w. ja  v  a 2 s  .c  om*/
@NotNull
public ImmutableCollection<String> getAllUrls() {
    TreeMultimap<Integer, String> allUrls = TreeMultimap.create();

    for (Element activity : myActivities) {
        Node node = activity.getFirstChild();
        while (node != null) {
            InstantAppIntentFilterWrapper wrapper = InstantAppIntentFilterWrapper.of(node);
            for (UrlData urlData : wrapper.getAllUrlData()) {
                allUrls.put(wrapper.getOrder(), urlData.getUrl());
            }
            node = node.getNextSibling();
        }
    }

    return ImmutableList.copyOf(allUrls.values());
}

From source file:moa2014.MOAH32014.java

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

    int difmatrizatual = diferencaMatriz(matrizatual);

    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();
        Integer key = (Integer) 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 = diferencaMatriz(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   w ww. j  a v a  2s  . 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++;
                int diferencamatriz = diferencaMatriz(matriz);
                int 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++;
                int diferencamatriz = diferencaMatriz(matriz);
                int 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++;
                int diferencamatriz = diferencaMatriz(matriz);
                int 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];

            int custoateaqui = diferencaMatriz(matriz) + altura + 1;
            String stringmatriz4 = transformaMatrizString(matriz);

            if (!(processados.containsKey(stringmatriz4))) {
                arvoresgeradas++;
                int diferencamatriz = diferencaMatriz(matriz);
                int 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:carskit.data.processor.DataTransformer.java

public String TransformationFromLooseToBinary() throws Exception {
    BufferedReader br = FileIO.getReader(dataPath);
    String line = br.readLine(); // 1st line;
    HashMap<String, HashMap<String, String>> newlines = new LinkedHashMap();
    Multimap<String, String> conditions = TreeMultimap.create(); // key=dim, value=cond, keep the order when we adding to it
    while ((line = br.readLine()) != null) {
        String[] strs = line.split(",", -1);
        String key = strs[0].trim().toLowerCase() + "," + strs[1].trim().toLowerCase() + ","
                + strs[2].trim().toLowerCase(); // key = user,item,rating
        String cond = strs[4].trim().toLowerCase();
        if (cond.equals(""))
            cond = "na";
        conditions.put(strs[3].trim().toLowerCase(), cond);
        if (newlines.containsKey(key)) {
            HashMap<String, String> ratingcontext = newlines.get(key);
            ratingcontext.put(strs[3].trim().toLowerCase(), cond);

        } else {// w w w  . j  ava2s.  c  o m
            HashMap<String, String> ratingcontext = new HashMap();
            ratingcontext.put(strs[3].trim().toLowerCase(), cond);
            newlines.put(key, ratingcontext);
        }
    }
    br.close();

    this.PublishNewRatingFiles(outputfolder, conditions, newlines, true);

    if (FileIO.exist(outputfolder + "ratings_binary.txt"))
        return "Data transformaton completed (from Loose to Binary format). See new rating file: "
                + outputfolder + "ratings_binary.txt";
    else
        return "Data transformation failed. See output folder: " + outputfolder;
}

From source file:org.dllearner.utilities.MapUtils.java

/**
 * Creates a Guava sorted multimap using the input map.
 *
 * @param input the input map/*  ww w  . j  a  v  a  2s .  co  m*/
 * @return the multimap
 */
public static <K extends Comparable, V extends Comparable> Multimap<K, V> createSortedMultiMap(
        Map<K, ? extends Iterable<V>> input) {
    Multimap<K, V> multimap = TreeMultimap.create();
    for (Map.Entry<K, ? extends Iterable<V>> entry : input.entrySet()) {
        multimap.putAll(entry.getKey(), entry.getValue());
    }
    return multimap;
}

From source file:com.github.nmorel.gwtjackson.guava.client.deser.TreeMultimapJsonDeserializer.java

@Override
protected TreeMultimap<K, V> newMultimap() {
    return TreeMultimap.create();
}

From source file:moa2014.MOAH22014.java

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

    int difmatrizatual = diferencaMatriz(matrizatual);

    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();

        Integer key = (Integer) 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 = diferencaMatriz(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  a2  s  . co  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++;
                int diferencamatriz = diferencaMatriz(matriz);
                int 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++;
                int diferencamatriz = diferencaMatriz(matriz);
                int 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++;
                int diferencamatriz = diferencaMatriz(matriz);
                int 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];

            int custoateaqui = diferencaMatriz(matriz) + altura + 1;
            String stringmatriz4 = transformaMatrizString(matriz);

            if (!(processados.containsKey(stringmatriz4))) {
                arvoresgeradas++;
                int diferencamatriz = diferencaMatriz(matriz);
                int 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.sosy_lab.cpachecker.cfa.postprocessing.global.CFACloner.java

public MutableCFA execute() {
    assert cfa.getLanguage() == Language.C;

    // copy content of old CFAs
    final SortedMap<String, FunctionEntryNode> functions = new TreeMap<>(cfa.getAllFunctions());
    final SortedSetMultimap<String, CFANode> nodes = TreeMultimap.create();
    for (final String function : cfa.getAllFunctionNames()) {
        if (cfa instanceof MutableCFA) {
            // it is more efficient to directly copy the nodes
            nodes.putAll(function, ((MutableCFA) cfa).getFunctionNodes(function));
        } else {/*from w  ww  . jav a 2 s . c  o  m*/
            nodes.putAll(function, CFATraversal.dfs().collectNodesReachableFrom(cfa.getFunctionHead(function)));
        }
    }

    for (String functionName : cfa.getAllFunctionNames()) {
        if (cfa.getMainFunction().getFunctionName().equals(functionName)) {
            continue; // ignore main function
        }

        final FunctionEntryNode entryNode = cfa.getFunctionHead(functionName);
        for (int i = 1; i <= numberOfCopies; i++) {
            final String newFunctionName = getFunctionName(functionName, i);

            Preconditions.checkArgument(!cfa.getAllFunctionNames().contains(newFunctionName));
            final Pair<FunctionEntryNode, Collection<CFANode>> newFunction = FunctionCloner.cloneCFA(entryNode,
                    newFunctionName);
            functions.put(newFunctionName, newFunction.getFirst());
            nodes.putAll(newFunctionName, newFunction.getSecond());

            // get functioncalls from the CFA
            Preconditions.checkArgument(functions.containsKey(newFunctionName), "function %s not available",
                    newFunctionName);
            final FunctionCallCollector visitor = new FunctionCallCollector();
            CFATraversal.dfs().traverseOnce(functions.get(newFunctionName), visitor);
            final Collection<AStatementEdge> functionCalls = visitor.getFunctionCalls();

            // redirect from caller to new (cloned) called function,
            // but only if the calling and the called function have equal clone-indices
            for (AStatementEdge statementEdge : functionCalls) {
                if (FunctionCallUnwinder.isFunctionCall(statementEdge, functions.keySet())) {
                    final String calledFunctionName = FunctionCallUnwinder.getNameOfFunction(statementEdge);
                    final String newCalledFunctionName = getFunctionName(calledFunctionName, i);
                    FunctionCallUnwinder.replaceFunctionCall(statementEdge, newCalledFunctionName);
                }
            }
        }
    }

    return new MutableCFA(cfa.getMachineModel(), functions, nodes, cfa.getMainFunction(), cfa.getLanguage());
}

From source file:org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.RamDiskReplicaLruTracker.java

RamDiskReplicaLruTracker() {
    replicaMaps = new HashMap<>();
    replicasNotPersisted = new LinkedList<>();
    replicasPersisted = TreeMultimap.create();
}

From source file:com.zimbra.cs.mailbox.util.PagedDelete.java

public Multimap<MailItem.Type, Integer> getTypedItemIds() {
    Iterator<Entry<Integer, MailItem.Type>> iterator = mItemIds2Type.entries().iterator();
    if (mType2ItemIds == null) {
        mType2ItemIds = TreeMultimap.create();
    }// w w  w.  j a  va 2 s .c om
    while (iterator.hasNext()) {
        Entry<Integer, MailItem.Type> e = iterator.next();
        mType2ItemIds.put(e.getValue(), e.getKey());
        iterator.remove();
    }
    return mType2ItemIds;
}

From source file:com.github.nmorel.gwtjackson.guava.client.deser.SortedSetMultimapJsonDeserializer.java

@Override
protected SortedSetMultimap<K, V> newMultimap() {
    return TreeMultimap.create();
}