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)
| 4158 | * @since 20.0 |
| 4159 | */ |
| 4160 | @Beta |
| 4161 | @GwtIncompatible // NavigableMap |
| 4162 | public static <K extends Comparable<? super K>, V> NavigableMap<K, V> subMap( |
| 4163 | NavigableMap<K, V> map, Range<K> range) { |
| 4164 | if (map.comparator() != null |
| 4165 | && map.comparator() != Ordering.natural() |
| 4166 | && range.hasLowerBound() |
| 4167 | && range.hasUpperBound()) { |
| 4168 | checkArgument( |
| 4169 | map.comparator().compare(range.lowerEndpoint(), range.upperEndpoint()) <= 0, |
| 4170 | "map is using a custom comparator which is inconsistent with the natural ordering."); |
| 4171 | } |
| 4172 | if (range.hasLowerBound() && range.hasUpperBound()) { |
| 4173 | return map.subMap( |
| 4174 | range.lowerEndpoint(), |
| 4175 | range.lowerBoundType() == BoundType.CLOSED, |
| 4176 | range.upperEndpoint(), |
| 4177 | range.upperBoundType() == BoundType.CLOSED); |
| 4178 | } else if (range.hasLowerBound()) { |
| 4179 | return map.tailMap(range.lowerEndpoint(), range.lowerBoundType() == BoundType.CLOSED); |
| 4180 | } else if (range.hasUpperBound()) { |
| 4181 | return map.headMap(range.upperEndpoint(), range.upperBoundType() == BoundType.CLOSED); |
| 4182 | } |
| 4183 | return checkNotNull(map); |
| 4184 | } |
| 4185 | } |
no test coverage detected