Package net.morimekta.util.collect
Class UnmodifiableMap<K,V>
- java.lang.Object
-
- net.morimekta.util.collect.UnmodifiableMap<K,V>
-
- Type Parameters:
K
- The entry key type.V
- The entry value type.
- All Implemented Interfaces:
java.util.Map<K,V>
@Immutable public class UnmodifiableMap<K,V> extends java.lang.Object implements java.util.Map<K,V>
Simple unmodifiable map that preserves entry order when iterating. This data structure is essentially the same as an associative array, but not modifiable. Backing lookup mechanism is a simple hash table. Note that the builder for this differs from the guava immutable map simply by accepting values to be overwritten, and differs from the java.utilHashMap
by being unmodifiable and order preserving, more like an unmodifiableLinkedHashMap
. Since the map is not modifiable it is possible to achieve full compatibility with theMap
interface with much simpler backing structures and logic. By requiring all values to be non-null, some of the logic can be even simpler.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
UnmodifiableMap.Builder<K,V>
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <K,V>
UnmodifiableMap.Builder<K,V>builder()
static <K,V>
UnmodifiableMap.Builder<K,V>builder(int initialCapacity)
void
clear()
boolean
containsKey(java.lang.Object o)
boolean
containsValue(java.lang.Object o)
static <K,V>
UnmodifiableMap<K,V>copyOf(java.util.Map<K,V> map)
protected static <K,V>
java.util.Map.Entry<K,V>entry(K key, V value)
java.util.Set<java.util.Map.Entry<K,V>>
entrySet()
boolean
equals(java.lang.Object obj)
V
get(java.lang.Object o)
int
hashCode()
boolean
isEmpty()
java.util.Set<K>
keySet()
protected java.util.Set<java.util.Map.Entry<K,V>>
makeEntrySet()
protected java.util.Set<K>
makeKeySet()
static <K,V>
UnmodifiableMap<K,V>mapOf()
static <K,V>
UnmodifiableMap<K,V>mapOf(K key, V value)
static <K,V>
UnmodifiableMap<K,V>mapOf(K k1, V v1, K k2, V v2)
static <K,V>
UnmodifiableMap<K,V>mapOf(K k1, V v1, K k2, V v2, K k3, V v3)
static <K,V>
UnmodifiableMap<K,V>mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)
static <K,V>
UnmodifiableMap<K,V>mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5)
static <K,V>
UnmodifiableMap<K,V>mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6)
static <K,V>
UnmodifiableMap<K,V>mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7)
static <K,V>
UnmodifiableMap<K,V>mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8)
static <K,V>
UnmodifiableMap<K,V>mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9)
static <K,V>
UnmodifiableMap<K,V>mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9, K k10, V v10)
UnmodifiableSortedMap<K,V>
orderedBy(java.util.Comparator<K> comparator)
Get the map as a sorted map ordered by the specific comparator.V
put(K k, V v)
void
putAll(java.util.Map<? extends K,? extends V> map)
V
remove(java.lang.Object o)
int
size()
java.lang.String
toString()
java.util.Collection<V>
values()
-
-
-
Method Detail
-
copyOf
@Nonnull public static <K,V> UnmodifiableMap<K,V> copyOf(java.util.Map<K,V> map)
-
mapOf
@Nonnull public static <K,V> UnmodifiableMap<K,V> mapOf()
-
mapOf
public static <K,V> UnmodifiableMap<K,V> mapOf(@Nonnull K key, @Nonnull V value)
-
mapOf
public static <K,V> UnmodifiableMap<K,V> mapOf(@Nonnull K k1, @Nonnull V v1, @Nonnull K k2, @Nonnull V v2)
-
mapOf
public static <K,V> UnmodifiableMap<K,V> mapOf(@Nonnull K k1, @Nonnull V v1, @Nonnull K k2, @Nonnull V v2, @Nonnull K k3, @Nonnull V v3)
-
mapOf
public static <K,V> UnmodifiableMap<K,V> mapOf(@Nonnull K k1, @Nonnull V v1, @Nonnull K k2, @Nonnull V v2, @Nonnull K k3, @Nonnull V v3, @Nonnull K k4, @Nonnull V v4)
-
mapOf
public static <K,V> UnmodifiableMap<K,V> mapOf(@Nonnull K k1, @Nonnull V v1, @Nonnull K k2, @Nonnull V v2, @Nonnull K k3, @Nonnull V v3, @Nonnull K k4, @Nonnull V v4, @Nonnull K k5, @Nonnull V v5)
-
mapOf
public static <K,V> UnmodifiableMap<K,V> mapOf(@Nonnull K k1, @Nonnull V v1, @Nonnull K k2, @Nonnull V v2, @Nonnull K k3, @Nonnull V v3, @Nonnull K k4, @Nonnull V v4, @Nonnull K k5, @Nonnull V v5, @Nonnull K k6, @Nonnull V v6)
-
mapOf
public static <K,V> UnmodifiableMap<K,V> mapOf(@Nonnull K k1, @Nonnull V v1, @Nonnull K k2, @Nonnull V v2, @Nonnull K k3, @Nonnull V v3, @Nonnull K k4, @Nonnull V v4, @Nonnull K k5, @Nonnull V v5, @Nonnull K k6, @Nonnull V v6, @Nonnull K k7, @Nonnull V v7)
-
mapOf
public static <K,V> UnmodifiableMap<K,V> mapOf(@Nonnull K k1, @Nonnull V v1, @Nonnull K k2, @Nonnull V v2, @Nonnull K k3, @Nonnull V v3, @Nonnull K k4, @Nonnull V v4, @Nonnull K k5, @Nonnull V v5, @Nonnull K k6, @Nonnull V v6, @Nonnull K k7, @Nonnull V v7, @Nonnull K k8, @Nonnull V v8)
-
mapOf
public static <K,V> UnmodifiableMap<K,V> mapOf(@Nonnull K k1, @Nonnull V v1, @Nonnull K k2, @Nonnull V v2, @Nonnull K k3, @Nonnull V v3, @Nonnull K k4, @Nonnull V v4, @Nonnull K k5, @Nonnull V v5, @Nonnull K k6, @Nonnull V v6, @Nonnull K k7, @Nonnull V v7, @Nonnull K k8, @Nonnull V v8, @Nonnull K k9, @Nonnull V v9)
-
mapOf
public static <K,V> UnmodifiableMap<K,V> mapOf(@Nonnull K k1, @Nonnull V v1, @Nonnull K k2, @Nonnull V v2, @Nonnull K k3, @Nonnull V v3, @Nonnull K k4, @Nonnull V v4, @Nonnull K k5, @Nonnull V v5, @Nonnull K k6, @Nonnull V v6, @Nonnull K k7, @Nonnull V v7, @Nonnull K k8, @Nonnull V v8, @Nonnull K k9, @Nonnull V v9, @Nonnull K k10, @Nonnull V v10)
-
builder
public static <K,V> UnmodifiableMap.Builder<K,V> builder()
-
builder
public static <K,V> UnmodifiableMap.Builder<K,V> builder(int initialCapacity)
-
containsKey
public boolean containsKey(java.lang.Object o)
-
makeKeySet
@Nonnull protected java.util.Set<K> makeKeySet()
-
orderedBy
public UnmodifiableSortedMap<K,V> orderedBy(@Nonnull java.util.Comparator<K> comparator)
Get the map as a sorted map ordered by the specific comparator.- Parameters:
comparator
- The comparator to make the map sorted for.- Returns:
- The sorted map.
-
size
public int size()
- Specified by:
size
in interfacejava.util.Map<K,V>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfacejava.util.Map<K,V>
-
containsValue
public boolean containsValue(java.lang.Object o)
- Specified by:
containsValue
in interfacejava.util.Map<K,V>
-
keySet
@Nonnull public java.util.Set<K> keySet()
- Specified by:
keySet
in interfacejava.util.Map<K,V>
-
values
@Nonnull public java.util.Collection<V> values()
- Specified by:
values
in interfacejava.util.Map<K,V>
-
entrySet
@Nonnull public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
- Specified by:
entrySet
in interfacejava.util.Map<K,V>
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfacejava.util.Map<K,V>
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Specified by:
equals
in interfacejava.util.Map<K,V>
- Overrides:
equals
in classjava.lang.Object
-
put
public V put(K k, V v)
- Specified by:
put
in interfacejava.util.Map<K,V>
-
remove
public V remove(java.lang.Object o)
- Specified by:
remove
in interfacejava.util.Map<K,V>
-
putAll
public void putAll(@Nonnull java.util.Map<? extends K,? extends V> map)
- Specified by:
putAll
in interfacejava.util.Map<K,V>
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Map<K,V>
-
entry
protected static <K,V> java.util.Map.Entry<K,V> entry(@Nonnull K key, @Nonnull V value)
-
-