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:com.enitalk.controllers.bots.TimeZoneTestr.java

public static void main(String[] args) {
    Set<String> ids = DateTimeZone.getAvailableIDs();
    TreeMultimap<Long, String> map = TreeMultimap.create();
    for (String id : ids) {
        DateTimeZone dz = DateTimeZone.forID(id);
        int offset = dz.getOffset(DateTime.now().withZone(DateTimeZone.UTC));

        map.put(TimeUnit.MILLISECONDS.toMinutes(offset), id);
    }/* w ww .  j  a  va2 s . c o m*/

    ObjectMapper j = new ObjectMapper();
    ArrayNode a = j.createArrayNode();
    map.keySet().forEach((Long key) -> {
        a.addObject().set(key.toString(), j.convertValue(map.get(key), ArrayNode.class));
    });

    System.out.println(a);

    //        System.out.println(map);
}

From source file:icqexport.ICQExport.java

public static void main(String[] args) throws IOException {
    System.out.println("ICQExport - exports ICQ database files (prior to version 2003b) to HTML");

    File datFile = null;/*from  w  w w.j a  va  2  s  .  c om*/
    if (args.length > 0) {
        datFile = new File(args[0]);
    } else {
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle("Choose ICQ database file (prior to version 2003b) which should be exported");
        FileNameExtensionFilter filter = new FileNameExtensionFilter("ICQ database files", "dat");
        chooser.setFileFilter(filter);
        int returnVal = chooser.showOpenDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            datFile = chooser.getSelectedFile();
        } else
            System.exit(1);
    }

    System.out.println("Processing dat file");

    LERandomAccessFile datIn = new LERandomAccessFile(datFile, "r");
    byte[] sig = new byte[15];
    Map<String, Map<String, String>> userData = Maps.<String, Map<String, String>>newHashMap();

    TreeMultimap<String, Message> msgs = TreeMultimap.create();

    try {
        while (true) {
            if (datIn.read(sig) != sig.length)
                break;
            if (Arrays.equals(sig, magic) || Arrays.equals(sig, magic2)) {
                long startPos = datIn.getFilePointer() - 0x1c;
                datIn.seek(startPos);
                int size = datIn.readInt();
                if (size < 0x20) {
                    // System.out.println("Warning: suspicious entry size: "
                    // + size + " @ " + startPos);
                    datIn.skipBytes(0x0a);
                    continue;
                }
                datIn.skipBytes(0x8);
                byte entryType = datIn.readByte();
                datIn.skipBytes(15);
                datIn.readShort();
                int flags = datIn.readInt();

                if (entryType == (byte) 0xE0 || entryType == (byte) 0x50) {
                    int subType = datIn.readShort();
                    int uin = datIn.readInt();
                    String msgText = readASCII(datIn);
                    if (msgText.indexOf((char) 0x00) >= 0) {
                        // System.out.println("possible corrupt entry @ "
                        // + startPos + " [msgtext: " + msgText + "]");
                        continue;
                    }
                    int status = datIn.readInt();
                    int sentOrReceived = datIn.readInt();
                    datIn.readShort();
                    long ts = datIn.readInt();
                    Date tsDate = new java.util.Date(ts * 1000L);
                    msgs.put(uin + "", new Message(msgText, tsDate, sentOrReceived == 0));
                } else if (entryType == (byte) 0xa0) {
                    int subType = datIn.readShort();
                    int uin = datIn.readInt();
                    String url = readASCII(datIn);
                    url = url.replaceAll("" + (char) 0xFE, " - ");
                    int status = datIn.readInt();
                    int sentOrReceived = datIn.readInt();
                    datIn.readShort();
                    long ts = datIn.readInt();
                    Date tsDate = new java.util.Date(ts * 1000L);
                    msgs.put(uin + "", new Message(url, tsDate, sentOrReceived == 0));
                } else if (entryType == (byte) 0xE5) {
                    try {

                        Map<String, String> properties = readProperties(datIn, startPos);
                        if (properties.containsKey("UIN")) {
                            userData.put(properties.get("UIN"), properties);
                        } else {
                            System.out.println("No UIN found inside properties!");
                        }
                    } catch (Exception e) {
                        // e.printStackTrace(System.err);
                    }
                }

            } else {
                datIn.seek(datIn.getFilePointer() - 14);
            }

        }
    } catch (EOFException e) {

    }

    System.out.println(msgs.size() + " messages extracted. Writing output files...");
    File indexFile = writeIndexFile(userData, msgs);

    for (String UIN : userData.keySet()) {
        writeMessageFile(UIN, userData, msgs);
    }

    System.out.println("Done!");

    if (Desktop.isDesktopSupported()) {

        Desktop.getDesktop().browse(indexFile.toURI());

    }

}

From source file:org.apache.kylin.common.util.SortUtil.java

public static <T extends Comparable, E extends Comparable> Iterator<T> extractAndSort(Iterator<T> input,
        Function<T, E> extractor) {
    TreeMultimap<E, T> reorgnized = TreeMultimap.create();
    while (input.hasNext()) {
        T t = input.next();//from  www  . j a v  a 2 s . c  o  m
        E e = extractor.apply(t);
        reorgnized.put(e, t);
    }
    return reorgnized.values().iterator();
}

From source file:com.spectralogic.ds3client.commands.interfaces.AbstractRequest.java

private static Multimap<String, String> buildDefaultHeaders() {
    final Multimap<String, String> headers = TreeMultimap.create();
    headers.put("Naming-Convention", "s3");
    return headers;
}

From source file:org.commoncrawl.service.parser.server.ParserSlaveServer.java

public static void main(String[] args) {
    Multimap<String, String> options = TreeMultimap.create();
    for (int i = 0; i < args.length; ++i) {
        String optionName = args[i];
        if (++i != args.length) {
            String optionValue = args[i];
            options.put(optionName, optionValue);
        }//from w  w  w . j av a 2s .c  om
    }
    options.removeAll("--server");
    options.put("--server", ParserSlaveServer.class.getName());

    Collection<Entry<String, String>> entrySet = options.entries();
    String finalArgs[] = new String[entrySet.size() * 2];
    int index = 0;
    for (Entry entry : entrySet) {
        finalArgs[index++] = (String) entry.getKey();
        finalArgs[index++] = (String) entry.getValue();
    }

    try {
        CommonCrawlServer.main(finalArgs);
    } catch (Exception e) {
        LOG.error(CCStringUtils.stringifyException(e));
    }
}

From source file:com.xumpy.grapias.Config.java

@Bean
public SortedSetMultimap<Integer, MenuItem> allMenuItems() {
    SortedSetMultimap<Integer, MenuItem> allMenuItems = TreeMultimap.create();

    return allMenuItems;
}

From source file:org.drools.verifier.report.html.MissingRangesReportVisitor.java

public static Collection<String> visitRestrictionsCollection(String sourceFolder,
        Collection<Restriction> restrictions, Collection<MissingRange> causes) {

    Multimap<String, DataRow> dt = TreeMultimap.create();
    Collection<String> stringRows = new ArrayList<String>();

    for (MissingRange cause : causes) {
        dt.put(cause.getValueAsString(),
                new DataRow(null, null, cause.getOperator(), cause.getValueAsString()));
    }// w  w  w.  jav  a 2 s  . c  om

    for (Restriction r : restrictions) {
        if (r instanceof NumberRestriction) {
            try {
                NumberRestriction restriction = (NumberRestriction) r;

                dt.put(restriction.getValue().toString(), new DataRow(restriction.getRulePath(),
                        restriction.getRuleName(), restriction.getOperator(), restriction.getValueAsString()));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    DataRow previous = null;
    for (Iterator<DataRow> iterator = dt.values().iterator(); iterator.hasNext();) {
        DataRow current = iterator.next();

        if (previous != null) {
            // Check if previous and current are from the same rule.
            if (previous.ruleId == null && current.ruleId == null && !previous.operator.equals(Operator.EQUAL)
                    && !previous.operator.equals(Operator.NOT_EQUAL) && !current.operator.equals(Operator.EQUAL)
                    && !current.operator.equals(Operator.NOT_EQUAL)) {
                // Combine these two.
                stringRows.add("Missing : " + previous + " .. " + current);

                if (iterator.hasNext())
                    current = iterator.next();

            } else if (previous.ruleId != null && previous.ruleId.equals(current.ruleId)) {
                // Combine these two.
                stringRows.add(UrlFactory.getRuleUrl(sourceFolder, current.ruleId, current.ruleName) + " : "
                        + previous.toString() + " " + current.toString());

                if (iterator.hasNext())
                    current = iterator.next();

            } else if (!iterator.hasNext()) { // If this is last row
                // Print previous and current if they were not merged.
                processRangeOutput(previous, stringRows, sourceFolder);
                processRangeOutput(current, stringRows, sourceFolder);

            } else { // If they are not from the same rule
                // Print previous.
                processRangeOutput(previous, stringRows, sourceFolder);
            }
        } else if (!iterator.hasNext()) {
            processRangeOutput(current, stringRows, sourceFolder);
        }

        // Set current as previous.
        previous = current;
    }

    return stringRows;
}

From source file:moa2014.MOAH52014.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 h1x = MOAH12014.diferencaMatriz(matrizatual);
    int h2x = MOAH22014.diferencaMatriz(matrizatual);
    int h3x = MOAH32014.diferencaMatriz(matrizatual);

    int difmatrizatual = maior(h1x, h2x, h3x);

    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 = MOAH32014.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  w w. j  a  v a  2s.c  o m*/
        int[][] matrizatualx = estadomenor.getMatriz();
        arvoresprocessadas++;
        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++;
                h1x = MOAH12014.diferencaMatriz(matriz);
                h2x = MOAH22014.diferencaMatriz(matriz);
                h3x = MOAH32014.diferencaMatriz(matriz);
                int diferencamatriz = maior(h1x, h2x, h3x);
                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++;
                h1x = MOAH12014.diferencaMatriz(matriz);
                h2x = MOAH22014.diferencaMatriz(matriz);
                h3x = MOAH32014.diferencaMatriz(matriz);
                int diferencamatriz = maior(h1x, h2x, h3x);
                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++;
                h1x = MOAH12014.diferencaMatriz(matriz);
                h2x = MOAH22014.diferencaMatriz(matriz);
                h3x = MOAH32014.diferencaMatriz(matriz);
                int diferencamatriz = maior(h1x, h2x, h3x);
                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];

            String stringmatriz4 = transformaMatrizString(matriz);

            if (!(processados.containsKey(stringmatriz4))) {
                arvoresgeradas++;
                h1x = MOAH12014.diferencaMatriz(matriz);
                h2x = MOAH22014.diferencaMatriz(matriz);
                h3x = MOAH32014.diferencaMatriz(matriz);
                int diferencamatriz = maior(h1x, h2x, h3x);
                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:moavns.SolucaoAleatoria.java

public static Solucao eliminarRedundancia(Solucao solucao) {
    Multimap<Float, Integer> colunas = TreeMultimap.create();
    for (Coluna coluna : solucao.getColunas()) {
        Float custo = coluna.getCusto();
        colunas.put((custo * (-1)), coluna.getNome());
    }/*from www.j  a  v  a  2 s. c om*/
    Solucao testarsolucao = new Solucao(solucao);
    for (Float chave : colunas.keySet()) {
        Iterator iterador = colunas.get(chave).iterator();
        while (iterador.hasNext()) {
            Solucao testar = new Solucao(testarsolucao);
            Coluna maiorcoluna = testarsolucao.getLinhasX().get(iterador.next());
            testar.getLinhasCobertas().clear();
            cobrirLinhas(maiorcoluna, testar);
            if (testar.getLinhasCobertas().size() == testar.getQtdeLinhas()) {
                testar.getColunas().remove(maiorcoluna);
                testar.setCustototal(testar.getCustototal() - maiorcoluna.getCusto());
                testarsolucao = testar;
            }
        }
    }
    return testarsolucao;
}

From source file:com.github.jasonruckman.sidney.ext.guava.MultimapSerializer.java

public static void registerMaps(AbstractSid sid) {
    sid.addSerializer(Multimap.class, MultimapSerializer.class);
    sid.addInstanceFactory(ArrayListMultimap.class, new InstanceFactory<ArrayListMultimap>() {
        @Override/*from   w ww .j  a v  a 2  s.com*/
        public ArrayListMultimap newInstance() {
            return ArrayListMultimap.create();
        }
    });
    sid.addInstanceFactory(LinkedListMultimap.class, new InstanceFactory<LinkedListMultimap>() {
        @Override
        public LinkedListMultimap newInstance() {
            return LinkedListMultimap.create();
        }
    });
    sid.addInstanceFactory(LinkedHashMultimap.class, new InstanceFactory<LinkedHashMultimap>() {
        @Override
        public LinkedHashMultimap newInstance() {
            return LinkedHashMultimap.create();
        }
    });
    sid.addInstanceFactory(TreeMultimap.class, new InstanceFactory<TreeMultimap>() {
        @Override
        public TreeMultimap newInstance() {
            return TreeMultimap.create();
        }
    });
    sid.addInstanceFactory(HashMultimap.class, new InstanceFactory<HashMultimap>() {
        @Override
        public HashMultimap newInstance() {
            return HashMultimap.create();
        }
    });
}