@Override public E last() { SortedSet<E> sortedUnfiltered = (SortedSet<E>) unfiltered; while (true) { E element = sortedUnfiltered.last(); if (predicate.apply(element)) { return element; } sortedUnfiltered = sortedUnfiltered.headSet(element); } } }
/** Calls the smallest subSet overload that filters out the extreme values. */ SortedSet<E> createSubSet(SortedSet<E> set, E firstExclusive, E lastExclusive) { if (from == Bound.NO_BOUND && to == Bound.EXCLUSIVE) { return set.headSet(lastExclusive); } else if (from == Bound.INCLUSIVE && to == Bound.NO_BOUND) { return set.tailSet(firstInclusive); } else if (from == Bound.INCLUSIVE && to == Bound.EXCLUSIVE) { return set.subSet(firstInclusive, lastExclusive); } else { throw new IllegalArgumentException(); } }
@Override public SortedSet<E> headSet(E toElement) { synchronized (mutex) { return sortedSet(delegate().headSet(toElement), mutex); } }
/** * A sensible default implementation of {@link #subSet(Object, Object)} in terms of {@link * #headSet(Object)} and {@link #tailSet(Object)}. In some situations, you may wish to override * {@link #subSet(Object, Object)} to forward to this implementation. * * @since 7.0 */ @Beta protected SortedSet<E> standardSubSet(E fromElement, E toElement) { return tailSet(fromElement).headSet(toElement); } }
@Override public SortedSet<E> headSet(E toElement) { return delegate().headSet(toElement); }
@Override public SortedSet<E> headSet(E toElement) { return new FilteredSortedSet<E>(((SortedSet<E>) unfiltered).headSet(toElement), predicate); }
@Override public SortedSet<E> headSet(E toElement) { synchronized (mutex) { return sortedSet(delegate().headSet(toElement), mutex); } }
@Override public E last() { SortedSet<E> sortedUnfiltered = (SortedSet<E>) unfiltered; while (true) { E element = sortedUnfiltered.last(); if (predicate.apply(element)) { return element; } sortedUnfiltered = sortedUnfiltered.headSet(element); } } }
@Override public SortedMap<K, V> headMap(K toKey) { return asMap(backingSet().headSet(toKey), function); }
/** * A sensible default implementation of {@link #subSet(Object, Object)} in terms of {@link * #headSet(Object)} and {@link #tailSet(Object)}. In some situations, you may wish to override * {@link #subSet(Object, Object)} to forward to this implementation. * * @since 7.0 */ @Beta protected SortedSet<E> standardSubSet(E fromElement, E toElement) { return tailSet(fromElement).headSet(toElement); } }
@Override public SortedMap<K, V> headMap(K toKey) { return asMap(backingSet().headSet(toKey), function); }
public void testOf_headSet() { SortedSet<String> set = of("e", "f", "b", "d", "c"); assertTrue(set.headSet("e") instanceof ImmutableSortedSet); assertThat(set.headSet("e")).containsExactly("b", "c", "d").inOrder(); assertThat(set.headSet("g")).containsExactly("b", "c", "d", "e", "f").inOrder(); assertSame(of(), set.headSet("a")); assertSame(of(), set.headSet("b")); }
public void testExplicit_headSet() { SortedSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH) .add("in", "the", "quick", "jumped", "over", "a") .build(); assertTrue(set.headSet("a") instanceof ImmutableSortedSet); assertTrue(set.headSet("fish") instanceof ImmutableSortedSet); assertThat(set.headSet("fish")).containsExactly("a", "in", "the").inOrder(); assertThat(set.headSet("california")) .containsExactly("a", "in", "the", "over", "quick", "jumped") .inOrder(); assertTrue(set.headSet("a").isEmpty()); assertTrue(set.headSet("").isEmpty()); }
public void testEmpty_headSet() { SortedSet<String> set = of(); assertSame(set, set.headSet("c")); }
public void testRowKeySetHeadSet() { sortedTable = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c'); Set<String> set = sortedTable.rowKeySet().headSet("cat"); assertEquals(Collections.singleton("bar"), set); set.clear(); assertTrue(set.isEmpty()); assertEquals(Collections.singleton("foo"), sortedTable.rowKeySet()); }
public void testSortedKeySet() { TreeMultimap<String, Integer> multimap = createPopulate(); SortedSet<String> keySet = multimap.keySet(); assertEquals(null, keySet.first()); assertEquals("google", keySet.last()); assertEquals(StringLength.COMPARATOR, keySet.comparator()); assertEquals(Sets.newHashSet(null, "tree"), keySet.headSet("yahoo")); assertEquals(Sets.newHashSet("google"), keySet.tailSet("yahoo")); assertEquals(Sets.newHashSet("tree"), keySet.subSet("ask", "yahoo")); }
public void testCopyOf_headSet() { SortedSet<String> set = of("e", "a", "f", "b", "d", "c"); SortedSet<String> headset = set.headSet("d"); SortedSet<String> copy = copyOf(headset); assertEquals(headset, copy); }
public void testElementSetSortedSetMethods() { TreeMultiset<String> ms = TreeMultiset.create(); ms.add("c", 1); ms.add("a", 3); ms.add("b", 2); SortedSet<String> elementSet = ms.elementSet(); assertEquals("a", elementSet.first()); assertEquals("c", elementSet.last()); assertEquals(Ordering.natural(), elementSet.comparator()); assertThat(elementSet.headSet("b")).containsExactly("a"); assertThat(elementSet.tailSet("b")).containsExactly("b", "c").inOrder(); assertThat(elementSet.subSet("a", "c")).containsExactly("a", "b").inOrder(); }