Package de.scravy.bedrock
Class ArrayMap<K extends Comparable<? super K>,V>
java.lang.Object
de.scravy.bedrock.ArrayMap<K,V>
- Type Parameters:
K- The type of the keys of this ArrayMap. Must implement Comparable. Does not allow for null values.V- The type of the values of this ArrayMap. Can be anything. Allows for null values.
- All Implemented Interfaces:
ExtendedIterable<Pair<K,V>>,Function1<K,V>,HasLengthAtLeast,Mapping<K,V>,Iterable<Pair<K,V>>,Function<K,V>
@Immutable public final class ArrayMap<K extends Comparable<? super K>,V> extends Object implements Mapping<K,V>
A very simple immutable map that is backed by two arrays
(one for the keys, one for the values). Lookups are performed by performing
binary searches on the key array - thus the keys need to implement the
Comparable interface.
Some operations are implemented quite space efficiently. For instance both mapValues and mapValuesWithKey share the key array with the source ArrayMap.
-
Nested Class Summary
Nested classes/interfaces inherited from interface de.scravy.bedrock.ExtendedIterable
ExtendedIterable.ForEachWithIndexConsumer<T>Nested classes/interfaces inherited from interface de.scravy.bedrock.Mapping
Mapping.EmptyMapping<K,V> -
Constructor Summary
Constructors Constructor Description ArrayMap() -
Method Summary
Modifier and Type Method Description Vapply(K key)static <K extends Comparable<? super K>, V>
ArrayMapBuilder<K,V>builder()static <K extends Comparable<? super K>, V>
Collector<Pair<K,V>,TreeMap<K,V>,ArrayMap<K,V>>collector()static <K extends Comparable<? super K>, V>
ArrayMap<K,V>empty()booleanequals(Object other)ArrayMap<K,V>filter(Predicate<K> predicate)ArrayMap<K,V>filterWithValue(BiPredicate<K,V> predicate)Optional<V>get(K key)Retrieves the value associated with the given key or Optional.empty() if the key is not mapped to any value.inthashCode()ArrayMap<K,V>intersect(ArrayMap<K,V> arrayMap)Iterator<Pair<K,V>>iterator()Seq<K>keys()<W> ArrayMap<K,W>mapValues(Function<V,W> f)<W> ArrayMap<K,W>mapValuesWithKey(BiFunction<K,V,W> f)static <K extends Comparable<K>, V>
ArrayMap<K,V>of(Pair<K,V>... pairs)static <K extends Comparable<? super K>, V>
ArrayMap<K,V>ofMap(Map<K,V> pairs)static <K extends Comparable<K>, V>
ArrayMap<K,V>ofSeq(Seq<Pair<K,V>> pairs)static <K extends Comparable<? super K>, V>
ArrayMap<K,V>ofTreeMap(TreeMap<K,V> pairs)ArrayMap<K,V>setDefaultReturnValue(V value)StringtoString()ArrayMap<K,V>union(ArrayMap<K,V> arrayMap)Seq<V>values()
-
Constructor Details
-
ArrayMap
public ArrayMap()
-
-
Method Details
-
setDefaultReturnValue
-
get
Description copied from interface:MappingRetrieves the value associated with the given key or Optional.empty() if the key is not mapped to any value. -
apply
-
mapValues
-
mapValuesWithKey
-
filter
-
filterWithValue
-
iterator
-
keys
-
values
-
union
-
intersect
-
toString
-
of
@Nonnull @SafeVarargs public static <K extends Comparable<K>, V> ArrayMap<K,V> of(@Nonnull Pair<K,V>... pairs) -
ofSeq
-
ofMap
@Nonnull public static <K extends Comparable<? super K>, V> ArrayMap<K,V> ofMap(@Nonnull Map<K,V> pairs) -
ofTreeMap
@Nonnull public static <K extends Comparable<? super K>, V> ArrayMap<K,V> ofTreeMap(@Nonnull TreeMap<K,V> pairs) -
empty
-
collector
-
builder
-
equals
-
hashCode
public int hashCode()
-