List of usage examples for java.util TreeMap lowerKey
public K lowerKey(K key)
From source file:Main.java
public static void main(String[] args) { TreeMap<Integer, String> db = new TreeMap<Integer, String>(); db.put(1000, "1000"); db.put(1011, "1011"); db.put(1102, "1102"); db.put(2023, "2023"); db.put(2034, "2034"); System.out.println("First key lower than 2034: " + db.lowerKey(2034)); }
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 lower key System.out.println("Checking lower key"); System.out.println("Value is: " + treemap.lowerKey(5)); }
From source file:Main.java
public static void main(String[] args) { TreeMap<Integer, Product> db = new TreeMap<Integer, Product>(); db.put(1000, new Product("D", 350)); db.put(1011, new Product("p", 15.75)); db.put(1102, new Product("M", 8.50)); db.put(2023, new Product("A", 150)); db.put(2034, new Product("T", 9.99)); System.out.println(db.subMap(1000, 1999) + "\n"); System.out.println(db.tailMap(1011) + "\n"); System.out.println(db.headMap(2023)); System.out.println("First key higher than 2034: " + db.higherKey(2034)); System.out.println("First key lower than 2034: " + db.lowerKey(2034)); }
From source file:org.eclipse.dataset.Stats.java
public static double[] outlierValuesMap(final Dataset a, int nl, int nh) { final TreeMap<Double, Integer> lMap = new TreeMap<Double, Integer>(); final TreeMap<Double, Integer> hMap = new TreeMap<Double, Integer>(); int ml = 0;//from w w w. j a va 2s .com int mh = 0; IndexIterator it = a.getIterator(); while (it.hasNext()) { Double x = a.getElementDoubleAbs(it.index); Integer i; if (ml == nl) { Double k = lMap.lastKey(); if (x < k) { i = lMap.get(k) - 1; if (i == 0) { lMap.remove(k); } else { lMap.put(k, i); } i = lMap.get(x); if (i == null) { lMap.put(x, 1); } else { lMap.put(x, i + 1); } } } else { i = lMap.get(x); if (i == null) { lMap.put(x, 1); } else { lMap.put(x, i + 1); } ml++; } if (mh == nh) { Double k = hMap.firstKey(); if (x > k) { i = hMap.get(k) - 1; if (i == 0) { hMap.remove(k); } else { hMap.put(k, i); } i = hMap.get(x); if (i == null) { hMap.put(x, 1); } else { hMap.put(x, i + 1); } } } else { i = hMap.get(x); if (i == null) { hMap.put(x, 1); } else { hMap.put(x, i + 1); } mh++; } } // Attempt to make values distinct double lx = lMap.lastKey(); double hx = hMap.firstKey(); if (lx >= hx) { Double h = hMap.higherKey(lx); if (h != null) { hx = h; mh--; } else { Double l = lMap.lowerKey(hx); if (l != null) { lx = l; ml--; } } } return new double[] { lMap.lastKey(), hMap.firstKey(), ml, mh }; }
From source file:org.eclipse.january.dataset.Stats.java
static double[] outlierValuesMap(final Dataset a, int nl, int nh) { final TreeMap<Double, Integer> lMap = new TreeMap<Double, Integer>(); final TreeMap<Double, Integer> hMap = new TreeMap<Double, Integer>(); int ml = 0;/*from w ww . j ava2 s. c o m*/ int mh = 0; IndexIterator it = a.getIterator(); while (it.hasNext()) { Double x = a.getElementDoubleAbs(it.index); Integer i; if (ml == nl) { Double k = lMap.lastKey(); if (x < k) { i = lMap.get(k) - 1; if (i == 0) { lMap.remove(k); } else { lMap.put(k, i); } i = lMap.get(x); if (i == null) { lMap.put(x, 1); } else { lMap.put(x, i + 1); } } } else { i = lMap.get(x); if (i == null) { lMap.put(x, 1); } else { lMap.put(x, i + 1); } ml++; } if (mh == nh) { Double k = hMap.firstKey(); if (x > k) { i = hMap.get(k) - 1; if (i == 0) { hMap.remove(k); } else { hMap.put(k, i); } i = hMap.get(x); if (i == null) { hMap.put(x, 1); } else { hMap.put(x, i + 1); } } } else { i = hMap.get(x); if (i == null) { hMap.put(x, 1); } else { hMap.put(x, i + 1); } mh++; } } // Attempt to make values distinct double lx = lMap.lastKey(); double hx = hMap.firstKey(); if (lx >= hx) { Double h = hMap.higherKey(lx); if (h != null) { hx = h; mh--; } else { Double l = lMap.lowerKey(hx); if (l != null) { lx = l; ml--; } } } return new double[] { lMap.lastKey(), hMap.firstKey(), ml, mh }; }