/** * Alias for {@link TreeSet#empty(Comparator)} * * @param <T> Component type of element. * @param comparator The comparator used to sort the elements * @return A new {@link TreeSet} empty instance */ public static <T extends Comparable<? super T>> SortedSet<T> SortedSet(Comparator<? super T> comparator) { return TreeSet.empty(comparator); }
/** * Alias for {@link TreeSet#empty()} * * @param <T> Component type of element. * @return A new {@link TreeSet} empty instance */ public static <T extends Comparable<? super T>> SortedSet<T> SortedSet() { return TreeSet.empty(); }
public static <V> Builder<V> withSortedSet(Comparator<? super V> comparator) { return new Builder<>(ContainerType.SORTED_SET, () -> TreeSet.empty(comparator)); }
public static <V> Builder<V> withSortedSet(Comparator<? super V> comparator) { return new Builder<>(ContainerType.SORTED_SET, () -> TreeSet.empty(comparator)); }
public static <V> Builder<V> withSortedSet(Comparator<? super V> comparator) { return new Builder<>(ContainerType.SORTED_SET, () -> TreeSet.empty(comparator)); }
public static <T extends Comparable<? super T>> TreeSet<T> empty() { return empty(Comparators.naturalComparator()); }
@SuppressWarnings("unchecked") public static <T> TreeSet<T> ofAll(Comparator<? super T> comparator, Iterable<? extends T> values) { Objects.requireNonNull(comparator, "comparator is null"); Objects.requireNonNull(values, "values is null"); if (values instanceof TreeSet && ((TreeSet<?>) values).comparator() == comparator) { return (TreeSet<T>) values; } else { return values.iterator().hasNext() ? new TreeSet<>(RedBlackTree.ofAll(comparator, values)) : empty(comparator); } }
/** * Returns a TreeSet containing tuples returned by {@code n} calls to a given Supplier {@code s}. * * @param <T> Component type of the TreeSet * @param comparator The comparator used to sort the elements * @param n The number of elements in the TreeSet * @param s The Supplier computing element values * @return A TreeSet of size {@code n}, where each element contains the result supplied by {@code s}. * @throws NullPointerException if {@code comparator} or {@code s} are null */ public static <T> TreeSet<T> fill(Comparator<? super T> comparator, int n, Supplier<? extends T> s) { Objects.requireNonNull(comparator, "comparator is null"); Objects.requireNonNull(s, "s is null"); return Collections.fill(n, s, TreeSet.empty(comparator), values -> of(comparator, values)); }
/** * Returns a TreeSet containing {@code n} values of a given Function {@code f} * over a range of integer values from 0 to {@code n - 1}. * * @param <T> Component type of the TreeSet * @param comparator The comparator used to sort the elements * @param n The number of elements in the TreeSet * @param f The Function computing element values * @return A TreeSet consisting of elements {@code f(0),f(1), ..., f(n - 1)} * @throws NullPointerException if {@code comparator} or {@code f} are null */ public static <T> TreeSet<T> tabulate(Comparator<? super T> comparator, int n, Function<? super Integer, ? extends T> f) { Objects.requireNonNull(comparator, "comparator is null"); Objects.requireNonNull(f, "f is null"); return Collections.tabulate(n, f, TreeSet.empty(comparator), values -> of(comparator, values)); }
@Override default Iterator<T> distinctBy(Comparator<? super T> comparator) { Objects.requireNonNull(comparator, "comparator is null"); if (!hasNext()) { return empty(); } else { return new DistinctIterator<>(this, TreeSet.empty(comparator), Function.identity()); } }
/** * Converts this to a {@link SortedSet}. * * @param comparator A comparator that induces an order of the SortedSet elements. * @return A new {@link TreeSet}. */ default SortedSet<T> toSortedSet(Comparator<? super T> comparator) { Objects.requireNonNull(comparator, "comparator is null"); return ValueModule.toTraversable(this, TreeSet.empty(comparator), value -> TreeSet.of(comparator, value), values -> TreeSet.ofAll(comparator, values)); }
@Override public TreeSet<T> take(int n) { if (n <= 0) { return empty(tree.comparator()); } else if (n >= length()) { return this; } else { return TreeSet.ofAll(tree.comparator(), iterator().take(n)); } }
@Override public TreeSet<T> takeRight(int n) { if (n <= 0) { return empty(tree.comparator()); } else if (n >= length()) { return this; } else { return TreeSet.ofAll(tree.comparator(), iterator().takeRight(n)); } }
@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 TreeSet<T> dropRight(int n) { if (n <= 0 || isEmpty()) { return this; } else if (n >= length()) { return empty(tree.comparator()); } else { return TreeSet.ofAll(tree.comparator(), iterator().dropRight(n)); } }
/** * Alias for {@link TreeSet#empty(Comparator)} * * @param <T> Component type of element. * @param comparator The comparator used to sort the elements * @return A new {@link TreeSet} empty instance */ public static <T extends Comparable<? super T>> SortedSet<T> SortedSet(Comparator<? super T> comparator) { return TreeSet.empty(comparator); }
/** * Alias for {@link TreeSet#empty()} * * @param <T> Component type of element. * @return A new {@link TreeSet} empty instance */ public static <T extends Comparable<? super T>> SortedSet<T> SortedSet() { return TreeSet.empty(); }
@SuppressWarnings("unchecked") public static <T> TreeSet<T> ofAll(Comparator<? super T> comparator, Iterable<? extends T> values) { Objects.requireNonNull(comparator, "comparator is null"); Objects.requireNonNull(values, "values is null"); if (values instanceof TreeSet && ((TreeSet<?>) values).comparator() == comparator) { return (TreeSet<T>) values; } else { return values.iterator().hasNext() ? new TreeSet<>(RedBlackTree.ofAll(comparator, values)) : empty(comparator); } }
@Override default Iterator<T> distinctBy(Comparator<? super T> comparator) { Objects.requireNonNull(comparator, "comparator is null"); if (!hasNext()) { return empty(); } else { return new DistinctIterator<>(this, TreeSet.empty(comparator), Function.identity()); } }
@Override public TreeSet<T> dropRight(int n) { if (n <= 0 || isEmpty()) { return this; } else if (n >= length()) { return empty(tree.comparator()); } else { return TreeSet.ofAll(tree.comparator(), iterator().dropRight(n)); } }