Returns a view of the portion of set whose elements are contained by range. This method delegates to the appropriate methods of NavigableSet (namely NavigableSet#subSet(Object, boolean, Object, boolean) subSet(), {@link NavigableSet#tailSet(Object, boolean) tailSe
(NavigableSet<K> set, Range<K> range)
| 1807 | */ |
| 1808 | |
| 1809 | @Beta |
| 1810 | @GwtIncompatible // NavigableSet |
| 1811 | public static <K extends Comparable<? super K>> NavigableSet<K> subSet(NavigableSet<K> set, Range<K> range) { |
| 1812 | if (set.comparator() != null && set.comparator() != Ordering.natural() |
| 1813 | && range.hasLowerBound() |
| 1814 | && range.hasUpperBound()) { |
| 1815 | checkArgument(set.comparator().compare(range.lowerEndpoint(), range.upperEndpoint()) <= 0, "set is using a custom comparator which is inconsistent with the natural ordering."); |
| 1816 | } |
| 1817 | if (range.hasLowerBound() && range.hasUpperBound()) { |
| 1818 | return set.subSet( |
| 1819 | range.lowerEndpoint(), range.lowerBoundType() == BoundType.CLOSED, |
| 1820 | range.upperEndpoint(), range.upperBoundType() == BoundType.CLOSED); |
| 1821 | } else if (range.hasLowerBound()) { |
| 1822 | return set.tailSet(range.lowerEndpoint(), range.lowerBoundType() == BoundType.CLOSED); |
| 1823 | } else if (range.hasUpperBound()) { |
| 1824 | return set.headSet(range.upperEndpoint(), range.upperBoundType() == BoundType.CLOSED); |
| 1825 | } |
| 1826 | return checkNotNull(set); |
| 1827 | } |
| 1828 | } |
no test coverage detected