Returns a view of the portion of map whose keys are contained by range. This method delegates to the appropriate methods of NavigableMap (namely NavigableMap#subMap(Object, boolean, Object, boolean) subMap(), NavigableMap#tailMap(Object, boolean) tailMap()
(NavigableMap<K, V> map, Range<K> range)
| 4230 | */ |
| 4231 | |
| 4232 | @Beta |
| 4233 | @GwtIncompatible // NavigableMap |
| 4234 | public static <K extends Comparable<? super K>, V> NavigableMap<K, V> subMap(NavigableMap<K, V> map, Range<K> range) { |
| 4235 | if (map.comparator() != null && map.comparator() != Ordering.natural() |
| 4236 | && range.hasLowerBound() |
| 4237 | && range.hasUpperBound()) { |
| 4238 | checkArgument(map.comparator().compare(range.lowerEndpoint(), range.upperEndpoint()) <= 0, "map is using a custom comparator which is inconsistent with the natural ordering."); |
| 4239 | } |
| 4240 | if (range.hasLowerBound() && range.hasUpperBound()) { |
| 4241 | return map.subMap( |
| 4242 | range.lowerEndpoint(), |
| 4243 | range.lowerBoundType() == BoundType.CLOSED, |
| 4244 | range.upperEndpoint(), |
| 4245 | range.upperBoundType() == BoundType.CLOSED); |
| 4246 | } else if (range.hasLowerBound()) { |
| 4247 | return map.tailMap(range.lowerEndpoint(), range.lowerBoundType() == BoundType.CLOSED); |
| 4248 | } else if (range.hasUpperBound()) { |
| 4249 | return map.headMap(range.upperEndpoint(), range.upperBoundType() == BoundType.CLOSED); |
| 4250 | } |
| 4251 | return checkNotNull(map); |
| 4252 | } |
| 4253 | } |
no test coverage detected