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

javaslang.collection.SortedMap Maven / Gradle / Ivy

There is a newer version: 8.1.2
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.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} 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); /** * 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 keyComparator, BiFunction> mapper); // -- Adjusted return types of Map methods @Override SortedMap bimap(Function keyMapper, Function valueMapper); @Override SortedMap distinct(); @Override SortedMap distinctBy(Comparator> comparator); @Override SortedMap distinctBy(Function, ? extends U> keyExtractor); @Override SortedMap drop(long n); @Override SortedMap dropRight(long n); @Override SortedMap dropUntil(Predicate> predicate); @Override SortedMap dropWhile(Predicate> predicate); @Override SortedMap filter(Predicate> predicate); @Override SortedMap flatMap(BiFunction>> mapper); @Override Map> groupBy(Function, ? extends C> classifier); @Override Iterator> grouped(long size); @Override SortedMap init(); @Override Option> initOption(); @Override SortedSet keySet(); @Override default Tuple2 last() { return max().getOrElseThrow(() -> new NoSuchElementException("last on empty SortedMap")); } @Override SortedMap map(BiFunction> mapper); @Override SortedMap mapValues(Function valueMapper); @Override SortedMap merge(Map that); @Override SortedMap merge(Map that, BiFunction collisionResolution); @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> sliding(long size); @Override Iterator> sliding(long size, long step); @Override Tuple2, ? extends SortedMap> span(Predicate> predicate); @Override SortedMap tail(); @Override Option> tailOption(); @Override SortedMap take(long n); @Override SortedMap takeRight(long n); @Override SortedMap takeUntil(Predicate> predicate); @Override SortedMap takeWhile(Predicate> predicate); @Override java.util.SortedMap toJavaMap(); }