Package uk.ac.manchester.spinnaker.utils
Interface MappableIterable<T>
- Type Parameters:
- T- The type of elements returned by the iterator. Note that it is strongly recommended to not ever return- null; consider using- Optionalinstead of that.
- All Superinterfaces:
- Iterable<T>
- All Known Implementing Classes:
- DoubleMapIterable,- ProgressIterable,- ReaderLineIterable,- TripleMapIterable
Extends iterable with the ability to be mapped to different values.
- Author:
- Donal Fellows
- 
Method SummaryModifier and TypeMethodDescriptiondefault MappableIterable<T>Apply a filter to an iterable to get another iterable.first()Get the first item in the iterable, if there is one.default MappableIterable<T>first(int n) Get another iterable with the firstnitem in the iterable (or up to that if the source iterable has fewer items).default <U> MappableIterable<U>Apply a function to an iterable to get another iterable.nth(int n) Index into the iterable.Convert this iterable to a map of sets of enum values.toCollectingMap(Function<T, K> keyMapper, Function<T, V> valueMapper) Convert this iterable to a map of lists.default <K,V, S extends Collection<V>> 
 Map<K,S> toCollectingMap(Supplier<Map<K, S>> mapSupplier, Supplier<S> collectorSupplier, Function<T, K> keyMapper, Function<T, V> valueMapper) Convert this iterable to a map of collections.default <K,V, S extends Collection<V>> 
 Map<K,S> Convert this iterable to a map of collections.toList()Convert this iterable to a list.Convert this iterable to a list.default <K,V> Map<K, V> Convert this iterable to a map.default <K,V> Map<K, V> Convert this iterable to a map.toSet()Convert this iterable to a set.Convert this iterable to a set.Methods inherited from interface java.lang.IterableforEach, iterator, spliterator
- 
Method Details- 
mapApply a function to an iterable to get another iterable.- Type Parameters:
- U- The type of the elements of the created iterable.
- Parameters:
- mapper- The function to apply. Should not return- null.
- Returns:
- The new iterable, which may also be mapped.
 
- 
filterApply a filter to an iterable to get another iterable. Note that this assumes thatnullis never produced as a value that should be produced in the resulting iterable.- Parameters:
- filterer- The filter function to apply.
- Returns:
- The new iterable, which only contains elements for which
         filtererreturnstrueand which are notnull.
 
- 
firstGet the first item in the iterable, if there is one.- Returns:
- an optional with the first item.
 
- 
firstGet another iterable with the firstnitem in the iterable (or up to that if the source iterable has fewer items).- Parameters:
- n- the maximum number of items of the iterable that are wanted
- Returns:
- the first nitems.
 
- 
nthIndex into the iterable.- Parameters:
- n- The index into the iterable. Zero-based.
- Returns:
- The item at that index, should it exist.
 
- 
toListConvert this iterable to a list. The order of elements in the list will be the same as the order of items in this iterable.- Returns:
- A list of the elements in the iterable. Note that this must be finite! This list is not modifiable.
 
- 
toListConvert this iterable to a list. Items will be added to the list in the order of this iterable.- Parameters:
- supplier- How to make the list itself.
- Returns:
- A list of the elements in the iterable. Note that this must be finite! This list is not modifiable.
 
- 
toSetConvert this iterable to a set. The natural order of elements in the set will be the same as the order of items in this iterable.- Returns:
- A set of the elements in the iterable. Note that this must be finite! This set is not modifiable.
 
- 
toSetConvert this iterable to a set. Items will be added to the set in the order of this iterable.- Parameters:
- supplier- How to make the set itself.
- Returns:
- A set of the elements in the iterable. Note that this must be finite! This set is not modifiable.
 
- 
toMapConvert this iterable to a map. The natural order of entries will be the same as the natural order of elements in this iterable.- Type Parameters:
- K- The type of keys.
- V- The type of values.
- Parameters:
- keyMapper- How to get a key from an element of the iterable.
- valueMapper- How to get a value from an element of the iterable.
- Returns:
- A map derived from elements in the iterable. Note that this must be finite! This map is not modifiable.
 
- 
toMapdefault <K,V> Map<K,V> toMap(Supplier<Map<K, V>> supplier, Function<T, K> keyMapper, Function<T, V> valueMapper) Convert this iterable to a map. Items will be added to the map in the order of this iterable.- Type Parameters:
- K- The type of keys.
- V- The type of values.
- Parameters:
- supplier- How to make the map itself.
- keyMapper- How to get a key from an element of the iterable.
- valueMapper- How to get a value from an element of the iterable.
- Returns:
- A map derived from the elements in the iterable. Note that this must be finite! This map is not modifiable.
 
- 
toCollectingMapConvert this iterable to a map of lists. Items will be added to the map and to the lists in the order of this iterable.- Type Parameters:
- K- The type of keys.
- V- The type of leaf values.
- Parameters:
- keyMapper- How to get a key from an element of the iterable.
- valueMapper- How to get a leaf value from an element of the iterable.
- Returns:
- A map derived from the elements in the iterable. Note that this must be finite! This map is not modifiable.
 
- 
toCollectingMapdefault <K,E extends Enum<E>> Map<K,EnumSet<E>> toCollectingMap(Class<E> cls, Function<T, K> keyMapper, Function<T, E> valueMapper) Convert this iterable to a map of sets of enum values. Items will be added to the map in the order of this iterable.- Type Parameters:
- K- The type of keys.
- E- The type of leaf values.
- Parameters:
- cls- The class of leaf values.
- keyMapper- How to get a key from an element of the iterable.
- valueMapper- How to get a leaf value from an element of the iterable.
- Returns:
- A map derived from the elements in the iterable. Note that this must be finite! This map is not modifiable.
 
- 
toCollectingMapdefault <K,V, Map<K,S extends Collection<V>> S> toCollectingMap(Supplier<S> supplier, Function<T, K> keyMapper, Function<T, V> valueMapper) Convert this iterable to a map of collections. Items will be added to the map and to the collections in the order of this iterable.- Type Parameters:
- K- The type of keys.
- V- The type of leaf values.
- S- The type of per-key collectors.
- Parameters:
- supplier- How to make the value collectors.
- keyMapper- How to get a key from an element of the iterable.
- valueMapper- How to get a leaf value from an element of the iterable.
- Returns:
- A map derived from the elements in the iterable. Note that this must be finite! This map is not modifiable.
 
- 
toCollectingMapdefault <K,V, Map<K,S extends Collection<V>> S> toCollectingMap(Supplier<Map<K, S>> mapSupplier, Supplier<S> collectorSupplier, Function<T, K> keyMapper, Function<T, V> valueMapper) Convert this iterable to a map of collections. Items will be added to the map and to the collections in the order of this iterable.- Type Parameters:
- K- The type of keys.
- V- The type of leaf values.
- S- The type of per-key collectors.
- Parameters:
- mapSupplier- How to make the map itself.
- collectorSupplier- How to make the value collectors.
- keyMapper- How to get a key from an element of the iterable.
- valueMapper- How to get a value from an element of the iterable.
- Returns:
- A map derived from the elements in the iterable. Note that this must be finite! This map is not modifiable.
 
 
-