javaslang.collection.SortedMap Maven / Gradle / Ivy
/* / \____ _ _ ____ ______ / \ ____ __ _______
* / / \/ \ / \/ \ / /\__\/ // \/ \ // /\__\ JΛVΛSLΛNG
* _/ / /\ \ \/ / /\ \\__\\ \ // /\ \ /\\/ \ /__\ \ Copyright 2014-2016 Javaslang, http://javaslang.io
* /___/\_/ \_/\____/\_/ \_/\__\/__/\__\_/ \_// \__/\_____/ Licensed under the Apache License, Version 2.0
*/
package javaslang.collection;
import javaslang.API;
import javaslang.Tuple2;
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 SortedMap} interface.
*
* @param Key type
* @param Value type
* @author Daniel Dietrich
* @since 2.0.0
*/
public interface SortedMap extends Map {
long serialVersionUID = 1L;
/**
* Narrows a widened {@code SortedMap extends K, ? extends V>} 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 extends K, ? extends V> 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 super K2> keyComparator,
Function super K, ? extends K2> keyMapper, Function super V, ? extends V2> 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 super K2> keyComparator, BiFunction super K, ? super V, ? extends Iterable>> mapper);
/**
* Returns the underlying key-comparator which defines the order of the elements contained in this map.
*
* @return This map's key-comparator.
*/
Comparator keyComparator();
/**
* 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 super K2> keyComparator, BiFunction super K, ? super V, Tuple2> mapper);
// -- Adjusted return types of Map methods
@Override
SortedMap bimap(Function super K, ? extends K2> keyMapper, Function super V, ? extends V2> valueMapper);
@Override
SortedMap distinct();
@Override
SortedMap distinctBy(Comparator super Tuple2> comparator);
@Override
SortedMap distinctBy(Function super Tuple2, ? extends U> keyExtractor);
@Override
SortedMap drop(long n);
@Override
SortedMap dropRight(long n);
@Override
SortedMap dropUntil(Predicate super Tuple2> predicate);
@Override
SortedMap dropWhile(Predicate super Tuple2> predicate);
@Override
SortedMap filter(Predicate super Tuple2> predicate);
@Override
SortedMap flatMap(BiFunction super K, ? super V, ? extends Iterable>> mapper);
@Override
Map> groupBy(Function super Tuple2, ? extends C> classifier);
@Override
Iterator extends SortedMap> grouped(long size);
@Override
SortedMap init();
@Override
Option extends SortedMap> initOption();
@Override
SortedSet keySet();
@Override
default Tuple2 last() {
return max().getOrElseThrow(() -> new NoSuchElementException("last on empty SortedMap"));
}
@Override
SortedMap map(BiFunction super K, ? super V, Tuple2> mapper);
@Override
SortedMap mapValues(Function super V, ? extends V2> valueMapper);
@Override
SortedMap merge(Map extends K, ? extends V> that);
@Override
SortedMap merge(Map extends K, U> that, BiFunction super V, ? super U, ? extends V> collisionResolution);
@Override
Tuple2 extends SortedMap, ? extends SortedMap> partition(Predicate super Tuple2> predicate);
@Override
SortedMap peek(Consumer super Tuple2> action);
@Override
SortedMap put(K key, V value);
@Override
SortedMap put(Tuple2 extends K, ? extends V> entry);
@Override
SortedMap remove(K key);
@Override
SortedMap removeAll(Iterable extends K> keys);
@Override
SortedMap replace(Tuple2 currentElement, Tuple2 newElement);
@Override
SortedMap replaceAll(Tuple2 currentElement, Tuple2 newElement);
@Override
SortedMap retainAll(Iterable extends Tuple2> elements);
@Override
SortedMap scan(Tuple2 zero, BiFunction super Tuple2, ? super Tuple2, ? extends Tuple2> operation);
@Override
Iterator extends SortedMap> sliding(long size);
@Override
Iterator extends SortedMap> sliding(long size, long step);
@Override
Tuple2 extends SortedMap, ? extends SortedMap> span(Predicate super Tuple2> predicate);
@Override
SortedMap tail();
@Override
Option extends SortedMap> tailOption();
@Override
SortedMap take(long n);
@Override
SortedMap takeRight(long n);
@Override
SortedMap takeUntil(Predicate super Tuple2> predicate);
@Override
SortedMap takeWhile(Predicate super Tuple2> predicate);
@Override
java.util.SortedMap toJavaMap();
}