Most visited

Recently visited

Added in API level 9

NavigableMap

public interface NavigableMap
implements SortedMap<K, V>

java.util.NavigableMap<K, V>
Known Indirect Subclasses


用导航方法扩展的SortedMap为给定的搜索目标返回最接近的匹配。 方法lowerEntry(K)floorEntry(K)ceilingEntry(K)higherEntry(K)返回Map.Entry与键相关联的对象比比大于给定的密钥分别更少,小于或等于,大于或等于,大于,返回null如果不存在这样的密钥。 同样,方法lowerKey(K)floorKey(K)ceilingKey(K) ,并higherKey(K)回报只有相关联的密钥。 所有这些方法都被设计用于定位,而不是遍历条目。

NavigableMap可以按照升序或降序键的顺序访问和遍历。 descendingMap()方法返回地图的视图,其中所有关系和方向方法的意义都反转了。 上行操作和意见的表现可能比下行表现更快。 方法subMap(K, boolean, K, boolean)headMap(K, boolean)tailMap(K, boolean)从等命名的不同SortedMap在接受描述的下限和上限是否是包含性的抗排斥附加参数的方法。 任何NavigableMapNavigableMap必须实现NavigableMap接口。

此接口还定义了方法 firstEntry()pollFirstEntry()lastEntry() ,并 pollLastEntry()返回和/或删除至少和最大的映射关系,如果存在,否则返回 null

入口返回方法的实现预计会返回Map.Entry对,它们表示映射快照在生成时的快照,因此通常支持可选的Entry.setValue方法。 但请注意,可以使用方法put更改相关映射中的映射。

方法subMap(K, K)headMap(K) ,并tailMap(K)被指定为返回SortedMap ,以允许现有的实现SortedMap能相容地改进来实现NavigableMap ,但鼓励扩展和该接口的实现重写这些方法返回NavigableMap 同样, keySet()可以被覆盖返回NavigableSet

Summary

Public methods

abstract Entry<K, V> ceilingEntry(K key)

返回与最小键大于或等于给定键相关联的键 - 值映射,如果不存在这样的键,则 null

abstract K ceilingKey(K key)

返回大于或等于给定键的 null键,或者如果不存在这样的键,则 null

abstract NavigableSet<K> descendingKeySet()

返回此映射中包含的键的相反顺序 NavigableSet视图。

abstract NavigableMap<K, V> descendingMap()

返回此映射中包含的映射的逆序视图。

abstract Entry<K, V> firstEntry()

返回与此地图中最小键值关联的键值映射,如果地图为空,则 null

abstract Entry<K, V> floorEntry(K key)

返回与最大键小于或等于给定键相关联的键 - 值映射,或者如果没有这样的键,则 null

abstract K floorKey(K key)

返回小于或等于给定键的最大键,或者如果不存在这样的键,则 null

abstract SortedMap<K, V> headMap(K toKey)

返回此映射的关键字严格小于 toKey的部分的视图。

相当于 headMap(toKey, false)

abstract NavigableMap<K, V> headMap(K toKey, boolean inclusive)

返回此映射的关键字小于(或等于,如果 inclusive为true) toKey

abstract Entry<K, V> higherEntry(K key)

返回与最小键相关的键值映射,严格大于给定键,或者如果没有这样的键,则 null

abstract K higherKey(K key)

返回严格大于给定键的最小键,或者如果不存在这样的键,则返回 null

abstract Entry<K, V> lastEntry()

返回与此地图中最大键关联的键值映射,如果地图为空,则 null

abstract Entry<K, V> lowerEntry(K key)

返回与最大键相关的键 - 值映射严格小于给定键,或者如果没有这样的键,则 null

abstract K lowerKey(K key)

如果没有这样的密钥,则返回严格小于给定密钥的最大密钥或 null

abstract NavigableSet<K> navigableKeySet()

返回包含在此映射中的键的 NavigableSet视图。

abstract Entry<K, V> pollFirstEntry()

删除并返回与此地图中最少键值关联的键值映射,或者 null映射为空的 null

abstract Entry<K, V> pollLastEntry()

移除并返回与此地图中最大键关联的键值映射,或者 null映射为空的 null

abstract SortedMap<K, V> subMap(K fromKey, K toKey)

返回此映射部分的视图,其键的范围从 fromKey (含)到 toKey (独占)。

相当于 subMap(fromKey, true, toKey, false)

abstract NavigableMap<K, V> subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive)

返回此映射部分的视图,其键的范围从 fromKeytoKey

abstract NavigableMap<K, V> tailMap(K fromKey, boolean inclusive)

返回此映射的关键字大于(或等于,如果 inclusive为true) fromKey

abstract SortedMap<K, V> tailMap(K fromKey)

返回此映射的关键字大于或等于 fromKey的部分的视图。

相当于 tailMap(fromKey, true)

Inherited methods

From interface java.util.SortedMap
From interface java.util.Map

Public methods

ceilingEntry

Added in API level 9
Entry<K, V> ceilingEntry (K key)

返回与最小键大于或等于给定键相关联的键 - 值映射,如果不存在这样的键,则 null

Parameters
key K: the key
Returns
Entry<K, V> an entry with the least key greater than or equal to key, or null if there is no such key
Throws
ClassCastException if the specified key cannot be compared with the keys currently in the map
NullPointerException if the specified key is null and this map does not permit null keys

ceilingKey

Added in API level 9
K ceilingKey (K key)

返回大于或等于给定键的 null键,或者如果没有这样的键,则 null

Parameters
key K: the key
Returns
K the least key greater than or equal to key, or null if there is no such key
Throws
ClassCastException if the specified key cannot be compared with the keys currently in the map
NullPointerException if the specified key is null and this map does not permit null keys

descendingKeySet

Added in API level 9
NavigableSet<K> descendingKeySet ()

返回此映射中包含的键的逆序NavigableSet视图。 集合的迭代器按降序返回键。 该集合由地图支持,因此对地图的更改反映在集合中,反之亦然。 如果在对集合进行迭代的过程中修改了映射(除了通过迭代器自己的remove操作),迭代的结果是未定义的。 该组支持元件移除,即从映射中相应的映射,经由Iterator.removeSet.removeremoveAllretainAll ,和clear操作。 它不支持addaddAll操作。

Returns
NavigableSet<K> a reverse order navigable set view of the keys in this map

descendingMap

Added in API level 9
NavigableMap<K, V> descendingMap ()

返回此映射中包含的映射的逆序视图。 降序地图由此地图支持,因此对地图的更改反映在降序地图中,反之亦然。 如果两个map中的任何一个在迭代时正在进行迭代(除了通过迭代器自己的remove操作),那么迭代的结果是未定义的。

返回的地图的订购等同于Collections.reverseOrder (comparator()) 表达m.descendingMap().descendingMap()返回一个视图的m实质上等同于m

Returns
NavigableMap<K, V> a reverse order view of this map

firstEntry

Added in API level 9
Entry<K, V> firstEntry ()

返回与此地图中最小键值关联的键值映射,如果地图为空,则 null

Returns
Entry<K, V> an entry with the least key, or null if this map is empty

floorEntry

Added in API level 9
Entry<K, V> floorEntry (K key)

返回与最大键小于或等于给定键相关联的键 - 值映射,或者如果不存在这样的键,则 null

Parameters
key K: the key
Returns
Entry<K, V> an entry with the greatest key less than or equal to key, or null if there is no such key
Throws
ClassCastException if the specified key cannot be compared with the keys currently in the map
NullPointerException if the specified key is null and this map does not permit null keys

floorKey

Added in API level 9
K floorKey (K key)

返回小于或等于给定键的最大键,或者如果没有这样的键,则 null

Parameters
key K: the key
Returns
K the greatest key less than or equal to key, or null if there is no such key
Throws
ClassCastException if the specified key cannot be compared with the keys currently in the map
NullPointerException if the specified key is null and this map does not permit null keys

headMap

Added in API level 11
SortedMap<K, V> headMap (K toKey)

返回此映射的关键字严格小于toKey的部分的视图。 返回的地图由此地图支持,因此返回地图中的更改会反映在此地图中,反之亦然。 返回的地图支持该地图支持的所有可选地图操作。

试图在其范围外插入密钥时,返回的地图会抛出 IllegalArgumentException

相当于 headMap(toKey, false)

Parameters
toKey K: high endpoint (exclusive) of the keys in the returned map
Returns
SortedMap<K, V> a view of the portion of this map whose keys are strictly less than toKey
Throws
ClassCastException
NullPointerException
IllegalArgumentException

headMap

Added in API level 9
NavigableMap<K, V> headMap (K toKey, 
                boolean inclusive)

返回此映射关键字小于(或等于,如果inclusive为true) toKey 返回的地图由此地图支持,因此返回地图中的更改会反映在此地图中,反之亦然。 返回的地图支持该地图支持的所有可选地图操作。

返回的地图将尝试在其范围外插入密钥,以引发 IllegalArgumentException

Parameters
toKey K: high endpoint of the keys in the returned map
inclusive boolean: true if the high endpoint is to be included in the returned view
Returns
NavigableMap<K, V> a view of the portion of this map whose keys are less than (or equal to, if inclusive is true) toKey
Throws
ClassCastException if toKey is not compatible with this map's comparator (or, if the map has no comparator, if toKey does not implement Comparable). Implementations may, but are not required to, throw this exception if toKey cannot be compared to keys currently in the map.
NullPointerException if toKey is null and this map does not permit null keys
IllegalArgumentException if this map itself has a restricted range, and toKey lies outside the bounds of the range

higherEntry

Added in API level 9
Entry<K, V> higherEntry (K key)

返回与最小键相关的键 - 值映射严格大于给定键,如果没有这样的键,则 null

Parameters
key K: the key
Returns
Entry<K, V> an entry with the least key greater than key, or null if there is no such key
Throws
ClassCastException if the specified key cannot be compared with the keys currently in the map
NullPointerException if the specified key is null and this map does not permit null keys

higherKey

Added in API level 9
K higherKey (K key)

返回严格大于给定键的最小键,或者如果没有这样的键,则返回 null

Parameters
key K: the key
Returns
K the least key greater than key, or null if there is no such key
Throws
ClassCastException if the specified key cannot be compared with the keys currently in the map
NullPointerException if the specified key is null and this map does not permit null keys

lastEntry

Added in API level 9
Entry<K, V> lastEntry ()

返回与此地图中最大键关联的键值映射,如果地图为空,则 null

Returns
Entry<K, V> an entry with the greatest key, or null if this map is empty

lowerEntry

Added in API level 9
Entry<K, V> lowerEntry (K key)

返回与最大键相关的键 - 值映射严格小于给定键,或者如果没有这样的键,则 null

Parameters
key K: the key
Returns
Entry<K, V> an entry with the greatest key less than key, or null if there is no such key
Throws
ClassCastException if the specified key cannot be compared with the keys currently in the map
NullPointerException if the specified key is null and this map does not permit null keys

lowerKey

Added in API level 9
K lowerKey (K key)

如果没有这样的密钥,则返回严格小于给定密钥的最大密钥,或 null

Parameters
key K: the key
Returns
K the greatest key less than key, or null if there is no such key
Throws
ClassCastException if the specified key cannot be compared with the keys currently in the map
NullPointerException if the specified key is null and this map does not permit null keys

navigableKeySet

Added in API level 9
NavigableSet<K> navigableKeySet ()

返回包含在此映射中的键的NavigableSet视图。 集合的迭代器按照升序返回键。 该集合由地图支持,因此对地图的更改反映在集合中,反之亦然。 如果在对集合进行迭代时修改了映射(除了通过迭代器自己的remove操作),迭代的结果是未定义的。 该组支持元件移除,即从映射中相应的映射,经由Iterator.removeSet.removeremoveAllretainAll ,和clear操作。 它不支持addaddAll操作。

Returns
NavigableSet<K> a navigable set view of the keys in this map

pollFirstEntry

Added in API level 9
Entry<K, V> pollFirstEntry ()

移除并返回与此地图中最小键值关联的键值映射,或者 null映射为空的 null

Returns
Entry<K, V> the removed first entry of this map, or null if this map is empty

pollLastEntry

Added in API level 9
Entry<K, V> pollLastEntry ()

移除并返回与此地图中最大键关联的键值映射,或者 null映射为空的 null

Returns
Entry<K, V> the removed last entry of this map, or null if this map is empty

subMap

Added in API level 11
SortedMap<K, V> subMap (K fromKey, 
                K toKey)

返回此映射部分的视图,其键的范围从fromKey (含)到toKey (不包括)。 (如果fromKeytoKey相等,则返回的地图为空。)返回的地图由此地图支持,因此返回的地图中的更改将反映在此地图中,反之亦然。 返回的地图支持该地图支持的所有可选地图操作。

返回的地图将尝试在其范围之外插入密钥时尝试输入 IllegalArgumentException

相当于 subMap(fromKey, true, toKey, false)

Parameters
fromKey K: low endpoint (inclusive) of the keys in the returned map
toKey K: high endpoint (exclusive) of the keys in the returned map
Returns
SortedMap<K, V> a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive
Throws
ClassCastException
NullPointerException
IllegalArgumentException

subMap

Added in API level 9
NavigableMap<K, V> subMap (K fromKey, 
                boolean fromInclusive, 
                K toKey, 
                boolean toInclusive)

返回此映射部分的视图,其键的范围从fromKeytoKey 如果fromKeytoKey相等,则返回的映射为空,除非fromInclusivetoInclusive均为真。 返回的地图由此地图支持,因此返回地图中的更改会反映在此地图中,反之亦然。 返回的地图支持该地图支持的所有可选地图操作。

返回的映射将尝试在其范围外插入一个键,或者构造其端点位于其范围之外的子映射的 IllegalArgumentException

Parameters
fromKey K: low endpoint of the keys in the returned map
fromInclusive boolean: true if the low endpoint is to be included in the returned view
toKey K: high endpoint of the keys in the returned map
toInclusive boolean: true if the high endpoint is to be included in the returned view
Returns
NavigableMap<K, V> a view of the portion of this map whose keys range from fromKey to toKey
Throws
ClassCastException if fromKey and toKey cannot be compared to one another using this map's comparator (or, if the map has no comparator, using natural ordering). Implementations may, but are not required to, throw this exception if fromKey or toKey cannot be compared to keys currently in the map.
NullPointerException if fromKey or toKey is null and this map does not permit null keys
IllegalArgumentException if fromKey is greater than toKey; or if this map itself has a restricted range, and fromKey or toKey lies outside the bounds of the range

tailMap

Added in API level 9
NavigableMap<K, V> tailMap (K fromKey, 
                boolean inclusive)

返回此映射的关键字大于(或等于,如果inclusive为true) fromKey 返回的地图由此地图支持,因此返回地图中的更改会反映在此地图中,反之亦然。 返回的地图支持该地图支持的所有可选地图操作。

返回的地图将尝试在其范围外插入密钥时尝试输入 IllegalArgumentException

Parameters
fromKey K: low endpoint of the keys in the returned map
inclusive boolean: true if the low endpoint is to be included in the returned view
Returns
NavigableMap<K, V> a view of the portion of this map whose keys are greater than (or equal to, if inclusive is true) fromKey
Throws
ClassCastException if fromKey is not compatible with this map's comparator (or, if the map has no comparator, if fromKey does not implement Comparable). Implementations may, but are not required to, throw this exception if fromKey cannot be compared to keys currently in the map.
NullPointerException if fromKey is null and this map does not permit null keys
IllegalArgumentException if this map itself has a restricted range, and fromKey lies outside the bounds of the range

tailMap

Added in API level 11
SortedMap<K, V> tailMap (K fromKey)

返回此映射的关键字大于或等于fromKey的部分的视图。 返回的地图由此地图支持,因此返回地图中的更改会反映在此地图中,反之亦然。 返回的地图支持该地图支持的所有可选地图操作。

返回的地图将尝试在其范围外插入密钥时尝试输入 IllegalArgumentException

相当于 tailMap(fromKey, true)

Parameters
fromKey K: low endpoint (inclusive) of the keys in the returned map
Returns
SortedMap<K, V> a view of the portion of this map whose keys are greater than or equal to fromKey
Throws
ClassCastException
NullPointerException
IllegalArgumentException

Hooray!