List of usage examples for java.util TreeMap tailMap
public SortedMap<K, V> tailMap(K fromKey)
From source file:org.cloudata.core.client.TabletLocationCache.java
protected TabletInfo findFromCache(String tableName, TreeMap<Row.Key, TabletInfo> cache, Row.Key cacheRowKey, Row.Key dataRowKey) {// w w w. j a v a 2s. c om cacheLock.obtainReadLock(); try { if (cache.containsKey(cacheRowKey)) { TabletInfo tabletInfo = cache.get(cacheRowKey); if (tabletInfo.belongRowRange(cacheRowKey)) { return tabletInfo; } else { return null; } } SortedMap<Row.Key, TabletInfo> tailMap = cache.tailMap(cacheRowKey); if (tailMap.isEmpty()) { return null; } Row.Key tailFirst = tailMap.firstKey(); TabletInfo tabletInfo = tailMap.get(tailFirst); if (tableName.equals(tabletInfo.getTableName()) && tabletInfo.belongRowRange(dataRowKey)) { return tabletInfo; } else { return null; } } finally { cacheLock.releaseReadLock(); } }
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 ww . j a va 2 s . c o m*/ }