@Override public LinkedHashSet<T> drop(int n) { if (n <= 0) { return this; } else { return LinkedHashSet.ofAll(iterator().drop(n)); } }
@Override public HashSet<T> drop(int n) { if (n <= 0) { return this; } else { return HashSet.ofAll(iterator().drop(n)); } }
/** * Tests whether this list contains the given sequence at a given index. * <p> * Note: If the both the receiver object this and the argument that are infinite sequences this method may not terminate. * * @param that the sequence to test * @param offset the index where the sequence is searched. * @return true if that is empty or that is prefix of this collection starting from the given offset, false otherwise. */ default boolean startsWith(Iterable<? extends T> that, int offset) { Objects.requireNonNull(that, "that is null"); if (offset < 0) { return false; } final Iterator<T> i = this.iterator().drop(offset); final java.util.Iterator<? extends T> j = that.iterator(); while (i.hasNext() && j.hasNext()) { if (!Objects.equals(i.next(), j.next())) { return false; } } return !j.hasNext(); }
static <K, V, M extends Map<K, V>> M drop(M map, OfEntries<K, V, M> ofEntries, Supplier<M> emptySupplier, int n) { if (n <= 0) { return map; } else if (n >= map.size()) { return emptySupplier.get(); } else { return ofEntries.apply(map.iterator().drop(n)); } }
@Override public BitSet<T> drop(int n) { if (n <= 0 || isEmpty()) { return this; } else if (n >= length()) { return createEmpty(); } else { return createFromAll(iterator().drop(n)); } }
@Override public PriorityQueue<T> drop(int n) { if (n <= 0 || isEmpty()) { return this; } else if (n >= length()) { return empty(comparator); } else { return ofAll(comparator, iterator().drop(n)); } }
@Override @SuppressWarnings("unchecked") public M drop(int n) { if (n <= 0 || isEmpty()) { return (M) this; } else if (n >= length()) { return (M) this.emptyInstance(); } else { return (M) createFromEntries(iterator().drop(n)); } }
/** * Tests whether this sequence ends with the given sequence. * <p> * Note: If the both the receiver object this and the argument that are infinite sequences this method may not terminate. * * @param that the sequence to test * @return true if this sequence has that as a suffix, false otherwise. */ default boolean endsWith(Seq<? extends T> that) { Objects.requireNonNull(that, "that is null"); final Iterator<T> i = this.iterator().drop(length() - that.length()); final Iterator<? extends T> j = that.iterator(); while (i.hasNext() && j.hasNext()) { if (!Objects.equals(i.next(), j.next())) { return false; } } return !j.hasNext(); }
@Override public TreeSet<T> drop(int n) { if (n <= 0 || isEmpty()) { return this; } else if (n >= length()) { return empty(tree.comparator()); } else { return TreeSet.ofAll(tree.comparator(), iterator().drop(n)); } }
@Override public LinkedHashSet<T> drop(int n) { if (n <= 0) { return this; } else { return LinkedHashSet.ofAll(iterator().drop(n)); } }
@Override public HashSet<T> drop(int n) { if (n <= 0) { return this; } else { return HashSet.ofAll(iterator().drop(n)); } }
/** * Tests whether this list contains the given sequence at a given index. * <p> * Note: If the both the receiver object this and the argument that are infinite sequences this method may not terminate. * * @param that the sequence to test * @param offset the index where the sequence is searched. * @return true if that is empty or that is prefix of this collection starting from the given offset, false otherwise. */ default boolean startsWith(Iterable<? extends T> that, int offset) { Objects.requireNonNull(that, "that is null"); if (offset < 0) { return false; } final Iterator<T> i = this.iterator().drop(offset); final java.util.Iterator<? extends T> j = that.iterator(); while (i.hasNext() && j.hasNext()) { if (!Objects.equals(i.next(), j.next())) { return false; } } return !j.hasNext(); }
static <K, V, M extends Map<K, V>> M drop(M map, OfEntries<K, V, M> ofEntries, Supplier<M> emptySupplier, int n) { if (n <= 0) { return map; } else if (n >= map.size()) { return emptySupplier.get(); } else { return ofEntries.apply(map.iterator().drop(n)); } }
@Override public BitSet<T> drop(int n) { if (n <= 0 || isEmpty()) { return this; } else if (n >= length()) { return createEmpty(); } else { return createFromAll(iterator().drop(n)); } }
@Override @SuppressWarnings("unchecked") public M drop(int n) { if (n <= 0 || isEmpty()) { return (M) this; } else if (n >= length()) { return (M) this.emptyInstance(); } else { return (M) createFromEntries(iterator().drop(n)); } }
@Override public PriorityQueue<T> drop(int n) { if (n <= 0 || isEmpty()) { return this; } else if (n >= length()) { return empty(comparator); } else { return ofAll(comparator, iterator().drop(n)); } }
/** * Tests whether this sequence ends with the given sequence. * <p> * Note: If the both the receiver object this and the argument that are infinite sequences this method may not terminate. * * @param that the sequence to test * @return true if this sequence has that as a suffix, false otherwise. */ default boolean endsWith(Seq<? extends T> that) { Objects.requireNonNull(that, "that is null"); final Iterator<T> i = this.iterator().drop(length() - that.length()); final Iterator<? extends T> j = that.iterator(); while (i.hasNext() && j.hasNext()) { if (!Objects.equals(i.next(), j.next())) { return false; } } return !j.hasNext(); }
@Override public TreeSet<T> drop(int n) { if (n <= 0 || isEmpty()) { return this; } else if (n >= length()) { return empty(tree.comparator()); } else { return TreeSet.ofAll(tree.comparator(), iterator().drop(n)); } }