Package Torello.Java.ReadOnly
Interface ReadOnlyMap<K,V>
-
- Type Parameters:
K- the type of keys maintained by this mapV- the type of mapped values
- All Known Subinterfaces:
ReadOnlyNavigableMap<K,V>,ReadOnlySequencedMap<K,V>,ReadOnlySortedMap<K,V>
- All Known Implementing Classes:
ReadOnlyHashMap,ReadOnlyHashtable,ReadOnlyProperties,ReadOnlyTreeMap
public interface ReadOnlyMap<K,V>
This interface was originally copied fromGitHub's Open-JDKAccount. Though the original file has been modified, few changes have been applied to the Javadoc Commenting. Due to fact that that is a Javainterfacefile, there were few method bodies with Source-Code to begin with - meaning this is largely a copy of Method-Signatures and Java-Doc Comments.
Method and parameter names & types have not been modified whatsoever; but several methods had to be eliminated for not being Read-Only. This Source-File was copied from the original Open JDK-21 file of the same (or, rather, highly similar) Interface-Name. The original file may be viewed on theJDK-21 GitHubpublic (and, coincidentally, Read-Only) Source-Release archive for Java Packagejava.util.*
The Original'.java'Source-File's Header-Copyright Information is included here:File Copyright. Within that Copyright Notice, it is suggested that a copy of theGNU Public License V2also be included alongside.Immutable variant of Java Collections Framework interfacejava.util.Map<K, V>. This interface contains all of the methods that the standard Java interface ReadOnlyMap contains - except those which would directly or indirectly modify / mutate the internal data-structure.
Hi-Lited Source-Code:- View Here: Torello/Java/ReadOnly/ReadOnlyMap.java
- Open New Browser-Tab: Torello/Java/ReadOnly/ReadOnlyMap.java
File Size: 48,130 Bytes Line Count: 1,192 '\n' Characters Found
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface static interfaceReadOnlyMap.Entry<K,V>
-
Method Summary
Retrieve a Map Value Modifier and Type Method Vget(Object key)Retrieve a Set of all Map Keys Modifier and Type Method ReadOnlySet<K>keySet()Retrieve a Collection of all Map Values Modifier and Type Method ReadOnlyCollection<V>values()Check this Map's Contents Modifier and Type Method booleancontainsKey(Object key)booleancontainsValue(Object value)booleanisEmpty()intsize()Retrieve a Set of Key-Value Pairs Modifier and Type Method ReadOnlySet<ReadOnlyMap.Entry<K,
V>>entrySet()Convert 'this' to a Standard 'java.util' Collections-Framework Type Modifier and Type Method Map<K,V>cloneToMap()Map<K,V>wrapToImmutableMap()Static Methods: Builder's Modifier and Type Method static <K,V>
ReadOnlyMap<K,V>of()static <K,V>
ReadOnlyMap<K,V>of(K k1, V v1)static <K,V>
ReadOnlyMap<K,V>of(K k1, V v1, K k2, V v2)static <K,V>
ReadOnlyMap<K,V>of(K k1, V v1, K k2, V v2, K k3, V v3)static <K,V>
ReadOnlyMap<K,V>of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)static <K,V>
ReadOnlyMap<K,V>of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5)static <K,V>
ReadOnlyMap<K,V>of(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>
ReadOnlyMap<K,V>of(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>
ReadOnlyMap<K,V>of(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>
ReadOnlyMap<K,V>of(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>
ReadOnlyMap<K,V>of(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)Static Methods: Builders that utilize inner-class 'Entry' Modifier and Type Method static <K,
V>
ReadOnlyMap.Entry<K,
V>entry(K k, V v)static <K,V>
ReadOnlyMap<K,V>ofEntries(ReadOnlyMap.Entry<? extends K,? extends V>... entries)Default Methods (Interface Methods with a Concrete, Default Implementation) Modifier and Type Method default voidcopyIntoMap(Map<? super K,? super V> map)default voidforEach(BiConsumer<? super K,? super V> action)default VgetOrDefault(Object key, V defaultValue)Default Methods: VarArgs Input, Keys - AND, NAND, OR & XOR Modifier and Type Method default booleancontainsKeyAND(Object... elements)default booleancontainsKeyNAND(Object... elements)default booleancontainsKeyOR(Object... elements)default booleancontainsKeyXOR(Object... elements)Default Methods: Iterable Input, Keys - AND, NAND, OR & XOR Modifier and Type Method default booleancontainsKeyAND(Iterable<?> i)default booleancontainsKeyNAND(Iterable<?> i)default booleancontainsKeyOR(Iterable<?> i)default booleancontainsKeyXOR(Iterable<?> i)Default Methods: VarArgs Input, Values - AND, NAND, OR & XOR Modifier and Type Method default booleancontainsValueAND(Object... elements)default booleancontainsValueNAND(Object... elements)default booleancontainsValueOR(Object... elements)default booleancontainsValueXOR(Object... elements)Default Methods: Iterable Input, Values - AND, NAND, OR & XOR Modifier and Type Method default booleancontainsValueAND(Iterable<?> i)default booleancontainsValueNAND(Iterable<?> i)default booleancontainsValueOR(Iterable<?> i)default booleancontainsValueXOR(Iterable<?> i)Methods: class java.lang.Object Modifier and Type Method booleanequals(Object o)inthashCode()
-
-
-
Method Detail
-
size
int size()
Returns the number of key-value mappings in this map. If the map contains more thanInteger.MAX_VALUEelements, returnsInteger.MAX_VALUE.- Returns:
- the number of key-value mappings in this map
-
isEmpty
boolean isEmpty()
ReturnsTRUEif this map contains no key-value mappings.- Returns:
TRUEif this map contains no key-value mappings
-
containsKey
boolean containsKey(java.lang.Object key)
ReturnsTRUEif this map contains a mapping for the specified key. More formally, returnsTRUEif and only if this map contains a mapping for a keyksuch thatObjects.equals(key, k). (There can be at most one such mapping.)- Parameters:
key- key whose presence in this map is to be tested- Returns:
TRUEif this map contains a mapping for the specified key- Throws:
java.lang.ClassCastException- if the key is of an inappropriate type for this map (optional-restrictions)java.lang.NullPointerException- if the specified key is null and this map does not permit null keys (optional-restrictions)
-
containsValue
boolean containsValue(java.lang.Object value)
ReturnsTRUEif this map maps one or more keys to the specified value. More formally, returnsTRUEif and only if this map contains at least one mapping to a valuevsuch thatObjects.equals(value, v). This operation will probably require time linear in the map size for most implementations of theMapinterface.- Parameters:
value- value whose presence in this map is to be tested- Returns:
TRUEif this map maps one or more keys to the specified value- Throws:
java.lang.ClassCastException- if the value is of an inappropriate type for this map (optional-restrictions)java.lang.NullPointerException- if the specified value is null and this map does not permit null values (optional-restrictions)
-
get
V get(java.lang.Object key)
Returns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.
More formally, if this map contains a mapping from a keykto a valuevsuch thatObjects.equals(key, k), then this method returnsv; otherwise it returnsnull. (There can be at most one such mapping.)
If this map permits null values, then a return value ofnulldoes not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key tonull. ThecontainsKeyoperation may be used to distinguish these two cases.- Parameters:
key- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped, or
nullif this map contains no mapping for the key - Throws:
java.lang.ClassCastException- if the key is of an inappropriate type for this map (optional-restrictions)java.lang.NullPointerException- if the specified key is null and this map does not permit null keys (optional-restrictions)
-
keySet
ReadOnlySet<K> keySet()
Returns aReadOnlySetview of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa.- Returns:
- a set view of the keys contained in this map
-
values
ReadOnlyCollection<V> values()
Returns aReadOnlyCollectionview of the values contained in this map.- Returns:
- a collection view of the values contained in this map
-
entrySet
ReadOnlySet<ReadOnlyMap.Entry<K,V>> entrySet()
Returns aReadOnlySetview of the mappings contained in this map.- Returns:
- a set view of the mappings contained in this map
-
cloneToMap
java.util.Map<K,V> cloneToMap()
Clones the internaljava.util.Maprepresentation, and returns it. This is the Top-Level Interface-Variant of this method. It returns the Interface-Implementationjava.util.Map.
Alternate Variant:
The four classes which implement the interfaceReadOnlyMap(which areReadOnlyHashMap,ReadOnlyTreeMap,ReadOnlyHashtableandReadOnlyProperties), for convenience, also implement an identical "Wrap To" Method which returns the exact type of the internalMaprepresentation (which arejava.util.HashMap, java.util.TreeMap, java.util.Hashtableandjava.util.Properties) - rather than the Interface-Typejava.util.Map.- Returns:
- For the sub-class
ReadOnlyHashMap, this will return a cloned instance of the internaljava.util.HashMap.
- For the sub-class
ReadOnlyTreeMap, this will return a cloned instance of the internaljava.util.TreeMap.
- For the sub-class
ReadOnlyHashtable, this will return a cloned instance of the internaljava.util.Hashtable.
- For the sub-class
ReadOnlyProperties, this will return a cloned instance of the internaljava.util.Properties.
- For the sub-class
-
wrapToImmutableMap
java.util.Map<K,V> wrapToImmutableMap()
Invokesjava.util.Collections.unmodifiableMapon the internalMap
Standard JDKMap:
There may be situations where the TypeReadOnlyMapis simply not usable with an API that can't be adapted to accept Type's from the Java-HTMLReadOnlyPackage. If such a case arises, this method can be used to generate an immutable instance of a JDK-Standardjava.utilType, which does not inherit fromTorello.Java.ReadOnly
Classjava.util.Collectionsoffers a method that wraps a type into an Unmodifiable-Wrapper that implements the standardjava.util.Map, but throws an exception if any attempts are made to invoke Mutator-Methods.
Unmodifiable-Collections throw Exceptions instead:
The returnedjava.util.Mapinstance will hopefully provide an acceptable substitute whenReadOnlyType's cannot match an API's requirements. Java's Immutable-Wrappers work on a different principle - these classes retain any / all Mutator-Methods amongst their Type-Members, but instead throw anUnsupportedOperationExceptionif any of those methods are invoked!
Also, if a Java Collections FrameworkUnmodifiable-Class has any Member-Methods that return a "View" into the underlying Data-Structure, the Sub-Lists and Sub-Maps returned by those methods are also, subsequently, wrapped in anUnmodifiable-Wrapper. These returned instances will also throw anUnsupportedOperationExceptionif any of those methods are invoked!
This does provide a shield or layer of protection against modification to guarantee the "Immutability-Contract" offered by these classes, all-the-while returning to native Java API Collection Types, rather thanTorello.Java.ReadOnlyTypes, which may not always be compatible with a given API or Interface requirement!
Remember, many of the Data-Classes insidejava.utilhave methods whose documentation state very clearly that "any changes made the this [View] will be pushed back into the original type."- Returns:
- A
Setwhich adheres to the JDK interfacejava.util.Set, but throws anUnsupportedOperationExceptionif a user attempts to invoke a Mutator-Method on the returned instance.
-
equals
boolean equals(java.lang.Object o)
Compares the specified object with this map for equality. ReturnsTRUEif the given object is also a map and the two maps represent the same mappings. More formally, two mapsm1andm2represent the same mappings ifm1.entrySet().equals(m2.entrySet()). This ensures that theequalsmethod works properly across different implementations of theMapinterface.- Overrides:
equalsin classjava.lang.Object- Parameters:
o- object to be compared for equality with this map- Returns:
TRUEif the specified object is equal to this map
-
hashCode
int hashCode()
Returns the hash code value for this map. The hash code of a map is defined to be the sum of the hash codes of each entry in the map'sentrySet()view. This ensures thatm1.equals(m2)implies thatm1.hashCode()==m2.hashCode()for any two mapsm1andm2, as required by the general contract ofObject.hashCode.- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hash code value for this map
- See Also:
ReadOnlyMap.Entry.hashCode(),equals(Object)
-
getOrDefault
default V getOrDefault(java.lang.Object key, V defaultValue)
Returns the value to which the specified key is mapped, ordefaultValueif this map contains no mapping for the key.- Parameters:
key- the key whose associated value is to be returneddefaultValue- the default mapping of the key- Returns:
- the value to which the specified key is mapped, or
defaultValueif this map contains no mapping for the key - Throws:
java.lang.ClassCastException- if the key is of an inappropriate type for this map (optional-restrictions)java.lang.NullPointerException- if the specified key is null and this map does not permit null keys (optional-restrictions)- Code:
- Exact Method Body:
V v; return (((v = get(key)) != null) || containsKey(key)) ? v : defaultValue;
-
forEach
default void forEach (java.util.function.BiConsumer<? super K,? super V> action)
Performs the given action for each entry in this map until all entries have been processed or the action throws an exception. Unless otherwise specified by the implementing class, actions are performed in the order of entry set iteration (if an iteration order is specified.) Exceptions thrown by the action are relayed to the caller.
The default implementation is equivalent to, for thismap:
for (ReadOnlyMap.Entry<K, V> entry : map.entrySet()) action.accept(entry.getKey(), entry.getValue());
The default implementation makes no guarantees about synchronization or atomicity properties of this method. Any implementation providing atomicity guarantees must override this method and document its concurrency properties.- Parameters:
action- The action to be performed for each entry- Throws:
java.lang.NullPointerException- if the specified action is null- Code:
- Exact Method Body:
Objects.requireNonNull(action); for (ReadOnlyMap.Entry<K, V> entry : entrySet()) { K k; V v; try { k = entry.getKey(); v = entry.getValue(); } catch (IllegalStateException ise) { // this usually means the entry is no longer in the map. // throw new ConcurrentModificationException(ise); throw new Torello.Java.UnreachableError(); } action.accept(k, v); }
-
copyIntoMap
default void copyIntoMap(java.util.Map<? super K,? super V> map)
Copies the contents of'this'ReadOnlyMap into the user-provided'map'. Utilizes thejava.util.Mapmethodput(K key, V value).- Parameters:
map- Any instance of java.util.Map- See Also:
forEach(BiConsumer)- Code:
- Exact Method Body:
this.forEach((K k, V v) -> map.put(k, v));
-
containsKeyAND
default boolean containsKeyAND(java.lang.Object... elements)
Checks to ensure that'this'instance ofReadOnlyMapcontains a matching key for every one of the elements in Var-Args Parameter'elements'- Parameters:
elements- a list of elements- Returns:
TRUEIf and only if'this'instance''keySet()'contains every element in'elements'- Code:
- Exact Method Body:
ReadOnlySet<K> keys = this.keySet(); for (Object elem : elements) if (! keys.contains(elem)) return false; return true;
-
containsKeyNAND
default boolean containsKeyNAND(java.lang.Object... elements)
Checks to ensure that'this'instance ofReadOnlyMapdoes not contain any key that matches any of the elements in Var-Args Parameter'elements'- Parameters:
elements- a list of elements- Returns:
TRUEIf and only if'this'instance''keySet()'contains none of the elements in'elements'- Code:
- Exact Method Body:
ReadOnlySet<K> keys = this.keySet(); for (Object elem : elements) if (keys.contains(elem)) return false; return true;
-
containsKeyOR
default boolean containsKeyOR(java.lang.Object... elements)
Checks to ensure that'this'instance ofReadOnlyMapcontains at least one key that matches at least one element in Var-Args Parameter'elements'- Parameters:
elements- a list of elements- Returns:
TRUEIf and only if'this'instance''keySet()'contains one or more of the elements in'elements'- Code:
- Exact Method Body:
ReadOnlySet<K> keys = this.keySet(); for (Object elem : elements) if (keys.contains(elem)) return true; return false;
-
containsKeyXOR
default boolean containsKeyXOR(java.lang.Object... elements)
Checks to ensure that'this'instance ofReadOnlyMapcontains exactly one key that matches an element in Var-Args Parameter'elements'- Parameters:
elements- a list of elements- Returns:
TRUEIf and only if'this'instance''keySet()'contains precisely one element that is also in'elements'- Code:
- Exact Method Body:
ReadOnlySet<K> keys = this.keySet(); boolean found = false; for (Object elem : elements) if (keys.contains(elem)) { if (found) return false; else found = true; } return found;
-
containsKeyAND
default boolean containsKeyAND(java.lang.Iterable<?> i)
Checks to ensure that'this'instance ofReadOnlyMapcontains a matching key for every one of the elements inIterableparameter'i'.- Parameters:
i- any JavaIterable- Returns:
TRUEIf and only if'this'instance''keySet()'contains every element in'i'- Code:
- Exact Method Body:
ReadOnlySet<K> keys = this.keySet(); for (Object o: i) if (! keys.contains(o)) return false; return true;
-
containsKeyNAND
default boolean containsKeyNAND(java.lang.Iterable<?> i)
Checks to ensure that'this'instance ofReadOnlyMapdoes not contain any key that matches any of the elements inIterableparameter'i'- Parameters:
i- any JavaIterable- Returns:
TRUEIf and only if'this'instance''keySet()'contains none of the elements in'i'- Code:
- Exact Method Body:
ReadOnlySet<K> keys = this.keySet(); for (Object o: i) if (keys.contains(o)) return false; return true;
-
containsKeyOR
default boolean containsKeyOR(java.lang.Iterable<?> i)
Checks to ensure that'this'instance ofReadOnlyMapcontains at least one key that matches at least one element inIterableparameter'i'- Parameters:
i- any JavaIterable- Returns:
TRUEIf and only if'this'instance''keySet()'contains one or more of the elements in'i'- Code:
- Exact Method Body:
ReadOnlySet<K> keys = this.keySet(); for (Object o: i) if (keys.contains(o)) return true; return false;
-
containsKeyXOR
default boolean containsKeyXOR(java.lang.Iterable<?> i)
Checks to ensure that'this'instance ofReadOnlyMapcontains exactly one key that matches an element inIterableparameter'i'- Parameters:
i- any JavaIterable- Returns:
TRUEIf and only if'this'instance''keySet()'contains precisely one element that is also in'i'- Code:
- Exact Method Body:
ReadOnlySet<K> keys = this.keySet(); boolean found = false; for (Object o: i) if (keys.contains(o)) { if (found) return false; else found = true; } return found;
-
containsValueAND
default boolean containsValueAND(java.lang.Object... elements)
Checks to ensure that'this'instance ofReadOnlyMapcontains a matching value for every one of the elements in Var-Args Parameter'elements'- Parameters:
elements- a list of elements- Returns:
TRUEIf and only if'this'instance''values()'contains every element in'elements'- Code:
- Exact Method Body:
ReadOnlyCollection<V> values = this.values(); for (Object elem : elements) if (! values.contains(elem)) return false; return true;
-
containsValueNAND
default boolean containsValueNAND(java.lang.Object... elements)
Checks to ensure that'this'instance ofReadOnlyMapdoes not contain any value that matches any of the elements in Var-Args Parameter'elements'- Parameters:
elements- a list of elements- Returns:
TRUEIf and only if'this'instance''values()'contains none of the elements in'elements'- Code:
- Exact Method Body:
ReadOnlyCollection<V> values = this.values(); for (Object elem : elements) if (values.contains(elem)) return false; return true;
-
containsValueOR
default boolean containsValueOR(java.lang.Object... elements)
Checks to ensure that'this'instance ofReadOnlyMapcontains at least one value that matches at least one element in Var-Args Parameter'elements'- Parameters:
elements- a list of elements- Returns:
TRUEIf and only if'this'instance''values()'contains one or more of the elements in'elements'- Code:
- Exact Method Body:
ReadOnlyCollection<V> values = this.values(); for (Object elem : elements) if (values.contains(elem)) return true; return false;
-
containsValueXOR
default boolean containsValueXOR(java.lang.Object... elements)
Checks to ensure that'this'instance ofReadOnlyMapcontains exactly one value that matches an element in Var-Args Parameter'elements'- Parameters:
elements- a list of elements- Returns:
TRUEIf and only if'this'instance''values()'contains precisely one element that is also in'elements'- Code:
- Exact Method Body:
ReadOnlyCollection<V> values = this.values(); boolean found = false; for (Object elem : elements) if (values.contains(elem)) { if (found) return false; else found = true; } return found;
-
containsValueAND
default boolean containsValueAND(java.lang.Iterable<?> i)
Checks to ensure that'this'instance ofReadOnlyMapcontains a matching value for every one of the elements inIterableparameter'i'- Parameters:
i- any JavaIterable- Returns:
TRUEIf and only if'this'instance''values()'contains every element in'i'- Code:
- Exact Method Body:
ReadOnlyCollection<V> values = this.values(); for (Object o: i) if (! values.contains(o)) return false; return true;
-
containsValueNAND
default boolean containsValueNAND(java.lang.Iterable<?> i)
Checks to ensure that'this'instance ofReadOnlyMapdoes not contain any value that matches any of the elements inIterableparameter'i'- Parameters:
i- any JavaIterable- Returns:
TRUEIf and only if'this'instance''values()'contains none of the elements in'i'- Code:
- Exact Method Body:
ReadOnlyCollection<V> values = this.values(); for (Object o: i) if (values.contains(o)) return false; return true;
-
containsValueOR
default boolean containsValueOR(java.lang.Iterable<?> i)
Checks to ensure that'this'instance ofReadOnlyMapcontains at least one value that matches at least one element inIterableparameter'i'- Parameters:
i- any JavaIterable- Returns:
TRUEIf and only if'this'instance''values()'contains one or more of the elements in'i'- Code:
- Exact Method Body:
ReadOnlyCollection<V> values = this.values(); for (Object o: i) if (values.contains(o)) return true; return false;
-
containsValueXOR
default boolean containsValueXOR(java.lang.Iterable<?> i)
Checks to ensure that'this'instance ofReadOnlyMapcontains exactly one value that matches an element inIterableparameter'i'- Parameters:
i- any JavaIterable- Returns:
TRUEIf and only if'this'instance''values()'contains precisely one element that is also in'i'- Code:
- Exact Method Body:
ReadOnlyCollection<V> values = this.values(); boolean found = false; for (Object o: i) if (values.contains(o)) { if (found) return false; else found = true; } return found;
-
of
static <K,V> ReadOnlyMap<K,V> of()
Returns an unmodifiable map containing zero mappings.- Type Parameters:
K- theMap's key typeV- theMap's value type- Returns:
- an empty
Map - Code:
- Exact Method Body:
return new JavaHTMLReadOnlyMap<>(Map.of());
-
of
static <K,V> ReadOnlyMap<K,V> of(K k1, V v1)
Returns an unmodifiable map containing a single mapping.- Type Parameters:
K- theMap's key typeV- theMap's value type- Parameters:
k1- the mapping's keyv1- the mapping's value- Returns:
- a
ReadOnlyMapcontaining the specified mapping - Throws:
java.lang.NullPointerException- if the key or the value isnull- Code:
- Exact Method Body:
return new JavaHTMLReadOnlyMap<>(Map.of(k1, v1));
-
of
static <K,V> ReadOnlyMap<K,V> of(K k1, V v1, K k2, V v2)
Returns an unmodifiable map containing two mappings.- Type Parameters:
K- theMap's key typeV- theMap's value type- Parameters:
k1- the first mapping's keyv1- the first mapping's valuek2- the second mapping's keyv2- the second mapping's value- Returns:
- a
ReadOnlyMapcontaining the specified mappings - Throws:
java.lang.IllegalArgumentException- if the keys are duplicatesjava.lang.NullPointerException- if any key or value isnull- Code:
- Exact Method Body:
return new JavaHTMLReadOnlyMap<>(Map.of(k1, v1, k2, v2));
-
of
static <K,V> ReadOnlyMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3)
Returns an unmodifiable map containing three mappings.- Type Parameters:
K- theMap's key typeV- theMap's value type- Parameters:
k1- the first mapping's keyv1- the first mapping's valuek2- the second mapping's keyv2- the second mapping's valuek3- the third mapping's keyv3- the third mapping's value- Returns:
- a
ReadOnlyMapcontaining the specified mappings - Throws:
java.lang.IllegalArgumentException- if there are any duplicate keysjava.lang.NullPointerException- if any key or value isnull- Code:
- Exact Method Body:
return new JavaHTMLReadOnlyMap<>(Map.of(k1, v1, k2, v2, k3, v3));
-
of
static <K,V> ReadOnlyMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)
Returns an unmodifiable map containing four mappings.- Type Parameters:
K- theMap's key typeV- theMap's value type- Parameters:
k1- the first mapping's keyv1- the first mapping's valuek2- the second mapping's keyv2- the second mapping's valuek3- the third mapping's keyv3- the third mapping's valuek4- the fourth mapping's keyv4- the fourth mapping's value- Returns:
- a
ReadOnlyMapcontaining the specified mappings - Throws:
java.lang.IllegalArgumentException- if there are any duplicate keysjava.lang.NullPointerException- if any key or value isnull- Code:
- Exact Method Body:
return new JavaHTMLReadOnlyMap<>(Map.of(k1, v1, k2, v2, k3, v3, k4, v4));
-
of
static <K,V> ReadOnlyMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5)
Returns an unmodifiable map containing five mappings.- Type Parameters:
K- theMap's key typeV- theMap's value type- Parameters:
k1- the first mapping's keyv1- the first mapping's valuek2- the second mapping's keyv2- the second mapping's valuek3- the third mapping's keyv3- the third mapping's valuek4- the fourth mapping's keyv4- the fourth mapping's valuek5- the fifth mapping's keyv5- the fifth mapping's value- Returns:
- a
ReadOnlyMapcontaining the specified mappings - Throws:
java.lang.IllegalArgumentException- if there are any duplicate keysjava.lang.NullPointerException- if any key or value isnull- Code:
- Exact Method Body:
return new JavaHTMLReadOnlyMap<>(Map.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5));
-
of
static <K,V> ReadOnlyMap<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6)
Returns an unmodifiable map containing six mappings.- Type Parameters:
K- theMap's key typeV- theMap's value type- Parameters:
k1- the first mapping's keyv1- the first mapping's valuek2- the second mapping's keyv2- the second mapping's valuek3- the third mapping's keyv3- the third mapping's valuek4- the fourth mapping's keyv4- the fourth mapping's valuek5- the fifth mapping's keyv5- the fifth mapping's valuek6- the sixth mapping's keyv6- the sixth mapping's value- Returns:
- a
ReadOnlyMapcontaining the specified mappings - Throws:
java.lang.IllegalArgumentException- if there are any duplicate keysjava.lang.NullPointerException- if any key or value isnull- Code:
- Exact Method Body:
return new JavaHTMLReadOnlyMap<> (Map.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6));
-
of
static <K,V> ReadOnlyMap<K,V> of(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)
Returns an unmodifiable map containing seven mappings.- Type Parameters:
K- theMap's key typeV- theMap's value type- Parameters:
k1- the first mapping's keyv1- the first mapping's valuek2- the second mapping's keyv2- the second mapping's valuek3- the third mapping's keyv3- the third mapping's valuek4- the fourth mapping's keyv4- the fourth mapping's valuek5- the fifth mapping's keyv5- the fifth mapping's valuek6- the sixth mapping's keyv6- the sixth mapping's valuek7- the seventh mapping's keyv7- the seventh mapping's value- Returns:
- a
ReadOnlyMapcontaining the specified mappings - Throws:
java.lang.IllegalArgumentException- if there are any duplicate keysjava.lang.NullPointerException- if any key or value isnull- Code:
- Exact Method Body:
return new JavaHTMLReadOnlyMap<> (Map.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7));
-
of
static <K,V> ReadOnlyMap<K,V> of(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)
Returns an unmodifiable map containing eight mappings.- Type Parameters:
K- theMap's key typeV- theMap's value type- Parameters:
k1- the first mapping's keyv1- the first mapping's valuek2- the second mapping's keyv2- the second mapping's valuek3- the third mapping's keyv3- the third mapping's valuek4- the fourth mapping's keyv4- the fourth mapping's valuek5- the fifth mapping's keyv5- the fifth mapping's valuek6- the sixth mapping's keyv6- the sixth mapping's valuek7- the seventh mapping's keyv7- the seventh mapping's valuek8- the eighth mapping's keyv8- the eighth mapping's value- Returns:
- a
ReadOnlyMapcontaining the specified mappings - Throws:
java.lang.IllegalArgumentException- if there are any duplicate keysjava.lang.NullPointerException- if any key or value isnull- Code:
- Exact Method Body:
return new JavaHTMLReadOnlyMap<> (Map.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8));
-
of
static <K,V> ReadOnlyMap<K,V> of(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)
Returns an unmodifiable map containing nine mappings.- Type Parameters:
K- theMap's key typeV- theMap's value type- Parameters:
k1- the first mapping's keyv1- the first mapping's valuek2- the second mapping's keyv2- the second mapping's valuek3- the third mapping's keyv3- the third mapping's valuek4- the fourth mapping's keyv4- the fourth mapping's valuek5- the fifth mapping's keyv5- the fifth mapping's valuek6- the sixth mapping's keyv6- the sixth mapping's valuek7- the seventh mapping's keyv7- the seventh mapping's valuek8- the eighth mapping's keyv8- the eighth mapping's valuek9- the ninth mapping's keyv9- the ninth mapping's value- Returns:
- a
ReadOnlyMapcontaining the specified mappings - Throws:
java.lang.IllegalArgumentException- if there are any duplicate keysjava.lang.NullPointerException- if any key or value isnull- Code:
- Exact Method Body:
return new JavaHTMLReadOnlyMap<> (Map.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9));
-
of
static <K,V> ReadOnlyMap<K,V> of(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)
Returns an unmodifiable map containing ten mappings.- Type Parameters:
K- theMap's key typeV- theMap's value type- Parameters:
k1- the first mapping's keyv1- the first mapping's valuek2- the second mapping's keyv2- the second mapping's valuek3- the third mapping's keyv3- the third mapping's valuek4- the fourth mapping's keyv4- the fourth mapping's valuek5- the fifth mapping's keyv5- the fifth mapping's valuek6- the sixth mapping's keyv6- the sixth mapping's valuek7- the seventh mapping's keyv7- the seventh mapping's valuek8- the eighth mapping's keyv8- the eighth mapping's valuek9- the ninth mapping's keyv9- the ninth mapping's valuek10- the tenth mapping's keyv10- the tenth mapping's value- Returns:
- a
ReadOnlyMapcontaining the specified mappings - Throws:
java.lang.IllegalArgumentException- if there are any duplicate keysjava.lang.NullPointerException- if any key or value isnull- Code:
- Exact Method Body:
return new JavaHTMLReadOnlyMap<>( Map.of( k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10 ));
-
ofEntries
@SafeVarargs tatic <K,V> ReadOnlyMap<K,V> ofEntries (ReadOnlyMap.Entry<? extends K,? extends V>... entries)
Returns an unmodifiable map containing keys and values extracted from the given entries. The entries themselves are not stored in the map.
It is convenient to create the map entries using theReadOnlyMap.entry()method. For example,
Example:
import static Torello.Java.ReadOnly.ReadOnlyMap.entry; ReadOnlyMap<Integer,String> map = ReadOnlyMap.ofEntries( entry(1, "a"), entry(2, "b"), entry(3, "c"), ... entry(26, "z"));
- Type Parameters:
K- theReadOnlyMap's key typeV- theReadOnlyMap's value type- Parameters:
entries-ReadOnlyMap.Entrys containing the keys and values from which the map is populated- Returns:
- a
ReadOnlyMapcontaining the specified mappings - Throws:
java.lang.IllegalArgumentException- if there are any duplicate keysjava.lang.NullPointerException- if any entry, key, or value isnull, or if theentriesarray isnull- See Also:
Map.entry()- Code:
- Exact Method Body:
// *** Java-HTML: This arbitrarily uses TreeMap ROTreeMapBuilder<K, V> b = new ROTreeMapBuilder<>(); for (ReadOnlyMap.Entry<? extends K, ? extends V> e : entries) b.put(e.getKey(), e.getValue()); return b.build();
-
entry
static <K,V> ReadOnlyMap.Entry<K,V> entry(K k, V v)
Returns an unmodifiableReadOnlyMap.Entrycontaining the given key and value. These entries are suitable for populatingReadOnlyMapinstances using theReadOnlyMap.ofEntries()method.- Type Parameters:
K- the key's typeV- the value's type- Parameters:
k- the keyv- the value- Returns:
- an
Entrycontaining the specified key and value - Throws:
java.lang.NullPointerException- if the key or value isnull- See Also:
Map.ofEntries()- Code:
- Exact Method Body:
// KeyValueHolder checks for nulls // return new KeyValueHolder<>(k, v); return new EntryImpl<>(Objects.requireNonNull(k), Objects.requireNonNull(v));
-
-