/** * Creates a TreeSet from int values. * * @param elements int values * @return A new TreeSet of Integer values * @throws NullPointerException if elements is null */ public static TreeSet<Integer> ofAll(int... elements) { Objects.requireNonNull(elements, "elements is null"); return TreeSet.ofAll(Iterator.ofAll(elements)); }
/** * Creates a TreeSet from long values. * * @param elements long values * @return A new TreeSet of Long values * @throws NullPointerException if elements is null */ public static TreeSet<Long> ofAll(long... elements) { Objects.requireNonNull(elements, "elements is null"); return TreeSet.ofAll(Iterator.ofAll(elements)); }
/** * Creates a TreeSet from double values. * * @param elements double values * @return A new TreeSet of Double values * @throws NullPointerException if elements is null */ public static TreeSet<Double> ofAll(double... elements) { Objects.requireNonNull(elements, "elements is null"); return TreeSet.ofAll(Iterator.ofAll(elements)); }
/** * Creates a TreeSet from byte values. * * @param elements byte values * @return A new TreeSet of Byte values * @throws NullPointerException if elements is null */ public static TreeSet<Byte> ofAll(byte... elements) { Objects.requireNonNull(elements, "elements is null"); return TreeSet.ofAll(Iterator.ofAll(elements)); }
/** * Creates a TreeSet from char values. * * @param elements char values * @return A new TreeSet of Character values * @throws NullPointerException if elements is null */ public static TreeSet<Character> ofAll(char... elements) { Objects.requireNonNull(elements, "elements is null"); return TreeSet.ofAll(Iterator.ofAll(elements)); }
/** * Returns this {@code TreeSet} if it is nonempty, * otherwise {@code TreeSet} created from result of evaluating supplier, using existing comparator. * * @param supplier An alternative {@code Traversable} * @return this {@code TreeSet} if it is nonempty, * otherwise {@code TreeSet} created from result of evaluating supplier, using existing comparator. */ @Override public TreeSet<T> orElse(Supplier<? extends Iterable<? extends T>> supplier) { return isEmpty() ? ofAll(tree.comparator(), supplier.get()) : this; }
@Override default <U> SortedSet<U> map(Comparator<? super U> comparator, Function<? super T, ? extends U> mapper) { Objects.requireNonNull(mapper, "mapper is null"); return TreeSet.ofAll(comparator, iterator().map(mapper)); }
@Override public <T1, T2, T3> Tuple3<TreeSet<T1>, TreeSet<T2>, TreeSet<T3>> unzip3( Function<? super T, Tuple3<? extends T1, ? extends T2, ? extends T3>> unzipper) { Objects.requireNonNull(unzipper, "unzipper is null"); return iterator().unzip3(unzipper).map( i1 -> TreeSet.ofAll(Comparators.naturalComparator(), i1), i2 -> TreeSet.ofAll(Comparators.naturalComparator(), i2), i3 -> TreeSet.ofAll(Comparators.naturalComparator(), i3)); }
@Override default <U, R> TreeSet<R> zipWith(Iterable<? extends U> that, BiFunction<? super T, ? super U, ? extends R> mapper) { Objects.requireNonNull(that, "that is null"); Objects.requireNonNull(mapper, "mapper is null"); return TreeSet.ofAll(Comparators.naturalComparator(), iterator().zipWith(that, mapper)); }
@Override public <U, R> TreeSet<R> zipWith(Iterable<? extends U> that, BiFunction<? super T, ? super U, ? extends R> mapper) { Objects.requireNonNull(that, "that is null"); Objects.requireNonNull(mapper, "mapper is null"); return TreeSet.ofAll(Comparators.naturalComparator(), iterator().zipWith(that, mapper)); }
@Override default <T1, T2> Tuple2<TreeSet<T1>, TreeSet<T2>> unzip( Function<? super T, Tuple2<? extends T1, ? extends T2>> unzipper) { Objects.requireNonNull(unzipper, "unzipper is null"); return iterator().unzip(unzipper).map(i1 -> TreeSet.ofAll(Comparators.naturalComparator(), i1), i2 -> TreeSet.ofAll(Comparators.naturalComparator(), i2)); }
@Override default <R> SortedSet<R> collect(PartialFunction<? super T, ? extends R> partialFunction) { Objects.requireNonNull(partialFunction, "partialFunction is null"); return TreeSet.ofAll(Comparators.naturalComparator(), iterator().collect(partialFunction)); }
@Override default TreeSet<Tuple2<T, Integer>> zipWithIndex() { final Comparator<? super T> component1Comparator = comparator(); final Comparator<Tuple2<T, Integer>> tuple2Comparator = (t1, t2) -> component1Comparator.compare(t1._1, t2._1); return TreeSet.ofAll(tuple2Comparator, iterator().zipWithIndex()); }
@Override default <U> TreeSet<U> zipWithIndex(BiFunction<? super T, ? super Integer, ? extends U> mapper) { Objects.requireNonNull(mapper, "mapper is null"); return TreeSet.ofAll(Comparators.naturalComparator(), iterator().zipWithIndex(mapper)); } }
@Override public <U> Set<U> scanLeft(U zero, BiFunction<? super U, ? super T, ? extends U> operation) { if (zero instanceof Comparable) { final Comparator<U> comparator = Comparators.naturalComparator(); return Collections.scanLeft(this, zero, operation, iter -> TreeSet.ofAll(comparator, iter)); } else { return Collections.scanLeft(this, zero, operation, HashSet::ofAll); } }
@Override public TreeSet<T> distinctBy(Comparator<? super T> comparator) { Objects.requireNonNull(comparator, "comparator is null"); return isEmpty() ? this : TreeSet.ofAll(tree.comparator(), iterator().distinctBy(comparator)); }
@Override default <U> TreeSet<Tuple2<T, U>> zipAll(Iterable<? extends U> that, T thisElem, U thatElem) { Objects.requireNonNull(that, "that is null"); final Comparator<Tuple2<T, U>> tuple2Comparator = Tuple2.comparator(comparator(), Comparators.naturalComparator()); return TreeSet.ofAll(tuple2Comparator, iterator().zipAll(that, thisElem, thatElem)); }
@Override default <U> TreeSet<Tuple2<T, U>> zip(Iterable<? extends U> that) { Objects.requireNonNull(that, "that is null"); final Comparator<Tuple2<T, U>> tuple2Comparator = Tuple2.comparator(comparator(), Comparators.naturalComparator()); return TreeSet.ofAll(tuple2Comparator, iterator().zip(that)); }
@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)); } }