List of usage examples for java.util TreeMap lastKey
public K lastKey()
From source file:Main.java
public static void main(String[] a) { TreeMap map = new TreeMap(); map.put("key1", "value1"); map.put("key2", "value2"); map.put("key3", "value3"); if (!map.isEmpty()) { Object last = map.lastKey(); boolean first = true; do {// w w w . j a v a 2s .com if (!first) { System.out.print(", "); } System.out.print(last); last = map.headMap(last).lastKey(); first = false; } while (last != map.firstKey()); System.out.println(); } }
From source file:Main.java
public static void main(String[] a) { TreeMap<String, String> map = new TreeMap<String, String>(); map.put("key1", "value1"); map.put("key2", "value2"); map.put("key3", "value3"); if (!map.isEmpty()) { String last = map.lastKey(); boolean first = true; do {//from w w w . j a v a 2s.com if (!first) { System.out.print(", "); } System.out.print(last); last = map.headMap(last, true).lastKey(); first = false; } while (last != map.firstKey()); System.out.println(); } }
From source file:MainClass.java
public static void main(String args[]) { TreeMap map = new TreeMap(); map.put("Virginia", "Richmond"); map.put("Massachusetts", "Boston"); map.put("New York", "Albany"); map.put("Maryland", "Annapolis"); if (!map.isEmpty()) { Object last = map.lastKey(); boolean first = true; do {/* w ww . j ava 2s .co m*/ if (!first) { System.out.print(", "); } System.out.print(last); last = map.headMap(last).lastKey(); first = false; } while (last != map.firstKey()); System.out.println(); } }
From source file:Main.java
public static void main(String[] args) { TreeMap<String, String> treeMap = new TreeMap<String, String>(); treeMap.put("1", "One"); treeMap.put("2", "Two"); treeMap.put("3", "Three"); treeMap.put("4", "Four"); treeMap.put("5", "Five"); System.out.println("Lowest key: " + treeMap.firstKey()); System.out.println("Highest key: " + treeMap.lastKey()); }
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 the last key System.out.println("Checking last key"); System.out.println("Value is: " + treemap.lastKey()); }
From source file:SortedMapDemo.java
public static void main(String[] args) { TreeMap sortedMap = new TreeMap(); sortedMap.put("Adobe", "Mountain View, CA"); sortedMap.put("IBM", "White Plains, NY"); sortedMap.put("Learning Tree", "Los Angeles, CA"); sortedMap.put("Microsoft", "Redmond, WA"); sortedMap.put("Netscape", "Mountain View, CA"); sortedMap.put("O'Reilly", "Sebastopol, CA"); sortedMap.put("Sun", "Mountain View, CA"); System.out.println(sortedMap); Object low = sortedMap.firstKey(), high = sortedMap.lastKey(); System.out.println(low);/* w w w . j a v a 2 s. co m*/ System.out.println(high); Iterator it = sortedMap.keySet().iterator(); for (int i = 0; i <= 6; i++) { if (i == 3) low = it.next(); if (i == 6) high = it.next(); else it.next(); } System.out.println(low); System.out.println(high); System.out.println(sortedMap.subMap(low, high)); System.out.println(sortedMap.headMap(high)); System.out.println(sortedMap.tailMap(low)); }
From source file:me.philnate.textmanager.updates.Updater.java
/** * checks what the actual db version is, if an old version is encountered * appropriate updates are performed to get the db to the latest version *//*from w ww . ja v a2s . c o m*/ public static void checkUpdateNeeded(String packageName) { checkArgument(StringUtils.isNotBlank(packageName), "You must insert a packageName"); TreeMap<Version, Class<? extends Update>> updates = createUpdateList(packageName); Setting v = Setting.find("version"); // check that an version is set, if none was found set it to 1 LOG.info(format("Database version is %s", v.getValue())); if (StringUtils.isBlank(v.getValue())) { Version db = (Version) ComparatorUtils.min(startVersion, updates.lastKey(), null); LOG.debug(String.format("No Version set, assuming []", db.toString())); v = new Setting("version", db); ds.save(v); } LOG.info(format("Found these Database upgrades: '%s'", updates.keySet())); for (Version vers : updates.keySet()) { if (vers.compareTo(new Version(v.getValue())) < Version.AFTER) { // if version is smaller than actual db version we have nothing // todo here LOG.debug(format("Database is already newer than '%s'", vers)); continue; } try { LOG.info(format("Going to update Database to version '%s'", vers)); backUp(); // create new Instance Update up = updates.get(vers).newInstance(); // verify that everything is met for this update up.preCheck(); // do the actual update up.upgrade(); // verify that everything is as expected up.postCheck(); // update the version v.setValue(vers.toString()).save(); } catch (Exception e) { // in case of an exception stop further rollback and stop // further updates LOG.error("Update process caused an exception going to rollback", e); rollback(); return; } finally { // finally drop backup directory to avoid to get conflicting // data versions try { FileUtils.deleteDirectory(backUpPath); } catch (IOException e) { LOG.error("Could not remove file", e); } } } }
From source file:cit360.sandbox.BackEndMenu.java
public static void ticketPrices() { TreeMap ageGroup = new TreeMap(); // Add some ageGroup. ageGroup.put("Adult", 8.75); ageGroup.put("Child", 5.50); ageGroup.put("Senior Citizen", 5.25); ageGroup.put("Military Veteran", 5.00); // Iterate over all ageGroup, using the keySet method. for (Object key : ageGroup.keySet()) System.out.println(key + " - $" + ageGroup.get(key)); System.out.println();//from w ww. ja va 2s . c om System.out.println("Highest key: " + ageGroup.lastKey()); System.out.println("Lowest key: " + ageGroup.firstKey()); System.out.println("\nPrinting all values: "); for (Object val : ageGroup.values()) System.out.println("$" + val); System.out.println(); // Clear all values. ageGroup.clear(); // Equals to zero. System.out.println("After clear operation, size: " + ageGroup.size()); }
From source file:Main.java
public static Window getOwnerForChildWindow() { Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow(); if (w != null) { return w; }/*from w w w . jav a 2 s .c om*/ w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); if (w != null) { return w; } /* * Priority level1 * modal dialog: +200 * non-modal dialog: +100 * frame: +0 * * Priority level2 * no owned windows: +10 */ TreeMap<Integer, Window> prioMap = new TreeMap<Integer, Window>(); for (Window cand : Window.getWindows()) { if (cand == null) { continue; } if (!cand.isVisible()) { continue; } if (!cand.isShowing()) { continue; } int prio = 0; Window[] children = cand.getOwnedWindows(); if (children == null || children.length == 0) { prio += 10; } if (cand instanceof Dialog) { Dialog dlg = (Dialog) cand; if (dlg.isModal()) { prio += 200; } else { prio += 100; } prioMap.put(prio, cand); } else if (cand instanceof Frame) { if (!prioMap.containsKey(prio)) { prioMap.put(prio, cand); } } } if (prioMap.size() > 0) { return prioMap.get(prioMap.lastKey()); } //last line of defense if (prioMap.size() == 0) { for (Window cand : Window.getWindows()) { if (cand == null) { continue; } if (cand.isVisible()) { return cand; } } } return null; }
From source file:br.edimarmanica.trinity.extract.Extract.java
private void train(File fPage) throws IOException { String sPage = UTF8FileUtil.readStrippedHTML(fPage.toURI()); TreeMap<Integer, Token> tokensPages = tokeniser.tokenise(sPage).getTokensMap(); tokensPages.remove(tokensPages.lastKey()); Text textPage = new Text(fPage, tokensPages.values()); root.add(textPage);/*w w w . j av a 2 s.co m*/ }