public class Immutables extends Object
For each Guava ImmutableCollection
, (where Collection
is List, Set, SortedSet, Map, SortedMap, BiMap
) there is a method:
ImmutableCollection mutateCollection(ImmutableCollection source, Consumer<MutableCollection> mutator)
ImmutableCollection
into a new MutableCollection
.MutableCollection
collection to the mutator
.MutableCollection
into a new ImmutableCollection
.ImmutableCollecion
.
There are also Function<ImmutableCollection, ImmutableCollection> mutatorCollection(Consumer<MutableCollection> mutator)
methods for each type, to easily create functions which operate on immutable collections.
This class also contains the simple optionalToSet(java.util.Optional<T>)
and optionalFrom(ImmutableCollection)
methods.
Modifier and Type | Method and Description |
---|---|
static <K,V> ImmutableBiMap<K,V> |
mutateBiMap(ImmutableBiMap<K,V> source,
Consumer<BiMap<K,V>> mutator)
Returns a mutated version of the given sorted map.
|
static <T> ImmutableList<T> |
mutateList(ImmutableList<T> source,
Consumer<List<T>> mutator)
Returns a mutated version of the given list.
|
static <K,V> ImmutableMap<K,V> |
mutateMap(ImmutableMap<K,V> source,
Consumer<Map<K,V>> mutator)
Returns a mutated version of the given map.
|
static <T> ImmutableSet<T> |
mutateSet(ImmutableSet<T> source,
Consumer<Set<T>> mutator)
Returns a mutated version of the given set.
|
static <K,V> ImmutableSortedMap<K,V> |
mutateSortedMap(ImmutableSortedMap<K,V> source,
Consumer<NavigableMap<K,V>> mutator)
Returns a mutated version of the given sorted map.
|
static <T> ImmutableSortedSet<T> |
mutateSortedSet(ImmutableSortedSet<T> source,
Consumer<NavigableSet<T>> mutator)
Returns a mutated version of the given sorted set.
|
static <K,V> UnaryOperator<ImmutableBiMap<K,V>> |
mutatorBiMap(Consumer<BiMap<K,V>> mutator)
Returns a function which mutates a sorted map using the given mutator.
|
static <T> UnaryOperator<ImmutableList<T>> |
mutatorList(Consumer<List<T>> mutator)
Returns a function which mutates a list using the given mutator.
|
static <K,V> UnaryOperator<ImmutableMap<K,V>> |
mutatorMap(Consumer<Map<K,V>> mutator)
Returns a function which mutates a map using the given mutator.
|
static <T> UnaryOperator<ImmutableSet<T>> |
mutatorSet(Consumer<Set<T>> mutator)
Returns a function which mutates a set using the given mutator.
|
static <K,V> UnaryOperator<ImmutableSortedMap<K,V>> |
mutatorSortedMap(Consumer<NavigableMap<K,V>> mutator)
Returns a function which mutates a sorted map using the given mutator.
|
static <T> UnaryOperator<ImmutableSortedSet<T>> |
mutatorSortedSet(Consumer<NavigableSet<T>> mutator)
Returns a function which mutates a sorted set using the given mutator.
|
static <T> Optional<T> |
optionalFrom(ImmutableCollection<T> collection)
Converts an
ImmutableCollection to an Optional . |
static <T> ImmutableSet<T> |
optionalToSet(Optional<T> selection)
Converts an
Optional to an ImmutableSet . |
static <T> Collector<T,?,ImmutableList<T>> |
toList()
A Collector which returns an ImmutableList.
|
static <T,K,V> Collector<T,?,ImmutableMap<K,V>> |
toMap(Function<? super T,? extends K> keyMapper,
Function<? super T,? extends V> valueMapper)
A Collector which returns an ImmutableMap using the given pair of key and value functions.
|
static <T> Collector<T,?,ImmutableSet<T>> |
toSet()
A Collector which returns an ImmutableSet.
|
static <T,K extends Comparable<?>,V> |
toSortedMap(Comparator<K> comparator,
Function<? super T,? extends K> keyMapper,
Function<? super T,? extends V> valueMapper)
A Collector which returns an ImmutableSortedMap which is ordered by the given comparator, and populated by the given pair of key and value functions.
|
static <T,K extends Comparable<?>,V> |
toSortedMap(Function<? super T,? extends K> keyMapper,
Function<? super T,? extends V> valueMapper)
A Collector which returns an ImmutableSortedMap which is populated by the given pair of key and value functions.
|
static <T extends Comparable<?>> |
toSortedSet()
A Collector of Comparables which returns an ImmutableSortedSet.
|
static <T> Collector<T,?,ImmutableSortedSet<T>> |
toSortedSet(Comparator<T> comparator)
A Collector which returns an ImmutableSortedSet which is ordered by the given comparator.
|
public static <T> ImmutableList<T> mutateList(ImmutableList<T> source, Consumer<List<T>> mutator)
public static <T> ImmutableSet<T> mutateSet(ImmutableSet<T> source, Consumer<Set<T>> mutator)
public static <T> ImmutableSortedSet<T> mutateSortedSet(ImmutableSortedSet<T> source, Consumer<NavigableSet<T>> mutator)
public static <K,V> ImmutableMap<K,V> mutateMap(ImmutableMap<K,V> source, Consumer<Map<K,V>> mutator)
public static <K,V> ImmutableSortedMap<K,V> mutateSortedMap(ImmutableSortedMap<K,V> source, Consumer<NavigableMap<K,V>> mutator)
public static <K,V> ImmutableBiMap<K,V> mutateBiMap(ImmutableBiMap<K,V> source, Consumer<BiMap<K,V>> mutator)
public static <T> UnaryOperator<ImmutableList<T>> mutatorList(Consumer<List<T>> mutator)
public static <T> UnaryOperator<ImmutableSet<T>> mutatorSet(Consumer<Set<T>> mutator)
public static <T> UnaryOperator<ImmutableSortedSet<T>> mutatorSortedSet(Consumer<NavigableSet<T>> mutator)
public static <K,V> UnaryOperator<ImmutableMap<K,V>> mutatorMap(Consumer<Map<K,V>> mutator)
public static <K,V> UnaryOperator<ImmutableSortedMap<K,V>> mutatorSortedMap(Consumer<NavigableMap<K,V>> mutator)
public static <K,V> UnaryOperator<ImmutableBiMap<K,V>> mutatorBiMap(Consumer<BiMap<K,V>> mutator)
public static <T> ImmutableSet<T> optionalToSet(Optional<T> selection)
Optional
to an ImmutableSet
.public static <T> Optional<T> optionalFrom(ImmutableCollection<T> collection)
ImmutableCollection
to an Optional
.IllegalArgumentException
- if there are multiple elements.public static <T> Collector<T,?,ImmutableList<T>> toList()
public static <T> Collector<T,?,ImmutableSet<T>> toSet()
public static <T extends Comparable<?>> Collector<T,?,ImmutableSortedSet<T>> toSortedSet()
public static <T> Collector<T,?,ImmutableSortedSet<T>> toSortedSet(Comparator<T> comparator)
public static <T,K,V> Collector<T,?,ImmutableMap<K,V>> toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends V> valueMapper)
public static <T,K extends Comparable<?>,V> Collector<T,?,ImmutableSortedMap<K,V>> toSortedMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends V> valueMapper)
public static <T,K extends Comparable<?>,V> Collector<T,?,ImmutableSortedMap<K,V>> toSortedMap(Comparator<K> comparator, Function<? super T,? extends K> keyMapper, Function<? super T,? extends V> valueMapper)