List of usage examples for java.util TreeMap headMap
public SortedMap<K, V> headMap(K toKey)
From source file:MainClass.java
public static void main(String[] a) { TreeMap map = new TreeMap(); map.put("key1", "value1"); map.put("key2", "value2"); map.put("key3", "value3"); Map map2 = map.headMap("key2"); System.out.println(map2);//from w w w . j ava2 s . co m }
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("3", "Three"); treeMap.put("2", "Two"); treeMap.put("5", "Five"); treeMap.put("4", "Four"); SortedMap sortedMap = treeMap.headMap("3"); System.out.println("Head Map Contains : " + sortedMap); }
From source file:Main.java
public static void main(String[] args) { TreeMap<Integer, String> treemap = new TreeMap<Integer, String>(); TreeMap<Integer, String> treemaphead = 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 head map treemaphead = treemap.headMap(3); System.out.println("Checking values of the sorted map"); System.out.println("Value is: " + treemaphead); }
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 a2 s . c om*/ 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<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: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 {//from w ww . j a v a2s .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: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);/*from www .ja 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:org.kalypso.model.hydrology.operation.evaporation.AbstractEvaporationCalculator.java
private TupleModelDataSet getDataSet(final ITimeseriesCache humidity, final Calendar ptr, final String type) { final TreeMap<Date, TupleModelDataSet[]> valueMap = humidity.getValueMap(); final Date base = ptr.getTime(); final SortedMap<Date, TupleModelDataSet[]> headMap = valueMap.headMap(base); final SortedMap<Date, TupleModelDataSet[]> tailMap = valueMap.tailMap(base); if (!headMap.isEmpty() && DateUtils.isSameDay(headMap.lastKey(), base)) return getDataSet(headMap.get(headMap.lastKey()), type); else if (!tailMap.isEmpty() && DateUtils.isSameDay(tailMap.firstKey(), base)) return getDataSet(tailMap.get(tailMap.firstKey()), type); return null;// w w w . j av a 2s. c o m }
From source file:streaming.core.WindowOperation.java
@Override public Object[][] process(Object[] event) { long day = (Long) event[0]; String word = (String) event[1]; long freqs = (Long) event[2]; TreeMap<Long, Long> sortedFreq = map.get(word); if (sortedFreq == null) { sortedFreq = new TreeMap<Long, Long>(); map.put(word, sortedFreq);//ww w. j a v a2s . co m } Long t = sortedFreq.get(day); if (t != null) { freqs = freqs + t; } sortedFreq.put(day, freqs); Iterator<Entry<Long, Long>> iterator = sortedFreq.headMap(1 + day - numberOfDays).entrySet().iterator(); while (iterator.hasNext()) { iterator.next(); iterator.remove(); } DescriptiveStatistics stats = new DescriptiveStatistics(); long dayIndex = 1 + day - numberOfDays; for (Entry<Long, Long> e : sortedFreq.entrySet()) { while (e.getKey() > dayIndex) { dayIndex++; stats.addValue(0); } stats.addValue(e.getValue()); } if (sortedFreq.size() > numberOfDays) { System.out.println(day + " size=" + sortedFreq.size() + " " + sortedFreq); } double mean = stats.getMean(); double meadian = stats.getPercentile(50); mean = (mean == 0) ? 1 : mean; meadian = (meadian == 0) ? 1 : meadian; double stddev = stats.getStandardDeviation(); stddev = (stddev == 0) ? 1 : stddev; double cov = stddev / mean; //double swna = Math.log(freqs)*freqs/stats.getMean(); double swna1 = Math.log(meadian) * Math.abs(freqs - meadian) / stddev; if (Double.isNaN(swna1)) { System.out.println(); } double swna2 = Math.abs(freqs - meadian) / stddev; double swna3 = freqs / (meadian * cov); Gaussian gaussian = new Gaussian(100, 50); double swna4 = (0.1 + 100 * gaussian.value(meadian)) * freqs / (meadian * cov); int percentageAvialableValues = Math.round(100 * sortedFreq.size() / numberOfDays); //System.out.println("#"+ word + " " + freqs + " "+ stats.getMean() + Arrays.toString(stats.getValues())); return new Object[][] { { day, word, swna1, freqs, stats.getMean(), meadian, stddev, swna2, swna3, swna4, cov, percentageAvialableValues } }; // if(freqs > 3 && swna> 5){ // return new Object[][]{{day, word, swna}}; // }else{ // return null; // } }
From source file:io.github.jeddict.jpa.spec.sync.JavaClassSyncHandler.java
private void syncHeaderJavaDoc(TypeDeclaration<?> type) { TreeMap<Integer, Comment> comments = new TreeMap<>(); int packagePosition = 1; if (type.getParentNode().isPresent()) { Node parentNode = type.getParentNode().get(); parentNode.getComment().ifPresent(comment -> comments.put(comment.getBegin().get().line, comment)); for (Node node : parentNode.getChildNodes()) { if (node instanceof PackageDeclaration) { PackageDeclaration packageDeclaration = (PackageDeclaration) node; if (packageDeclaration.getBegin().isPresent()) { packagePosition = packageDeclaration.getBegin().get().line; }//from w w w . j a v a2 s . co m if (packageDeclaration.getComment().isPresent()) { Comment comment = packageDeclaration.getComment().get(); comments.put(comment.getBegin().get().line, comment); } } else if (node instanceof Comment) { Comment comment = (Comment) node; comments.put(comment.getBegin().get().line, comment); } } } type.getComment().ifPresent(comment -> comments.put(comment.getBegin().get().line, comment)); comments.headMap(packagePosition).values().forEach(this::syncHeader); comments.tailMap(packagePosition).values().forEach(this::syncJavadoc); }