/** * Alias for {@link TreeMap#empty(Comparator)} * * @param <K> The key type. * @param <V> The value type. * @param keyComparator The comparator used to sort the entries by their key * @return A new empty {@link TreeMap} instance */ public static <K, V> SortedMap<K, V> SortedMap(Comparator<? super K> keyComparator) { return TreeMap.empty(keyComparator); }
/** * Alias for {@link TreeMap#empty()} * * @param <K> The key type. * @param <V> The value type. * @return A new empty {@link TreeMap} instance */ public static <K extends Comparable<? super K>, V> SortedMap<K, V> SortedMap() { return TreeMap.empty(); }
/** * Returns the empty TreeMultimap using the given key comparator. * * @param <K> The key type * @param <V2> The value type * @param keyComparator The comparator used to sort the entries by their key. * @return A new empty TreeMultimap. */ public <K, V2 extends V> TreeMultimap<K, V2> empty(Comparator<? super K> keyComparator) { Objects.requireNonNull(keyComparator, "keyComparator is null"); return new TreeMultimap<>(TreeMap.empty(keyComparator), containerType, emptyContainer); }
@Override protected <K2, V2> Map<K2, V2> emptyMapSupplier() { return TreeMap.empty(Comparators.naturalComparator()); }
/** * Returns a {@code TreeMap}, from entries mapped from stream. * * @param stream the source stream * @param entryMapper the entry mapper * @param <T> The stream element type * @param <K> The key type * @param <V> The value type * @return A new Map */ public static <T, K extends Comparable<? super K>, V> TreeMap<K, V> ofAll(java.util.stream.Stream<? extends T> stream, Function<? super T, Tuple2<? extends K, ? extends V>> entryMapper) { return Maps.ofStream(TreeMap.<K, V> empty(), stream, entryMapper); }
/** * Returns a {@code TreeMap}, from entries mapped from stream. * * @param keyComparator The comparator used to sort the entries by their key. * @param stream the source stream * @param entryMapper the entry mapper * @param <T> The stream element type * @param <K> The key type * @param <V> The value type * @return A new Map */ public static <T, K, V> TreeMap<K, V> ofAll(Comparator<? super K> keyComparator, java.util.stream.Stream<? extends T> stream, Function<? super T, Tuple2<? extends K, ? extends V>> entryMapper) { return Maps.ofStream(empty(keyComparator), stream, entryMapper); }
/** * Returns a {@code TreeMap}, from entries mapped from stream. * * @param stream the source stream * @param keyMapper the key mapper * @param valueMapper the value mapper * @param <T> The stream element type * @param <K> The key type * @param <V> The value type * @return A new Map */ public static <T, K extends Comparable<? super K>, V> TreeMap<K, V> ofAll(java.util.stream.Stream<? extends T> stream, Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends V> valueMapper) { return Maps.ofStream(TreeMap.<K, V> empty(), stream, keyMapper, valueMapper); }
/** * Returns a {@code TreeMap}, from entries mapped from stream. * * @param keyComparator The comparator used to sort the entries by their key. * @param stream the source stream * @param keyMapper the key mapper * @param valueMapper the value mapper * @param <T> The stream element type * @param <K> The key type * @param <V> The value type * @return A new Map */ public static <T, K, V> TreeMap<K, V> ofAll(Comparator<? super K> keyComparator, java.util.stream.Stream<? extends T> stream, Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends V> valueMapper) { return Maps.ofStream(empty(keyComparator), stream, keyMapper, valueMapper); }
@Override public <K2> TreeMap<K2, V> mapKeys(Function<? super K, ? extends K2> keyMapper, BiFunction<? super V, ? super V, ? extends V> valueMerge) { final Comparator<K2> comparator = Comparators.naturalComparator(); return Collections.mapKeys(this, TreeMap.<K2, V> empty(comparator), keyMapper, valueMerge); }
/** * Converts this to a {@link Map}. * * @param comparator A comparator that induces an order of the Map keys. * @param f A function that maps an element to a key/value pair represented by Tuple2 * @param <K> The key type * @param <V> The value type * @return A new {@link TreeMap}. */ default <K, V> SortedMap<K, V> toSortedMap(Comparator<? super K> comparator, Function<? super T, ? extends Tuple2<? extends K, ? extends V>> f) { Objects.requireNonNull(comparator, "comparator is null"); Objects.requireNonNull(f, "f is null"); final Function<Tuple2<? extends K, ? extends V>, SortedMap<K, V>> ofElement = t -> TreeMap.of(comparator, t); final Function<Iterable<Tuple2<? extends K, ? extends V>>, SortedMap<K, V>> ofAll = t -> TreeMap.ofEntries(comparator, t); return ValueModule.toMap(this, TreeMap.empty(comparator), ofElement, ofAll, f); }
/** * Alias for {@link TreeMap#empty(Comparator)} * * @param <K> The key type. * @param <V> The value type. * @param keyComparator The comparator used to sort the entries by their key * @return A new empty {@link TreeMap} instance */ public static <K, V> SortedMap<K, V> SortedMap(Comparator<? super K> keyComparator) { return TreeMap.empty(keyComparator); }
/** * Alias for {@link TreeMap#empty()} * * @param <K> The key type. * @param <V> The value type. * @return A new empty {@link TreeMap} instance */ public static <K extends Comparable<? super K>, V> SortedMap<K, V> SortedMap() { return TreeMap.empty(); }
/** * Returns the empty TreeMultimap using the given key comparator. * * @param <K> The key type * @param <V2> The value type * @param keyComparator The comparator used to sort the entries by their key. * @return A new empty TreeMultimap. */ public <K, V2 extends V> TreeMultimap<K, V2> empty(Comparator<? super K> keyComparator) { Objects.requireNonNull(keyComparator, "keyComparator is null"); return new TreeMultimap<>(TreeMap.empty(keyComparator), containerType, emptyContainer); }
@Override protected <K2, V2> Map<K2, V2> emptyMapSupplier() { return TreeMap.empty(Comparators.naturalComparator()); }
/** * Returns a {@code TreeMap}, from entries mapped from stream. * * @param stream the source stream * @param entryMapper the entry mapper * @param <T> The stream element type * @param <K> The key type * @param <V> The value type * @return A new Map */ public static <T, K extends Comparable<? super K>, V> TreeMap<K, V> ofAll(java.util.stream.Stream<? extends T> stream, Function<? super T, Tuple2<? extends K, ? extends V>> entryMapper) { return Maps.ofStream(TreeMap.<K, V> empty(), stream, entryMapper); }
/** * Returns a {@code TreeMap}, from entries mapped from stream. * * @param stream the source stream * @param keyMapper the key mapper * @param valueMapper the value mapper * @param <T> The stream element type * @param <K> The key type * @param <V> The value type * @return A new Map */ public static <T, K extends Comparable<? super K>, V> TreeMap<K, V> ofAll(java.util.stream.Stream<? extends T> stream, Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends V> valueMapper) { return Maps.ofStream(TreeMap.<K, V> empty(), stream, keyMapper, valueMapper); }
/** * Returns a {@code TreeMap}, from entries mapped from stream. * * @param keyComparator The comparator used to sort the entries by their key. * @param stream the source stream * @param entryMapper the entry mapper * @param <T> The stream element type * @param <K> The key type * @param <V> The value type * @return A new Map */ public static <T, K, V> TreeMap<K, V> ofAll(Comparator<? super K> keyComparator, java.util.stream.Stream<? extends T> stream, Function<? super T, Tuple2<? extends K, ? extends V>> entryMapper) { return Maps.ofStream(empty(keyComparator), stream, entryMapper); }
@Override public <K2> TreeMap<K2, V> mapKeys(Function<? super K, ? extends K2> keyMapper, BiFunction<? super V, ? super V, ? extends V> valueMerge) { final Comparator<K2> comparator = Comparators.naturalComparator(); return Collections.mapKeys(this, TreeMap.<K2, V> empty(comparator), keyMapper, valueMerge); }
/** * Converts this to a {@link Map}. * * @param comparator A comparator that induces an order of the Map keys. * @param f A function that maps an element to a key/value pair represented by Tuple2 * @param <K> The key type * @param <V> The value type * @return A new {@link TreeMap}. */ default <K, V> SortedMap<K, V> toSortedMap(Comparator<? super K> comparator, Function<? super T, ? extends Tuple2<? extends K, ? extends V>> f) { Objects.requireNonNull(comparator, "comparator is null"); Objects.requireNonNull(f, "f is null"); final Function<Tuple2<? extends K, ? extends V>, SortedMap<K, V>> ofElement = t -> TreeMap.of(comparator, t); final Function<Iterable<Tuple2<? extends K, ? extends V>>, SortedMap<K, V>> ofAll = t -> TreeMap.ofEntries(comparator, t); return ValueModule.toMap(this, TreeMap.empty(comparator), ofElement, ofAll, f); }
@Override <K, V> Map<K, V> emptyMap() { return TreeMap.empty((o1, o2) -> o1.toString().compareTo(o2.toString())); }