io.vavr.collection.SortedMap Maven / Gradle / Ivy
Show all versions of vavr Show documentation
/* __ __ __ __ __ ___
* \ \ / / \ \ / / __/
* \ \/ / /\ \ \/ / /
* \____/__/ \__\____/__/.ɪᴏ
* ᶜᵒᵖʸʳᶦᵍʰᵗ ᵇʸ ᵛᵃᵛʳ ⁻ ˡᶦᶜᵉⁿˢᵉᵈ ᵘⁿᵈᵉʳ ᵗʰᵉ ᵃᵖᵃᶜʰᵉ ˡᶦᶜᵉⁿˢᵉ ᵛᵉʳˢᶦᵒⁿ ᵗʷᵒ ᵈᵒᵗ ᶻᵉʳᵒ
*/
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 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);
/**
* 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
Tuple2> computeIfAbsent(K key, Function super K, ? extends V> mappingFunction);
@Override
Tuple2