12f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson/* 22f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Written by Doug Lea and Josh Bloch with assistance from members of JCP 32f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * JSR-166 Expert Group and released to the public domain, as explained at 4a807b4d808d2591894daf13aab179b2e9c46a2f5Jesse Wilson * http://creativecommons.org/publicdomain/zero/1.0/ 56232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson */ 66232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson 76232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilsonpackage java.util; 86232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson 92f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson// BEGIN android-note 102f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson// removed link to collections framework docs 112f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson// END android-note 122f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson 136232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson/** 142f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * A {@link SortedMap} extended with navigation methods returning the 152f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * closest matches for given search targets. Methods 162f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@code lowerEntry}, {@code floorEntry}, {@code ceilingEntry}, 172f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * and {@code higherEntry} return {@code Map.Entry} objects 182f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * associated with keys respectively less than, less than or equal, 192f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * greater than or equal, and greater than a given key, returning 202f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@code null} if there is no such key. Similarly, methods 212f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@code lowerKey}, {@code floorKey}, {@code ceilingKey}, and 222f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@code higherKey} return only the associated keys. All of these 232f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * methods are designed for locating, not traversing entries. 242f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * 252f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p>A {@code NavigableMap} may be accessed and traversed in either 262f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * ascending or descending key order. The {@code descendingMap} 272f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * method returns a view of the map with the senses of all relational 282f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * and directional methods inverted. The performance of ascending 292f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * operations and views is likely to be faster than that of descending 302f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * ones. Methods {@code subMap}, {@code headMap}, 312f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * and {@code tailMap} differ from the like-named {@code 322f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * SortedMap} methods in accepting additional arguments describing 332f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * whether lower and upper bounds are inclusive versus exclusive. 342f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Submaps of any {@code NavigableMap} must implement the {@code 352f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * NavigableMap} interface. 366232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * 372f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p>This interface additionally defines methods {@code firstEntry}, 382f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@code pollFirstEntry}, {@code lastEntry}, and 392f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@code pollLastEntry} that return and/or remove the least and 402f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * greatest mappings, if any exist, else returning {@code null}. 412f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * 422f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p>Implementations of entry-returning methods are expected to 432f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * return {@code Map.Entry} pairs representing snapshots of mappings 442f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * at the time they were produced, and thus generally do <em>not</em> 452f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * support the optional {@code Entry.setValue} method. Note however 462f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * that it is possible to change mappings in the associated map using 472f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * method {@code put}. 482f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * 492f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p>Methods 50a807b4d808d2591894daf13aab179b2e9c46a2f5Jesse Wilson * {@link #subMap(Object, Object) subMap(K, K)}, 51a807b4d808d2591894daf13aab179b2e9c46a2f5Jesse Wilson * {@link #headMap(Object) headMap(K)}, and 52a807b4d808d2591894daf13aab179b2e9c46a2f5Jesse Wilson * {@link #tailMap(Object) tailMap(K)} 532f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * are specified to return {@code SortedMap} to allow existing 542f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * implementations of {@code SortedMap} to be compatibly retrofitted to 552f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * implement {@code NavigableMap}, but extensions and implementations 562f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * of this interface are encouraged to override these methods to return 572f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@code NavigableMap}. Similarly, 582f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@link #keySet()} can be overriden to return {@code NavigableSet}. 592f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * 602f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @author Doug Lea 612f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @author Josh Bloch 622f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @param <K> the type of keys maintained by this map 632f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @param <V> the type of mapped values 646232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * @since 1.6 656232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson */ 662f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilsonpublic interface NavigableMap<K,V> extends SortedMap<K,V> { 676232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson /** 682f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Returns a key-value mapping associated with the greatest key 692f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * strictly less than the given key, or {@code null} if there is 702f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * no such key. 716232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * 722f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @param key the key 732f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @return an entry with the greatest key less than {@code key}, 742f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * or {@code null} if there is no such key 752f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws ClassCastException if the specified key cannot be compared 762f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * with the keys currently in the map 772f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws NullPointerException if the specified key is null 782f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * and this map does not permit null keys 796232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson */ 802f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson Map.Entry<K,V> lowerEntry(K key); 816232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson 826232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson /** 832f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Returns the greatest key strictly less than the given key, or 842f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@code null} if there is no such key. 856232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * 862f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @param key the key 872f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @return the greatest key less than {@code key}, 882f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * or {@code null} if there is no such key 892f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws ClassCastException if the specified key cannot be compared 902f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * with the keys currently in the map 912f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws NullPointerException if the specified key is null 922f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * and this map does not permit null keys 936232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson */ 942f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson K lowerKey(K key); 956232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson 966232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson /** 972f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Returns a key-value mapping associated with the greatest key 982f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * less than or equal to the given key, or {@code null} if there 992f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * is no such key. 1006232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * 1012f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @param key the key 1022f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @return an entry with the greatest key less than or equal to 1032f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@code key}, or {@code null} if there is no such key 1042f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws ClassCastException if the specified key cannot be compared 1052f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * with the keys currently in the map 1062f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws NullPointerException if the specified key is null 1072f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * and this map does not permit null keys 1086232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson */ 1092f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson Map.Entry<K,V> floorEntry(K key); 1106232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson 1116232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson /** 1122f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Returns the greatest key less than or equal to the given key, 1132f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * or {@code null} if there is no such key. 1146232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * 1152f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @param key the key 1162f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @return the greatest key less than or equal to {@code key}, 1172f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * or {@code null} if there is no such key 1182f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws ClassCastException if the specified key cannot be compared 1192f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * with the keys currently in the map 1202f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws NullPointerException if the specified key is null 1212f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * and this map does not permit null keys 1226232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson */ 1232f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson K floorKey(K key); 1246232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson 1256232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson /** 1262f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Returns a key-value mapping associated with the least key 1272f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * greater than or equal to the given key, or {@code null} if 1282f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * there is no such key. 1296232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * 1302f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @param key the key 1312f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @return an entry with the least key greater than or equal to 1322f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@code key}, or {@code null} if there is no such key 1332f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws ClassCastException if the specified key cannot be compared 1342f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * with the keys currently in the map 1352f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws NullPointerException if the specified key is null 1362f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * and this map does not permit null keys 1376232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson */ 1382f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson Map.Entry<K,V> ceilingEntry(K key); 1396232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson 1406232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson /** 1412f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Returns the least key greater than or equal to the given key, 1422f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * or {@code null} if there is no such key. 1436232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * 1442f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @param key the key 1452f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @return the least key greater than or equal to {@code key}, 1462f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * or {@code null} if there is no such key 1472f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws ClassCastException if the specified key cannot be compared 1482f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * with the keys currently in the map 1492f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws NullPointerException if the specified key is null 1502f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * and this map does not permit null keys 1516232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson */ 1526232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson K ceilingKey(K key); 1536232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson 1546232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson /** 1552f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Returns a key-value mapping associated with the least key 1562f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * strictly greater than the given key, or {@code null} if there 1572f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * is no such key. 1586232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * 1592f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @param key the key 1602f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @return an entry with the least key greater than {@code key}, 1612f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * or {@code null} if there is no such key 1622f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws ClassCastException if the specified key cannot be compared 1632f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * with the keys currently in the map 1642f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws NullPointerException if the specified key is null 1652f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * and this map does not permit null keys 1666232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson */ 1672f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson Map.Entry<K,V> higherEntry(K key); 1686232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson 1696232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson /** 1702f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Returns the least key strictly greater than the given key, or 1712f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@code null} if there is no such key. 1726232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * 1732f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @param key the key 1742f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @return the least key greater than {@code key}, 1752f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * or {@code null} if there is no such key 1762f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws ClassCastException if the specified key cannot be compared 1772f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * with the keys currently in the map 1782f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws NullPointerException if the specified key is null 1792f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * and this map does not permit null keys 1806232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson */ 1816232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson K higherKey(K key); 1826232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson 1836232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson /** 1842f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Returns a key-value mapping associated with the least 1852f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * key in this map, or {@code null} if the map is empty. 1866232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * 1872f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @return an entry with the least key, 1882f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * or {@code null} if this map is empty 1896232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson */ 1902f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson Map.Entry<K,V> firstEntry(); 1916232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson 1926232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson /** 1932f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Returns a key-value mapping associated with the greatest 1942f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * key in this map, or {@code null} if the map is empty. 1956232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * 1962f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @return an entry with the greatest key, 1972f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * or {@code null} if this map is empty 1986232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson */ 1992f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson Map.Entry<K,V> lastEntry(); 2006232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson 2016232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson /** 2022f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Removes and returns a key-value mapping associated with 2032f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * the least key in this map, or {@code null} if the map is empty. 2046232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * 2052f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @return the removed first entry of this map, 2062f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * or {@code null} if this map is empty 2076232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson */ 2082f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson Map.Entry<K,V> pollFirstEntry(); 2096232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson 2106232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson /** 2112f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Removes and returns a key-value mapping associated with 2122f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * the greatest key in this map, or {@code null} if the map is empty. 2136232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * 2142f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @return the removed last entry of this map, 2152f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * or {@code null} if this map is empty 2166232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson */ 2172f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson Map.Entry<K,V> pollLastEntry(); 2186232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson 2196232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson /** 2202f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Returns a reverse order view of the mappings contained in this map. 2212f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * The descending map is backed by this map, so changes to the map are 2222f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * reflected in the descending map, and vice-versa. If either map is 2232f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * modified while an iteration over a collection view of either map 2242f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * is in progress (except through the iterator's own {@code remove} 2252f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * operation), the results of the iteration are undefined. 2262f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * 2272f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p>The returned map has an ordering equivalent to 2282f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <tt>{@link Collections#reverseOrder(Comparator) Collections.reverseOrder}(comparator())</tt>. 2292f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * The expression {@code m.descendingMap().descendingMap()} returns a 2302f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * view of {@code m} essentially equivalent to {@code m}. 2316232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * 2322f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @return a reverse order view of this map 2336232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson */ 2342f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson NavigableMap<K,V> descendingMap(); 2356232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson 2366232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson /** 2372f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Returns a {@link NavigableSet} view of the keys contained in this map. 2382f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * The set's iterator returns the keys in ascending order. 2392f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * The set is backed by the map, so changes to the map are reflected in 2402f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * the set, and vice-versa. If the map is modified while an iteration 2412f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * over the set is in progress (except through the iterator's own {@code 2422f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * remove} operation), the results of the iteration are undefined. The 2432f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * set supports element removal, which removes the corresponding mapping 2442f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * from the map, via the {@code Iterator.remove}, {@code Set.remove}, 2452f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@code removeAll}, {@code retainAll}, and {@code clear} operations. 2462f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * It does not support the {@code add} or {@code addAll} operations. 2476232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * 2482f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @return a navigable set view of the keys in this map 2496232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson */ 2502f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson NavigableSet<K> navigableKeySet(); 2516232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson 2526232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson /** 2532f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Returns a reverse order {@link NavigableSet} view of the keys contained in this map. 2542f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * The set's iterator returns the keys in descending order. 2552f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * The set is backed by the map, so changes to the map are reflected in 2562f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * the set, and vice-versa. If the map is modified while an iteration 2572f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * over the set is in progress (except through the iterator's own {@code 2582f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * remove} operation), the results of the iteration are undefined. The 2592f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * set supports element removal, which removes the corresponding mapping 2602f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * from the map, via the {@code Iterator.remove}, {@code Set.remove}, 2612f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@code removeAll}, {@code retainAll}, and {@code clear} operations. 2622f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * It does not support the {@code add} or {@code addAll} operations. 2636232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * 2642f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @return a reverse order navigable set view of the keys in this map 2656232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson */ 2666232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson NavigableSet<K> descendingKeySet(); 2676232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson 2686232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson /** 2692f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Returns a view of the portion of this map whose keys range from 2702f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@code fromKey} to {@code toKey}. If {@code fromKey} and 2712f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@code toKey} are equal, the returned map is empty unless 2722f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@code fromExclusive} and {@code toExclusive} are both true. The 2732f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * returned map is backed by this map, so changes in the returned map are 2742f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * reflected in this map, and vice-versa. The returned map supports all 2752f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * optional map operations that this map supports. 2762f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * 2772f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p>The returned map will throw an {@code IllegalArgumentException} 2782f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * on an attempt to insert a key outside of its range, or to construct a 2792f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * submap either of whose endpoints lie outside its range. 2802f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * 2812f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @param fromKey low endpoint of the keys in the returned map 2822f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @param fromInclusive {@code true} if the low endpoint 2832f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * is to be included in the returned view 2842f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @param toKey high endpoint of the keys in the returned map 2852f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @param toInclusive {@code true} if the high endpoint 2862f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * is to be included in the returned view 2872f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @return a view of the portion of this map whose keys range from 2882f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@code fromKey} to {@code toKey} 2892f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws ClassCastException if {@code fromKey} and {@code toKey} 2902f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * cannot be compared to one another using this map's comparator 2912f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * (or, if the map has no comparator, using natural ordering). 2922f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Implementations may, but are not required to, throw this 2932f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * exception if {@code fromKey} or {@code toKey} 2942f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * cannot be compared to keys currently in the map. 2952f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws NullPointerException if {@code fromKey} or {@code toKey} 2962f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * is null and this map does not permit null keys 2972f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws IllegalArgumentException if {@code fromKey} is greater than 2982f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@code toKey}; or if this map itself has a restricted 2992f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * range, and {@code fromKey} or {@code toKey} lies 3002f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * outside the bounds of the range 3012f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson */ 3022f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson NavigableMap<K,V> subMap(K fromKey, boolean fromInclusive, 3032f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson K toKey, boolean toInclusive); 3042f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson 3052f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson /** 3062f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Returns a view of the portion of this map whose keys are less than (or 3072f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * equal to, if {@code inclusive} is true) {@code toKey}. The returned 3082f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * map is backed by this map, so changes in the returned map are reflected 3092f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * in this map, and vice-versa. The returned map supports all optional 3102f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * map operations that this map supports. 3112f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * 3122f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p>The returned map will throw an {@code IllegalArgumentException} 3132f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * on an attempt to insert a key outside its range. 3142f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * 3152f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @param toKey high endpoint of the keys in the returned map 3162f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @param inclusive {@code true} if the high endpoint 3172f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * is to be included in the returned view 3182f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @return a view of the portion of this map whose keys are less than 3192f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * (or equal to, if {@code inclusive} is true) {@code toKey} 3202f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws ClassCastException if {@code toKey} is not compatible 3212f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * with this map's comparator (or, if the map has no comparator, 3222f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * if {@code toKey} does not implement {@link Comparable}). 3232f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Implementations may, but are not required to, throw this 3242f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * exception if {@code toKey} cannot be compared to keys 3252f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * currently in the map. 3262f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws NullPointerException if {@code toKey} is null 3272f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * and this map does not permit null keys 3282f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws IllegalArgumentException if this map itself has a 3292f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * restricted range, and {@code toKey} lies outside the 3302f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * bounds of the range 3312f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson */ 3322f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson NavigableMap<K,V> headMap(K toKey, boolean inclusive); 3332f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson 3342f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson /** 3352f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Returns a view of the portion of this map whose keys are greater than (or 3362f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * equal to, if {@code inclusive} is true) {@code fromKey}. The returned 3372f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * map is backed by this map, so changes in the returned map are reflected 3382f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * in this map, and vice-versa. The returned map supports all optional 3392f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * map operations that this map supports. 3402f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * 3412f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p>The returned map will throw an {@code IllegalArgumentException} 3422f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * on an attempt to insert a key outside its range. 3432f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * 3442f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @param fromKey low endpoint of the keys in the returned map 3452f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @param inclusive {@code true} if the low endpoint 3462f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * is to be included in the returned view 3472f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @return a view of the portion of this map whose keys are greater than 3482f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * (or equal to, if {@code inclusive} is true) {@code fromKey} 3492f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws ClassCastException if {@code fromKey} is not compatible 3502f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * with this map's comparator (or, if the map has no comparator, 3512f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * if {@code fromKey} does not implement {@link Comparable}). 3522f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Implementations may, but are not required to, throw this 3532f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * exception if {@code fromKey} cannot be compared to keys 3542f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * currently in the map. 3552f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws NullPointerException if {@code fromKey} is null 3562f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * and this map does not permit null keys 3572f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws IllegalArgumentException if this map itself has a 3582f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * restricted range, and {@code fromKey} lies outside the 3592f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * bounds of the range 3602f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson */ 3612f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson NavigableMap<K,V> tailMap(K fromKey, boolean inclusive); 3622f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson 3632f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson /** 3642f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@inheritDoc} 3656232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * 3662f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p>Equivalent to {@code subMap(fromKey, true, toKey, false)}. 3676232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * 3682f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws ClassCastException {@inheritDoc} 3692f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws NullPointerException {@inheritDoc} 3702f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws IllegalArgumentException {@inheritDoc} 3716232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson */ 3722f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson SortedMap<K,V> subMap(K fromKey, K toKey); 3736232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson 3746232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson /** 3752f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@inheritDoc} 3766232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * 3772f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p>Equivalent to {@code headMap(toKey, false)}. 3786232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * 3792f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws ClassCastException {@inheritDoc} 3802f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws NullPointerException {@inheritDoc} 3812f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws IllegalArgumentException {@inheritDoc} 3826232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson */ 3832f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson SortedMap<K,V> headMap(K toKey); 3846232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson 3856232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson /** 3862f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@inheritDoc} 3876232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * 3882f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p>Equivalent to {@code tailMap(fromKey, true)}. 3896232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson * 3902f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws ClassCastException {@inheritDoc} 3912f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws NullPointerException {@inheritDoc} 3922f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @throws IllegalArgumentException {@inheritDoc} 3936232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson */ 3942f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson SortedMap<K,V> tailMap(K fromKey); 3952f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson} 396