/** * Iterates this Map sequentially, mapping the (key, value) pairs to elements. * * @param mapper A function that maps (key, value) pairs to elements of type U * @param <U> The type of the resulting elements * @return An iterator through the mapped elements. */ default <U> Iterator<U> iterator(BiFunction<K, V, ? extends U> mapper) { Objects.requireNonNull(mapper, "mapper is null"); return iterator().map(t -> mapper.apply(t._1, t._2)); }
@Override default <R> Iterator<R> collect(PartialFunction<? super T, ? extends R> partialFunction) { Objects.requireNonNull(partialFunction, "partialFunction is null"); return filter(partialFunction::isDefinedAt).map(partialFunction::apply); }
/** * Returns the keys contained in this map as an iterator. * * @return {@code Iterator} of the keys contained in this map. */ default Iterator<K> keysIterator() { return iterator().map(Tuple2::_1); }
/** * Iterates this Multimap sequentially, mapping the (key, value) pairs to elements. * * @param mapper A function that maps (key, value) pairs to elements of type U * @param <U> The type of the resulting elements * @return An iterator through the mapped elements. */ default <U> Iterator<U> iterator(BiFunction<K, V, ? extends U> mapper) { Objects.requireNonNull(mapper, "mapper is null"); return iterator().map(t -> mapper.apply(t._1, t._2)); }
/** * Yields a result for elements of the cross product of the underlying Iterable. * * @param f a function that maps an element of the cross product to a result * @param <R> type of the resulting {@code Iterator} elements * @return an {@code Iterator} of mapped results */ public <R> Iterator<R> yield(Function<? super T1, ? extends R> f) { Objects.requireNonNull(f, "f is null"); return Iterator.ofAll(ts1).map(f); }
public <U> PriorityQueue<U> map(Comparator<U> comparator, Function<? super T, ? extends U> mapper) { Objects.requireNonNull(comparator, "comparator is null"); Objects.requireNonNull(mapper, "mapper is null"); return ofAll(comparator, iterator().map(mapper)); }
@Override public <K2, V2> LinkedHashMap<K2, V2> bimap(Function<? super K, ? extends K2> keyMapper, Function<? super V, ? extends V2> valueMapper) { Objects.requireNonNull(keyMapper, "keyMapper is null"); Objects.requireNonNull(valueMapper, "valueMapper is null"); final Iterator<Tuple2<K2, V2>> entries = iterator().map(entry -> Tuple.of(keyMapper.apply(entry._1), valueMapper.apply(entry._2))); return LinkedHashMap.ofEntries(entries); }
@Override public <U> TreeSet<U> map(Comparator<? super U> comparator, Function<? super T, ? extends U> mapper) { Objects.requireNonNull(mapper, "mapper is null"); return TreeSet.ofAll(comparator, iterator().map(mapper)); }
@Override public <K2, V2> HashMap<K2, V2> bimap(Function<? super K, ? extends K2> keyMapper, Function<? super V, ? extends V2> valueMapper) { Objects.requireNonNull(keyMapper, "keyMapper is null"); Objects.requireNonNull(valueMapper, "valueMapper is null"); final Iterator<Tuple2<K2, V2>> entries = iterator().map(entry -> Tuple.of(keyMapper.apply(entry._1), valueMapper.apply(entry._2))); return HashMap.ofEntries(entries); }
@Override default <U> SortedSet<U> map(Comparator<? super U> comparator, Function<? super T, ? extends U> mapper) { Objects.requireNonNull(mapper, "mapper is null"); return TreeSet.ofAll(comparator, iterator().map(mapper)); }
@Override public <K2, V2> Multimap<K2, V2> bimap(Function<? super K, ? extends K2> keyMapper, Function<? super V, ? extends V2> valueMapper) { Objects.requireNonNull(keyMapper, "keyMapper is null"); Objects.requireNonNull(valueMapper, "valueMapper is null"); final Iterator<Tuple2<K2, V2>> entries = iterator().map(entry -> Tuple.of(keyMapper.apply(entry._1), valueMapper.apply(entry._2))); return createFromEntries(entries); }
@Override public final String toString() { return iterator().map(t -> t._1 + " -> " + t._2).mkString("HashArrayMappedTrie(", ", ", ")"); } }
/** * Returns <code>true</code> if this map maps one or more keys to the * specified value. This operation will require time linear in the map size. * * @param value value whose presence in this map is to be tested * @return <code>true</code> if this map maps one or more keys to the * specified value */ default boolean containsValue(V value) { return iterator().map(Tuple2::_2).contains(value); }
@SuppressWarnings("unchecked") @Override public Iterator<M> sliding(int size, int step) { return (Iterator<M>) iterator().sliding(size, step).map(this::createFromEntries); }
/** * Returns <code>true</code> if this multimap maps one or more keys to the * specified value. This operation will require time linear in the map size. * * @param value value whose presence in this multimap is to be tested * @return <code>true</code> if this multimap maps one or more keys to the * specified value */ default boolean containsValue(V value) { return iterator().map(Tuple2::_2).contains(value); }
static <T, K, V, E extends Tuple2<? extends K, ? extends V>, R extends Map<K, V>> R toMap( Value<T> value, R empty, Function<E, R> ofElement, Function<Iterable<E>, R> ofAll, Function<? super T, ? extends E> f) { if (value.isEmpty()) { return empty; } else if (value.isSingleValued()) { return ofElement.apply(f.apply(value.get())); } else { return ofAll.apply(Iterator.ofAll(value).map(f)); } }
@GwtIncompatible("BigDecimalHelper is GwtIncompatible") static Iterator<Double> rangeBy(double from, double toExclusive, double step) { final BigDecimal fromDecimal = asDecimal(from), toDecimal = asDecimal(toExclusive), stepDecimal = asDecimal(step); return rangeBy(fromDecimal, toDecimal, stepDecimal).map(BigDecimal::doubleValue); }
@Override default <T1, T2> Tuple2<Iterator<T1>, Iterator<T2>> unzip( Function<? super T, Tuple2<? extends T1, ? extends T2>> unzipper) { Objects.requireNonNull(unzipper, "unzipper is null"); if (!hasNext()) { return Tuple.of(empty(), empty()); } else { final Stream<Tuple2<? extends T1, ? extends T2>> source = Stream.ofAll(this.map(unzipper)); return Tuple.of(source.map(t -> (T1) t._1).iterator(), source.map(t -> (T2) t._2).iterator()); } }
@Override public Iterator<Tuple2<K, V>> iterator() { if (containerType == ContainerType.SORTED_SET) { return back.iterator().flatMap(t -> t._2.iterator().map(v -> Tuple.of(t._1, v))); } else { return back.iterator().flatMap(t -> t._2.map(v -> Tuple.of(t._1, v))); } }
@Override default <T1, T2, T3> Tuple3<Iterator<T1>, Iterator<T2>, Iterator<T3>> unzip3( Function<? super T, Tuple3<? extends T1, ? extends T2, ? extends T3>> unzipper) { Objects.requireNonNull(unzipper, "unzipper is null"); if (!hasNext()) { return Tuple.of(empty(), empty(), empty()); } else { final Stream<Tuple3<? extends T1, ? extends T2, ? extends T3>> source = Stream.ofAll(this.map(unzipper)); return Tuple.of(source.map(t -> (T1) t._1).iterator(), source.map(t -> (T2) t._2).iterator(), source.map(t -> (T3) t._3).iterator()); } }