All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javaslang.collection.SortedSet Maven / Gradle / Ivy

There is a newer version: 2.1.0-alpha
Show newest version
/*     / \____  _    _  ____   ______  / \ ____  __    _______
 *    /  /    \/ \  / \/    \ /  /\__\/  //    \/  \  //  /\__\   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} 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 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 comparator, Function> 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 comparator, Function mapper); // -- Adjusted return types of Set methods @Override SortedSet add(T element); @Override SortedSet addAll(Iterable elements); @Override SortedSet diff(Set elements); @Override SortedSet distinct(); @Override SortedSet distinctBy(Comparator comparator); @Override SortedSet distinctBy(Function keyExtractor); @Override SortedSet drop(long n); @Override SortedSet dropRight(long n); @Override SortedSet dropUntil(Predicate predicate); @Override SortedSet dropWhile(Predicate predicate); @Override SortedSet filter(Predicate predicate); @Override SortedSet flatMap(Function> mapper); @Override Map> groupBy(Function classifier); @Override Iterator> grouped(long size); @Override SortedSet init(); @Override Option> initOption(); @Override SortedSet intersect(Set elements); @Override default T last() { return max().getOrElseThrow(() -> new NoSuchElementException("last on empty SortedSet")); } @Override SortedSet map(Function mapper); @Override Tuple2, ? extends SortedSet> partition(Predicate predicate); @Override SortedSet peek(Consumer action); @Override SortedSet remove(T element); @Override SortedSet removeAll(Iterable elements); @Override SortedSet replace(T currentElement, T newElement); @Override SortedSet replaceAll(T currentElement, T newElement); @Override SortedSet retainAll(Iterable elements); @Override SortedSet scan(T zero, BiFunction operation); // DEV-NOTE: The return type is either Set or SortedSet, depending whether U is Comparable @Override Set scanLeft(U zero, BiFunction operation); // DEV-NOTE: The return type is either Set or SortedSet, depending whether U is Comparable @Override Set scanRight(U zero, BiFunction operation); @Override Iterator> sliding(long size); @Override Iterator> sliding(long size, long step); @Override Tuple2, ? extends SortedSet> span(Predicate predicate); @Override SortedSet tail(); @Override Option> tailOption(); @Override SortedSet take(long n); @Override SortedSet takeRight(long n); @Override SortedSet takeUntil(Predicate predicate); @Override SortedSet takeWhile(Predicate predicate); @Override java.util.SortedSet toJavaSet(); @Override SortedSet union(Set elements); @Override Tuple2, ? extends SortedSet> unzip(Function> unzipper); @Override Tuple3, ? extends SortedSet, ? extends SortedSet> unzip3(Function> unzipper); @Override SortedSet> zip(Iterable that); @Override SortedSet> zipAll(Iterable that, T thisElem, U thatElem); @Override SortedSet> zipWithIndex(); }