Class Mappings
- java.lang.Object
-
- net.automatalib.common.util.mapping.Mappings
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <D,R>
Iterable<R>apply(Mapping<? super D,R> mapping, Iterable<? extends D> it)
Applies a mapping to an iterable.static <D,R>
Collection<R>apply(Mapping<? super D,R> mapping, Collection<? extends D> coll)
Applies a mapping to a collection, resulting in a collection containing the result of applying the specified mapping to each element in the collection.static <D,R>
Iterator<R>apply(Mapping<? super D,R> mapping, Iterator<? extends D> baseIt)
Applies a mapping to an iterator.static <D,R>
List<R>apply(Mapping<? super D,R> mapping, List<? extends D> list)
Applies a mapping to a list, resulting in a list containing the result of applying the specified mapping to each element in the list.static <D,I,R>
Mapping<D,R>compose(Mapping<D,? extends I> first, Mapping<? super I,R> second)
Retrieves the composition of two mappings, i.e., that mapping that results from applying theMapping.get(Object)
method consecutively.static <D,R>
Mapping<D,R>fromMap(Map<D,R> map)
static <T> Mapping<T,T>
identity()
Retrieves the identity mapping, which maps each domain value to itself.static <D> D
idGet(Mapping<D,D> mapping, D key)
static Mapping<@NonNegative Long,String>
indexToString()
static <D,R>
@Nullable RnullGet(@Nullable Mapping<? super D,? extends R> mapping, D key)
static <D,R>
Mapping<D,R>nullMapping()
Retrieves thenull
mapping, which maps each domain value tonull
.static <D,R>
RsafeGet(@Nullable Mapping<? super D,? extends R> mapping, D key, R fallback)
Safely retrieves a value from a mapping.static Mapping<String,Long>
stringToIndex()
static <D> Mapping<D,String>
toStringMapping()
Returns a mapping that maps objects to theirString
representation, as obtained byString.valueOf(Object)
.static <S,T extends S>
Mapping<T,S>upcast()
Returns a mapping that maps objects to a supertype representation.
-
-
-
Method Detail
-
nullMapping
public static <D,R> Mapping<D,R> nullMapping()
Retrieves thenull
mapping, which maps each domain value tonull
.- Type Parameters:
D
- domain class.R
- range class.- Returns:
- the
null
mapping.
-
identity
public static <T> Mapping<T,T> identity()
Retrieves the identity mapping, which maps each domain value to itself.- Type Parameters:
T
- domain/range class.- Returns:
- the identity mapping.
-
toStringMapping
public static <D> Mapping<D,String> toStringMapping()
Returns a mapping that maps objects to theirString
representation, as obtained byString.valueOf(Object)
.- Returns:
- the "
toString()
" mapping
-
upcast
public static <S,T extends S> Mapping<T,S> upcast()
Returns a mapping that maps objects to a supertype representation.- Returns:
- the "upcast" mapping
-
compose
public static <D,I,R> Mapping<D,R> compose(Mapping<D,? extends I> first, Mapping<? super I,R> second)
Retrieves the composition of two mappings, i.e., that mapping that results from applying theMapping.get(Object)
method consecutively.- Type Parameters:
D
- domain class of the first (and resulting) mapping.I
- intermediate object class, range class of the first and domain class of the second mapping.R
- range class of the second (and resulting) mapping.- Parameters:
first
- first mapping.second
- second mapping.- Returns:
- the composed mapping.
-
apply
public static <D,R> Collection<R> apply(Mapping<? super D,R> mapping, Collection<? extends D> coll)
Applies a mapping to a collection, resulting in a collection containing the result of applying the specified mapping to each element in the collection.Note that more specific properties of the specified collection won't be preserved: If the given collection is e.g. a set, and the provided mapping is not bijective, then the resulting collections may contain some values multiple times.
- Type Parameters:
D
- domain class.R
- range class.- Parameters:
mapping
- the mapping to apply.coll
- the collection.- Returns:
- the mapped collection.
-
apply
public static <D,R> Iterator<R> apply(Mapping<? super D,R> mapping, Iterator<? extends D> baseIt)
Applies a mapping to an iterator. For the behavior, seeapply(Mapping, Iterable)
. The resulting iterator supports each operation which the underlying supports.- Type Parameters:
D
- domain class.R
- range class.- Parameters:
mapping
- the mapping to apply.baseIt
- the underlying iterator.- Returns:
- the mapped iterator.
-
apply
public static <D,R> List<R> apply(Mapping<? super D,R> mapping, List<? extends D> list)
Applies a mapping to a list, resulting in a list containing the result of applying the specified mapping to each element in the list.- Parameters:
mapping
- the mapping to apply.list
- the list.- Returns:
- the mapped list.
-
apply
public static <D,R> Iterable<R> apply(Mapping<? super D,R> mapping, Iterable<? extends D> it)
Applies a mapping to an iterable. The result is an iterable whose iterator returns the results of applying the specified mapping to each of the elements returned by the original iterable.- Type Parameters:
D
- domain class.R
- range clas.- Parameters:
mapping
- the mapping to apply.it
- the underlying iterable.- Returns:
- the mapped iterable.
-
idGet
public static <D> D idGet(Mapping<D,D> mapping, D key)
-
safeGet
public static <D,R> R safeGet(@Nullable Mapping<? super D,? extends R> mapping, D key, R fallback)
Safely retrieves a value from a mapping. If the mapping isnull
or returns anull
value, the given fallback value is returned.- Parameters:
mapping
- the mapping.key
- the key.fallback
- the fallback value to return if either the mapping or the originally returned value arenull
.- Returns:
- the value returned by the specified mapping, or the fallback value.
-
nullGet
public static <D,R> @Nullable R nullGet(@Nullable Mapping<? super D,? extends R> mapping, D key)
-
indexToString
public static Mapping<@NonNegative Long,String> indexToString()
-
-