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

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

Introduction

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

Prototype

@Override
@GwtIncompatible("NavigableSet")
public NavigableSet<V> get(@Nullable K key) 

Source Link

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);
    }//from  w  ww. j  a v  a 2  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:org.crypto.sse.DynRH_Disk.java

public static void update(ConcurrentMap<String, byte[]> dictionary, TreeMultimap<String, byte[]> tokenUp) {

    for (String label : tokenUp.keySet()) {
        dictionary.put(label, tokenUp.get(label).first());
    }/*from   w w  w.jav  a 2s .  c o m*/
}

From source file:org.clusion.DynRHAndroid.java

public static void update(HashMap<String, byte[]> dictionary, TreeMultimap<String, byte[]> tokenUp) {

    for (String label : tokenUp.keySet()) {
        dictionary.put(label, tokenUp.get(label).first());
    }//from ww  w.j  a  v  a  2  s.c  o m
}

From source file:org.opendaylight.yangtools.yang.model.util.FilteringSchemaContextProxy.java

private static Collection<Module> getImportedModules(final Map<ModuleId, Module> allModules,
        final Set<Module> baseModules, final TreeMultimap<String, Module> nameToModulesAll) {

    List<Module> relatedModules = Lists.newLinkedList();

    for (Module module : baseModules) {
        for (ModuleImport moduleImport : module.getImports()) {

            Date revisionDate = moduleImport.getRevision() == null
                    ? nameToModulesAll.get(moduleImport.getModuleName()).first().getRevision()
                    : moduleImport.getRevision();

            ModuleId key = new ModuleId(moduleImport.getModuleName(), revisionDate);
            Module importedModule = allModules.get(key);

            Preconditions.checkArgument(importedModule != null,
                    "Invalid schema, cannot find imported module: %s from module: %s, %s, modules:%s", key,
                    module.getQNameModule(), module.getName());
            relatedModules.add(importedModule);

            //calling imports recursive
            relatedModules.addAll(//w w  w .ja v  a  2s . c om
                    getImportedModules(allModules, Collections.singleton(importedModule), nameToModulesAll));

        }
    }

    return relatedModules;
}

From source file:org.onos.yangtools.yang.model.util.FilteringSchemaContextProxy.java

private static Collection<Module> getImportedModules(Map<ModuleId, Module> allModules, Set<Module> baseModules,
        TreeMultimap<String, Module> nameToModulesAll) {

    List<Module> relatedModules = Lists.newLinkedList();

    for (Module module : baseModules) {
        for (ModuleImport moduleImport : module.getImports()) {

            Date revisionDate = moduleImport.getRevision() == null
                    ? nameToModulesAll.get(moduleImport.getModuleName()).first().getRevision()
                    : moduleImport.getRevision();

            ModuleId key = new ModuleId(moduleImport.getModuleName(), revisionDate);
            Module importedModule = allModules.get(key);

            Preconditions.checkArgument(importedModule != null,
                    "Invalid schema, cannot find imported module: %s from module: %s, %s, modules:%s", key,
                    module.getQNameModule(), module.getName());
            relatedModules.add(importedModule);

            //calling imports recursive
            relatedModules.addAll(/*from w w  w . ja v  a  2 s.  com*/
                    getImportedModules(allModules, Collections.singleton(importedModule), nameToModulesAll));

        }
    }

    return relatedModules;
}

From source file:icqexport.ICQExport.java

private static void writeMessageFile(String UIN, Map<String, Map<String, String>> userData,
        TreeMultimap<String, Message> msgs) throws IOException {
    File outDir = new File("html");
    outDir.mkdirs();/*from ww  w. ja  va  2s .c  o m*/
    File indexFile = new File(outDir, UIN + ".html");
    String nick = userData.get(UIN).get("NickName");
    BufferedWriter bw = new BufferedWriter(new FileWriter(indexFile));

    bw.write("<html><body style='font-family: monospace'><h1>Message log with " + nick + " (UIN " + UIN
            + ")</h1>");

    bw.write("<br>");
    for (Message msg : msgs.get(UIN).descendingSet()) {
        String text = HtmlEscapers.htmlEscaper().escape(msg.text);
        text = text.replaceAll("\r\n", "<br>");
        if (msg.received) {
            bw.write("<div style='color:#000080'>[" + msg.timestamp + "]   " + nick + ": " + text + "</div>");
        } else {
            bw.write("<div style='color:#008000'>[" + msg.timestamp + "]   me: " + text + "</div>");
        }
        bw.newLine();
    }

    bw.write("<h2>Properties:</h2><br>");
    for (Entry<String, String> entry : userData.get(UIN).entrySet()) {
        if (!"".equals(entry.getValue())) {
            bw.write(entry.getKey() + ":" + entry.getValue() + "<br>");
        }
    }

    bw.write("<hr><i>exported by ICQExport</i></body></html>");
    bw.close();
}

From source file:com.publictransitanalytics.scoregenerator.output.ComparativeSectorReachInformation.java

private static Map<SimplePath, Integer> getPathCounts(final Set<MovementPath> bestPaths)
        throws InterruptedException {
    final Map<SimplePath, Integer> pathCounts;
    final TreeMultimap<Integer, SimplePath> frequencyMap = TreeMultimap.create(Integer::compareTo,
            (p1, p2) -> p1.toString().compareTo(p2.toString()));

    if (bestPaths != null) {
        final ImmutableMultiset.Builder<SimplePath> bestSimplePathsBuilder = ImmutableMultiset.builder();
        for (final MovementPath bestPath : bestPaths) {
            bestSimplePathsBuilder.add(new SimplePath(bestPath));
        }/*ww w.ja va 2  s. com*/
        final ImmutableMultiset<SimplePath> bestSimplePaths = bestSimplePathsBuilder.build();

        for (final SimplePath path : bestSimplePaths.elementSet()) {
            frequencyMap.put(bestSimplePaths.count(path), path);
        }

        pathCounts = new LinkedHashMap<>();
        for (final Integer frequency : frequencyMap.keySet().descendingSet()) {
            final NavigableSet<SimplePath> pathsForFrequency = frequencyMap.get(frequency);
            for (final SimplePath pathForFrequency : pathsForFrequency) {
                pathCounts.put(pathForFrequency, frequency);
            }
        }
    } else {
        pathCounts = null;
    }
    return pathCounts;
}

From source file:org.icgc.dcc.portal.util.MutationUtils.java

/**
 * Determines the unique affected donor counts by project from the supplied ssm occurrences.
 * //from   ww  w.j  a va  2s.c  om
 * @param ssmOccurrences - the list of ssm occurrences of the related mutation
 * @return the affected donor counts by project
 */
public static List<Map<String, Object>> affectedProjectDonorCounts(List<Map<String, Object>> ssmOccurrences) {
    // Sorted for stability
    TreeMultimap<String, String> projectDonorIds = TreeMultimap.create();
    Map<String, String> projectNames = newHashMap();

    for (val ssmOccurrence : ssmOccurrences) {
        String projectId = projectId(ssmOccurrence);
        projectNames.put(projectId, projectName(ssmOccurrence));
        projectDonorIds.put(projectId, donorId(ssmOccurrence));
    }

    List<Map<String, Object>> records = newArrayList();
    for (String projectId : projectDonorIds.keySet()) {
        // Attributes
        String projectName = projectNames.get(projectId);
        Integer projectDonorCount = projectDonorIds.get(projectId).size();

        // Assemble
        Map<String, Object> record = newLinkedHashMap();
        record.put("_project_id", projectId);
        record.put("project_name", projectName);
        record.put("count", projectDonorCount);

        records.add(record);
    }

    return records;
}

From source file:icqexport.ICQExport.java

private static File writeIndexFile(Map<String, Map<String, String>> userData,
        TreeMultimap<String, Message> msgs) throws IOException {
    File outDir = new File("html");
    outDir.mkdirs();// w  w  w . j  a v a  2s. c om
    File indexFile = new File(outDir, "index.html");
    BufferedWriter bw = new BufferedWriter(new FileWriter(indexFile));

    bw.write(
            "<html><body><table><tr><th>UIN</th><th>Nickname</th><th>Last seen online</th><th># Messages</tr>");
    for (String UIN : userData.keySet()) {
        Map<String, String> props = userData.get(UIN);
        String lastOnlineStr = "Unknown";
        if (props.containsKey("LastOnlineTime")) {
            Date lastOnline = new Date(new Long(props.get("LastOnlineTime")).longValue() * 1000L);
            lastOnlineStr = lastOnline.toString();
        }
        bw.write("<tr><td><a href=\"" + UIN + ".html\">" + UIN + "</TD>+<TD>" + props.get("NickName")
                + "</TD><TD>" + lastOnlineStr + "</TD><TD>" + msgs.get(UIN).size() + "</TD></TR>");
    }
    bw.write("</table><hr><i>exported by ICQExport</i></body></html>");
    bw.close();
    return indexFile;
}

From source file:eus.ixa.ixa.pipe.ml.resources.POSDictionary.java

public String getMostFrequentTag(String word) {
    TreeMultimap<Integer, String> mfTagMap = getOrderedMap(word);
    String mfTag = null;/*from  ww  w  . j  a  v a 2  s . c o m*/
    if (!mfTagMap.isEmpty()) {
        SortedSet<String> mfTagSet = mfTagMap.get(mfTagMap.keySet().first());
        mfTag = mfTagSet.first();
    } else {
        mfTag = "O";
    }
    return mfTag;
}