Example usage for java.util TreeMap navigableKeySet

List of usage examples for java.util TreeMap navigableKeySet

Introduction

In this page you can find the example usage for java.util TreeMap navigableKeySet.

Prototype

KeySet navigableKeySet

To view the source code for java.util TreeMap navigableKeySet.

Click Source Link

Usage

From source file:Main.java

public static void main(String[] args) {

    TreeMap<Integer, String> treemap = new TreeMap<Integer, String>();

    // populating tree map
    treemap.put(2, "two");
    treemap.put(1, "one");
    treemap.put(3, "three");
    treemap.put(6, "six");
    treemap.put(5, "from java2s.com");

    // getting navigable key set 
    System.out.println("Checking key set value");
    System.out.println("Value is: " + treemap.navigableKeySet());
}

From source file:org.apache.hconf2prop.Main.java

public static void convert(String arg) throws IOException {

    File input = new File(arg);
    if (!input.isFile() || !input.canRead()) {
        throw new IllegalArgumentException(arg);
    }/*from ww w . j  a  va2  s  .c  om*/

    Configuration conf = new Configuration();
    conf.addResource(new Path(input.toURI()));

    TreeMap<String, String> map = new TreeMap<String, String>();

    Iterator<Map.Entry<String, String>> entries = conf.iterator();
    while (entries.hasNext()) {
        Map.Entry<String, String> entry = entries.next();
        map.put(entry.getKey(), entry.getValue());
    }

    String base = FilenameUtils.getBaseName(input.getName());
    File output = new File(input.getParentFile(), base + ".prop");
    FileOutputStream stream = new FileOutputStream(output);
    Writer writer = new OutputStreamWriter(stream);
    BufferedWriter buffer = new BufferedWriter(writer);
    Iterator<String> keys = map.navigableKeySet().iterator();
    while (keys.hasNext()) {
        String key = keys.next();
        String value = map.get(key);
        String line = String.format("%s = %s", key, value);
        buffer.write(line);
        buffer.newLine();
    }
    buffer.close();

}

From source file:kmi.taa.core.Crawler.java

public void crawlAll(TreeMap<Integer, String> targetUrls, String service, String proxy, String otfile) {
    SortedSet<Integer> results = Collections.synchronizedSortedSet(new TreeSet<Integer>());
    ExecutorService pool = Executors.newFixedThreadPool(100);

    int howManyUrls = targetUrls.size();
    System.out.println("total " + howManyUrls + " to be processed");

    List<String> output = Collections.synchronizedList(new ArrayList<String>());
    for (Integer targetId : targetUrls.navigableKeySet()) {
        String uri = targetUrls.get(targetId);
        pool.execute(new Explorer(targetId, uri, service, proxy, results, otfile, output));
    }/*  w w  w  . java  2  s.  com*/
    pool.shutdown();

    while (results.size() < howManyUrls) {
        System.out.println("already processed " + results.size() + " subject links");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            log.error("crawlAll error", e);
        }

    }

    resultToFile(output, otfile);
    System.out.println("already processed " + results.size() + " subject links");

}

From source file:com.cloudfoundry.bae.cloudpush.Channel.java

/**
* genSign//from  w ww.  j av a 2s  .  c  om
*
* ?
*
* ?method, url, ? ???
*/
private String genSign(String method, String url, Map<String, String> opt) {
    String gather = method + url;
    TreeMap<String, String> sortOpt = new TreeMap<String, String>(opt);
    NavigableSet<String> keySet = sortOpt.navigableKeySet();
    Iterator<String> it = keySet.iterator();
    while (it.hasNext()) {
        String key = it.next();
        String value = sortOpt.get(key);
        gather += key + "=" + value;
    }

    gather += secretKey;

    logger.info("sign source content: " + gather);

    String encodedGather;
    try {
        //            encodedGather = new URLCodec("utf8").encode(gather);
        encodedGather = URLEncoder.encode(gather, "utf8");
    } catch (UnsupportedEncodingException ex) {
        throw new ChannelException("wrong params are seted: " + gather, CHANNEL_SDK_PARAM);
    }
    String sign = DigestUtils.md5Hex(encodedGather);

    return sign;
}