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

io.vavr.collection.SortedMap Maven / Gradle / Ivy

There is a newer version: 1.0.0-alpha-4
Show newest version
/*                        __    __  __  __    __  ___
 *                       \  \  /  /    \  \  /  /  __/
 *                        \  \/  /  /\  \  \/  /  /
 *                         \____/__/  \__\____/__/.ɪᴏ
 * ᶜᵒᵖʸʳᶦᵍʰᵗ ᵇʸ ᵛᵃᵛʳ ⁻ ˡᶦᶜᵉⁿˢᵉᵈ ᵘⁿᵈᵉʳ ᵗʰᵉ ᵃᵖᵃᶜʰᵉ ˡᶦᶜᵉⁿˢᵉ ᵛᵉʳˢᶦᵒⁿ ᵗʷᵒ ᵈᵒᵗ ᶻᵉʳᵒ
 */
package io.vavr.collection;

import io.vavr.Tuple2;
import io.vavr.control.Option;

import java.util.Comparator;
import java.util.NoSuchElementException;
import java.util.function.*;

/**
 * An immutable {@code SortedMap} interface.
 *
 * @param  Key type
 * @param  Value type
 * @author Daniel Dietrich
 */
public interface SortedMap extends Map, Ordered {

    long serialVersionUID = 1L;

    /**
     * Narrows a widened {@code SortedMap} to {@code SortedMap}
     * by performing a type-safe cast. This is eligible because immutable/read-only
     * collections are covariant.
     * 

* CAUTION: If {@code K} is narrowed, the underlying {@code Comparator} might fail! * * @param sortedMap A {@code SortedMap}. * @param Key type * @param Value type * @return the given {@code sortedMap} instance as narrowed type {@code SortedMap}. */ @SuppressWarnings("unchecked") static SortedMap narrow(SortedMap sortedMap) { return (SortedMap) sortedMap; } /** * Same as {@link #bimap(Function, Function)}, using a specific comparator for keys of the codomain of the given * {@code keyMapper}. * * @param key's component type of the map result * @param value's component type of the map result * @param keyComparator A comparator for keys of type K2 * @param keyMapper a {@code Function} that maps the keys of type {@code K} to keys of type {@code K2} * @param valueMapper a {@code Function} that the values of type {@code V} to values of type {@code V2} * @return a new {@code SortedMap} * @throws NullPointerException if {@code keyMapper} or {@code valueMapper} is null */ SortedMap bimap(Comparator keyComparator, Function keyMapper, Function valueMapper); /** * Same as {@link #flatMap(BiFunction)} but using a specific comparator for values of the codomain of the given * {@code mapper}. * * @param keyComparator A comparator for keys of type U * @param mapper A function which maps key/value pairs to Iterables map entries * @param New key type * @param New value type * @return A new Map instance containing mapped entries */ SortedMap flatMap(Comparator keyComparator, BiFunction>> mapper); /** * Same as {@link #map(BiFunction)}, using a specific comparator for keys of the codomain of the given * {@code mapper}. * * @param keyComparator A comparator for keys of type U * @param key's component type of the map result * @param value's component type of the map result * @param mapper a {@code Function} that maps entries of type {@code (K, V)} to entries of type {@code (K2, V2)} * @return a new {@code SortedMap} * @throws NullPointerException if {@code mapper} is null */ SortedMap map(Comparator keyComparator, BiFunction> mapper); // -- Adjusted return types of Map methods @Override SortedMap bimap(Function keyMapper, Function valueMapper); @Override Tuple2> computeIfAbsent(K key, Function mappingFunction); @Override Tuple2, ? extends SortedMap> computeIfPresent(K key, BiFunction remappingFunction); @Override SortedMap distinct(); @Override SortedMap distinctBy(Comparator> comparator); @Override SortedMap distinctBy(Function, ? extends U> keyExtractor); @Override SortedMap drop(int n); @Override SortedMap dropRight(int n); @Override SortedMap dropUntil(Predicate> predicate); @Override SortedMap dropWhile(Predicate> predicate); @Override SortedMap filter(Predicate> predicate); @Override SortedMap filter(BiPredicate predicate); @Override SortedMap filterKeys(Predicate predicate); @Override SortedMap filterValues(Predicate predicate); @Override SortedMap removeAll(BiPredicate predicate); @Override SortedMap removeKeys(Predicate predicate); @Override SortedMap removeValues(Predicate predicate); @Override SortedMap flatMap(BiFunction>> mapper); @Override Map> groupBy(Function, ? extends C> classifier); @Override Iterator> grouped(int size); @Override SortedMap init(); @Override Option> initOption(); @Override default boolean isOrdered() { return true; } @Override SortedSet keySet(); @Override default Tuple2 last() { return max().getOrElseThrow(() -> new NoSuchElementException("last on empty SortedMap")); } @Override SortedMap map(BiFunction> mapper); @Override SortedMap mapKeys(Function keyMapper); @Override SortedMap mapKeys(Function keyMapper, BiFunction valueMerge); @Override SortedMap mapValues(Function valueMapper); @Override SortedMap merge(Map that); @Override SortedMap merge(Map that, BiFunction collisionResolution); @Override SortedMap orElse(Iterable> other); @Override SortedMap orElse(Supplier>> supplier); @Override Tuple2, ? extends SortedMap> partition(Predicate> predicate); @Override SortedMap peek(Consumer> action); @Override SortedMap put(K key, V value); @Override SortedMap put(Tuple2 entry); @Override SortedMap remove(K key); @Override SortedMap removeAll(Iterable keys); @Override SortedMap replace(Tuple2 currentElement, Tuple2 newElement); @Override SortedMap replaceAll(Tuple2 currentElement, Tuple2 newElement); @Override SortedMap retainAll(Iterable> elements); @Override SortedMap scan(Tuple2 zero, BiFunction, ? super Tuple2, ? extends Tuple2> operation); @Override Iterator> slideBy(Function, ?> classifier); @Override Iterator> sliding(int size); @Override Iterator> sliding(int size, int step); @Override Tuple2, ? extends SortedMap> span(Predicate> predicate); @Override SortedMap tail(); @Override Option> tailOption(); @Override SortedMap take(int n); @Override SortedMap takeRight(int n); @Override SortedMap takeUntil(Predicate> predicate); @Override SortedMap takeWhile(Predicate> predicate); @Override java.util.SortedMap toJavaMap(); }