@Override public SortedSet<E> tailSet(E fromElement) { synchronized (mutex) { return sortedSet(delegate().tailSet(fromElement), mutex); } }
/** 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> tailSet(E fromElement) { return delegate().tailSet(fromElement); }
@Override public SortedSet<E> tailSet(E fromElement) { return new FilteredSortedSet<E>(((SortedSet<E>) unfiltered).tailSet(fromElement), predicate); }
@Override public SortedSet<E> tailSet(E fromElement) { synchronized (mutex) { return sortedSet(delegate().tailSet(fromElement), mutex); } }
@Override public SortedSet<E> tailSet(E fromElement) { return new FilteredSortedSet<E>(((SortedSet<E>) unfiltered).tailSet(fromElement), predicate); }
@Override public SortedSet<E> tailSet(E fromElement) { return delegate().tailSet(fromElement); }
@Override public SortedMap<K, V> tailMap(K fromKey) { return asMap(backingSet().tailSet(fromKey), function); }
/** * A sensible definition of {@link #contains} in terms of the {@code first()} method of {@link * #tailSet}. If you override {@link #tailSet}, you may wish to override {@link #contains} to * forward to this implementation. * * @since 7.0 */ @Override @Beta protected boolean standardContains(@Nullable Object object) { try { // any ClassCastExceptions are caught @SuppressWarnings("unchecked") SortedSet<Object> self = (SortedSet<Object>) this; Object ceiling = self.tailSet(object).first(); return unsafeCompare(ceiling, object) == 0; } catch (ClassCastException | NoSuchElementException | NullPointerException e) { return false; } }
/** * A sensible definition of {@link #remove} in terms of the {@code iterator()} method of {@link * #tailSet}. If you override {@link #tailSet}, you may wish to override {@link #remove} to * forward to this implementation. * * @since 7.0 */ @Override @Beta protected boolean standardRemove(@Nullable Object object) { try { // any ClassCastExceptions are caught @SuppressWarnings("unchecked") SortedSet<Object> self = (SortedSet<Object>) this; Iterator<Object> iterator = self.tailSet(object).iterator(); if (iterator.hasNext()) { Object ceiling = iterator.next(); if (unsafeCompare(ceiling, object) == 0) { iterator.remove(); return true; } } } catch (ClassCastException | NullPointerException e) { return false; } return false; }
@Override public SortedMap<K, V> tailMap(K fromKey) { return asMap(backingSet().tailSet(fromKey), function); }
public void testOf_tailSet() { SortedSet<String> set = of("e", "f", "b", "d", "c"); assertTrue(set.tailSet("e") instanceof ImmutableSortedSet); assertThat(set.tailSet("e")).containsExactly("e", "f").inOrder(); assertThat(set.tailSet("a")).containsExactly("b", "c", "d", "e", "f").inOrder(); assertSame(of(), set.tailSet("g")); }
public void testExplicit_tailSet() { SortedSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH) .add("in", "the", "quick", "jumped", "over", "a") .build(); assertTrue(set.tailSet("california") instanceof ImmutableSortedSet); assertTrue(set.tailSet("fish") instanceof ImmutableSortedSet); assertThat(set.tailSet("fish")).containsExactly("over", "quick", "jumped").inOrder(); assertThat(set.tailSet("a")) .containsExactly("a", "in", "the", "over", "quick", "jumped") .inOrder(); assertTrue(set.tailSet("california").isEmpty()); }
public void testEmpty_tailSet() { SortedSet<String> set = of(); assertSame(set, set.tailSet("f")); }
public void testRowKeySetTailSet() { sortedTable = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c'); Set<String> set = sortedTable.rowKeySet().tailSet("cat"); assertEquals(Collections.singleton("foo"), set); set.clear(); assertTrue(set.isEmpty()); assertEquals(Collections.singleton("bar"), 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_tailSet() { SortedSet<String> set = of("e", "a", "f", "b", "d", "c"); SortedSet<String> tailset = set.tailSet("d"); SortedSet<String> copy = copyOf(tailset); assertEquals(tailset, 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(); }