javaslang.collection.SortedSet Maven / Gradle / Ivy
Show all versions of javaslang Show documentation
/* / \____ _ _ ____ ______ / \ ____ __ _______
* / / \/ \ / \/ \ / /\__\/ // \/ \ // /\__\ JΛVΛSLΛNG
* _/ / /\ \ \/ / /\ \\__\\ \ // /\ \ /\\/ \ /__\ \ Copyright 2014-2016 Javaslang, http://javaslang.io
* /___/\_/ \_/\____/\_/ \_/\__\/__/\__\_/ \_// \__/\_____/ Licensed under the Apache License, Version 2.0
*/
package javaslang.collection;
import javaslang.Tuple2;
import javaslang.Tuple3;
import javaslang.control.Option;
import java.util.Comparator;
import java.util.NoSuchElementException;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
/**
* An immutable {@code SortedSet} interface.
*
*
* Specific SortedSet operations:
*
*
* - {@link #comparator()}
* - {@link #flatMap(Comparator, Function)}
* - {@link #map(Comparator, Function)}
*
*
* @param Component type
* @author Daniel Dietrich
* @since 2.0.0
*/
public interface SortedSet extends Set {
long serialVersionUID = 1L;
/**
* Narrows a widened {@code SortedSet extends T>} to {@code SortedSet}
* by performing a type safe-cast. This is eligible because immutable/read-only
* collections are covariant.
*
* CAUTION: The underlying {@code Comparator} might fail!
*
* @param sortedSet A {@code SortedSet}.
* @param Component type of the {@code SortedSet}.
* @return the given {@code sortedSet} instance as narrowed type {@code SortedSet}.
*/
@SuppressWarnings("unchecked")
static SortedSet narrow(SortedSet extends T> sortedSet) {
return (SortedSet) sortedSet;
}
/**
* Returns the underlying comparator which defines the order of the elements contained in this set.
*
* @return This set's comparator.
*/
Comparator comparator();
/**
* Same as {@link #flatMap(Function)} but using a specific comparator for values of the codomain of the given
* {@code mapper}.
*
* @param comparator A comparator for values of type U
* @param mapper A function which maps values of type T to Iterables of values of type U
* @param Type of flat-mapped values
* @return A new Set instance containing mapped values
*/
SortedSet flatMap(Comparator super U> comparator, Function super T, ? extends Iterable extends U>> mapper);
/**
* Same as {@link #map(Function)} but using a specific comparator for values of the codomain of the given
* {@code mapper}.
*
* @param comparator A comparator for values of type U
* @param mapper A function which maps values of type T to values of type U
* @param Type of mapped values
* @return A new Set instance containing mapped values
*/
SortedSet map(Comparator super U> comparator, Function super T, ? extends U> mapper);
// -- Adjusted return types of Set methods
@Override
SortedSet add(T element);
@Override
SortedSet addAll(Iterable extends T> elements);
@Override
SortedSet diff(Set extends T> elements);
@Override
SortedSet distinct();
@Override
SortedSet distinctBy(Comparator super T> comparator);
@Override
SortedSet distinctBy(Function super T, ? extends U> keyExtractor);
@Override
SortedSet drop(long n);
@Override
SortedSet dropRight(long n);
@Override
SortedSet dropUntil(Predicate super T> predicate);
@Override
SortedSet dropWhile(Predicate super T> predicate);
@Override
SortedSet filter(Predicate super T> predicate);
@Override
SortedSet flatMap(Function super T, ? extends Iterable extends U>> mapper);
@Override
Map> groupBy(Function super T, ? extends C> classifier);
@Override
Iterator extends SortedSet> grouped(long size);
@Override
SortedSet init();
@Override
Option extends SortedSet> initOption();
@Override
SortedSet intersect(Set extends T> elements);
@Override
default T last() {
return max().getOrElseThrow(() -> new NoSuchElementException("last on empty SortedSet"));
}
@Override
SortedSet map(Function super T, ? extends U> mapper);
@Override
Tuple2 extends SortedSet, ? extends SortedSet> partition(Predicate super T> predicate);
@Override
SortedSet peek(Consumer super T> action);
@Override
SortedSet remove(T element);
@Override
SortedSet removeAll(Iterable extends T> elements);
@Override
SortedSet replace(T currentElement, T newElement);
@Override
SortedSet replaceAll(T currentElement, T newElement);
@Override
SortedSet retainAll(Iterable extends T> elements);
@Override
SortedSet scan(T zero, BiFunction super T, ? super T, ? extends T> operation);
// DEV-NOTE: The return type is either Set or SortedSet, depending whether U is Comparable
@Override
Set scanLeft(U zero, BiFunction super U, ? super T, ? extends U> operation);
// DEV-NOTE: The return type is either Set or SortedSet, depending whether U is Comparable
@Override
Set scanRight(U zero, BiFunction super T, ? super U, ? extends U> operation);
@Override
Iterator extends SortedSet> sliding(long size);
@Override
Iterator extends SortedSet> sliding(long size, long step);
@Override
Tuple2 extends SortedSet, ? extends SortedSet> span(Predicate super T> predicate);
@Override
SortedSet tail();
@Override
Option extends SortedSet> tailOption();
@Override
SortedSet take(long n);
@Override
SortedSet takeRight(long n);
@Override
SortedSet takeUntil(Predicate super T> predicate);
@Override
SortedSet takeWhile(Predicate super T> predicate);
@Override
java.util.SortedSet toJavaSet();
@Override
SortedSet union(Set extends T> elements);
@Override
Tuple2 extends SortedSet, ? extends SortedSet> unzip(Function super T, Tuple2 extends T1, ? extends T2>> unzipper);
@Override
Tuple3 extends SortedSet, ? extends SortedSet, ? extends SortedSet> unzip3(Function super T, Tuple3 extends T1, ? extends T2, ? extends T3>> unzipper);
@Override
SortedSet> zip(Iterable extends U> that);
@Override
SortedSet> zipAll(Iterable extends U> that, T thisElem, U thatElem);
@Override
SortedSet> zipWithIndex();
}