Class ObjectObjectOrderedMap<K,V>
- All Implemented Interfaces:
Arrangeable,Ordered<K>,Iterable<Map.Entry<K,,V>> Map<K,V>
- Direct Known Subclasses:
CaseInsensitiveOrderedMap,FilteredIterableOrderedMap,FilteredStringOrderedMap,IdentityObjectOrderedMap
ObjectObjectMap that also stores keys in an ObjectList using the insertion order. Null keys are not allowed. No
allocation is done except when growing the table size.
Iteration over the entrySet(), keySet(), and values() is ordered and faster than an unordered map. Keys
can also be accessed and the order changed using order(). There is some additional overhead for put and remove.
This class performs fast contains (typically O(1), worst case O(n) but that is rare in practice). Remove is somewhat slower due
to order(). Add may be slightly slower, depending on hash collisions. Hashcodes are rehashed to reduce
collisions and the need to resize. Load factors greater than 0.91 greatly increase the chances to resize to the next higher POT
size.
Unordered sets and maps are not designed to provide especially fast iteration. Iteration is faster with Ordered types like
ObjectOrderedSet and ObjectObjectOrderedMap.
You can customize most behavior of this map by extending it. ObjectObjectMap.place(Object) can be overridden to change how hashCodes
are calculated (which can be useful for types like StringBuilder that don't implement hashCode()), and
ObjectObjectMap.equate(Object, Object) can be overridden to change how equality is calculated.
This implementation uses linear probing with the backward shift algorithm for removal. It tries different hashes from a simple family, with the hash changing on resize. Linear probing continues to work even when all hashCodes collide; it just works more slowly in that case.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic classNested classes/interfaces inherited from class com.github.tommyettinger.ds.ObjectObjectMap
ObjectObjectMap.Entries<K,V>, ObjectObjectMap.Entry<K, V>, ObjectObjectMap.Keys<K, V>, ObjectObjectMap.MapIterator<K, V, I>, ObjectObjectMap.Values<K, V> Nested classes/interfaces inherited from interface com.github.tommyettinger.ds.Arrangeable
Arrangeable.ArrangeableList<T>Nested classes/interfaces inherited from interface com.github.tommyettinger.ds.Ordered
Ordered.OfBoolean, Ordered.OfByte, Ordered.OfChar, Ordered.OfDouble, Ordered.OfFloat, Ordered.OfInt, Ordered.OfLong, Ordered.OfShort -
Field Summary
FieldsFields inherited from class com.github.tommyettinger.ds.ObjectObjectMap
defaultValue, entries1, entries2, hashMultiplier, keys1, keys2, keyTable, loadFactor, mask, shift, size, threshold, values1, values2, valueTable -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new map with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor().ObjectObjectOrderedMap(int initialCapacity) Creates a new map with the given starting capacity and a load factor ofUtilities.getDefaultLoadFactor().ObjectObjectOrderedMap(int initialCapacity, float loadFactor) Creates a new map with the specified initial capacity and load factor.ObjectObjectOrderedMap(int initialCapacity, float loadFactor, OrderType ordering) Creates a new map with the specified initial capacity and load factor.ObjectObjectOrderedMap(int initialCapacity, OrderType ordering) Creates a new map with the given starting capacity and a load factor ofUtilities.getDefaultLoadFactor().ObjectObjectOrderedMap(ObjectObjectMap<? extends K, ? extends V> map) Creates a new map identical to the specified map.ObjectObjectOrderedMap(ObjectObjectMap<? extends K, ? extends V> map, OrderType ordering) Creates a new map identical to the specified map.ObjectObjectOrderedMap(ObjectObjectOrderedMap<? extends K, ? extends V> map) Creates a new map identical to the specified map.ObjectObjectOrderedMap(ObjectObjectOrderedMap<? extends K, ? extends V> other, int offset, int count) Creates a new set by copyingcountitems from the given ObjectObjectOrderedMap, starting atoffsetin that Map, into this.ObjectObjectOrderedMap(ObjectObjectOrderedMap<? extends K, ? extends V> other, int offset, int count, OrderType ordering) Creates a new set by copyingcountitems from the given ObjectObjectOrderedMap, starting atoffsetin that Map, into this.ObjectObjectOrderedMap(OrderType ordering) Creates a new map with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor().ObjectObjectOrderedMap(Collection<? extends K> keys, Collection<? extends V> values) Given two side-by-side collections, one of keys, one of values, this constructs a map and inserts each pair of key and value into it.ObjectObjectOrderedMap(Collection<? extends K> keys, Collection<? extends V> values, OrderType ordering) Given two side-by-side collections, one of keys, one of values, this constructs a map and inserts each pair of key and value into it.ObjectObjectOrderedMap(Map<? extends K, ? extends V> map) Creates a new map identical to the specified map.ObjectObjectOrderedMap(Map<? extends K, ? extends V> map, OrderType ordering) Creates a new map identical to the specified map.ObjectObjectOrderedMap(K[] keys, V[] values) Given two side-by-side arrays, one of keys, one of values, this constructs a map and inserts each pair of key and value into it.ObjectObjectOrderedMap(K[] keys, V[] values, OrderType ordering) Given two side-by-side arrays, one of keys, one of values, this constructs a map and inserts each pair of key and value into it. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChanges the keybeforetoafterwithout changing its position in the order or its value.booleanChanges the key at the givenindexin the order toafter, without changing the ordering of other entries or any values.appendTo(StringBuilder sb, String entrySeparator, String keyValueSeparator, boolean braces, Appender<K> keyAppender, Appender<V> valueAppender) voidclear()voidclear(int maximumCapacity) Clears the map and reduces the size of the backing arrays to be the specified capacity / loadFactor, if they are larger.voidensureCapacity(int additionalCapacity) Increases the size of the backing array to accommodate the specified number of additional items / loadFactor.entrySet()Returns a Set of Map.Entry, containing the entries in the map.getAt(int index) Gets the V value at the givenindexin the insertion order.iterator()Reuses the iterator of the reusedObjectObjectMap.Entriesproduced byentrySet(); does not permit nested iteration.keyAt(int index) Gets the K key at the givenindexin the insertion order.keySet()Returns aSetview of the keys contained in this map.order()Gets the ObjectList of keys in the order this class will iterate through them.static <K,V> ObjectObjectOrderedMap<K, V> parse(String str, String entrySeparator, String keyValueSeparator, PartialParser<K> keyParser, PartialParser<V> valueParser) Creates a new map by parsing all ofstrwith the given PartialParser for keys and for values, with entries separated byentrySeparator, such as", "and the keys separated from values bykeyValueSeparator, such as"=".static <K,V> ObjectObjectOrderedMap<K, V> parse(String str, String entrySeparator, String keyValueSeparator, PartialParser<K> keyParser, PartialParser<V> valueParser, boolean brackets) Creates a new map by parsing all ofstr(or ifbracketsis true, all but the first and last chars) with the given PartialParser for keys and for values, with entries separated byentrySeparator, such as", "and the keys separated from values bykeyValueSeparator, such as"=".static <K,V> ObjectObjectOrderedMap<K, V> parse(String str, String entrySeparator, String keyValueSeparator, PartialParser<K> keyParser, PartialParser<V> valueParser, int offset, int length) Creates a new map by parsing the given subrange ofstrwith the given PartialParser for keys and for values, with entries separated byentrySeparator, such as", "and the keys separated from values bykeyValueSeparator, such as"=".Returns the old value associated with the specified key, or this map'sObjectObjectMap.defaultValueif there was no prior value.Puts the given key and value into this map at the given index in its order.voidputAll(int insertionIndex, ObjectObjectOrderedMap<? extends K, ? extends V> other, int offset, int count) Adds up tocountentries, starting fromoffset, in the mapotherto this set, inserting starting atinsertionIndexin the iteration order.voidputAll(ObjectObjectOrderedMap<? extends K, ? extends V> map) Puts every key-value pair in the given map into this, with the values from the given map overwriting the previous values if two keys are identical.voidputAll(ObjectObjectOrderedMap<? extends K, ? extends V> other, int offset, int count) Adds up tocountentries, starting fromoffset, in the mapotherto this set, inserting at the end of the iteration order.putOrDefault(K key, V value, V defaultValue) removeAt(int index) Removes the entry at the given index in the order, returning the value of that entry.voidremoveRange(int start, int end) Removes the items between the specified start index, inclusive, and end index, exclusive.Changes the value at a specifiedindexin the iteration order tov, without changing keys at all.voidsort()Sorts this ObjectObjectOrderedMap in-place by the keys' natural ordering;Kmust implementComparable.voidsort(Comparator<? super K> comp) Sorts this ObjectObjectOrderedMap in-place by the given Comparator used on the keys.voidsortByValue(Comparator<V> comp) Sorts this ObjectObjectOrderedMap in-place by the given Comparator used on the values.voidtruncate(int newSize) Reduces the size of the map to the specified size.values()Returns a Collection for the values in the map.static <K,V> ObjectObjectOrderedMap<K, V> with()Constructs an empty map given the types as generic type arguments.static <K,V> ObjectObjectOrderedMap<K, V> with(K key0, V value0) Constructs a single-entry map given one key and one value.static <K,V> ObjectObjectOrderedMap<K, V> Constructs a map given alternating keys and values.static <K,V> ObjectObjectOrderedMap<K, V> with(K key0, V value0, K key1, V value1) Constructs a single-entry map given two key-value pairs.static <K,V> ObjectObjectOrderedMap<K, V> with(K key0, V value0, K key1, V value1, K key2, V value2) Constructs a single-entry map given three key-value pairs.static <K,V> ObjectObjectOrderedMap<K, V> with(K key0, V value0, K key1, V value1, K key2, V value2, K key3, V value3) Constructs a single-entry map given four key-value pairs.Methods inherited from class com.github.tommyettinger.ds.ObjectObjectMap
appendTo, combine, combine, containsKey, containsValue, containsValue, equals, equalsIdentity, equate, findKey, findKey, get, getDefaultValue, getHashMultiplier, getLoadFactor, getOrDefault, getTableSize, hashCode, isEmpty, locateKey, notEmpty, place, putAll, putAll, putAll, putAll, putAll, putAll, putLegible, putLegible, putLegible, putLegible, putPairs, putResize, replace, resize, setDefaultValue, setHashMultiplier, setLoadFactor, shrink, size, toString, toString, toString, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.github.tommyettinger.ds.Arrangeable
rearrange, shuffle, sizeMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, merge, putIfAbsent, remove, replace, replaceAllMethods inherited from interface com.github.tommyettinger.ds.Ordered
getOrderType, random, random, reverse, selectRanked, selectRankedIndex, shuffle, swap
-
Field Details
-
keys
-
-
Constructor Details
-
ObjectObjectOrderedMap
Creates a new map with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor().- Parameters:
ordering- determines what implementationorder()will use
-
ObjectObjectOrderedMap
Creates a new map with the given starting capacity and a load factor ofUtilities.getDefaultLoadFactor().- Parameters:
initialCapacity- If not a power of two, it is increased to the next nearest power of two.ordering- determines what implementationorder()will use
-
ObjectObjectOrderedMap
Creates a new map with the specified initial capacity and load factor. This map will hold initialCapacity items before growing the backing table.- Parameters:
initialCapacity- If not a power of two, it is increased to the next nearest power of two.loadFactor- what fraction of the capacity can be filled before this has to resize; 0 < loadFactor <= 1ordering- determines what implementationorder()will use
-
ObjectObjectOrderedMap
Creates a new map identical to the specified map.- Parameters:
map- the map to copyordering- determines what implementationorder()will use
-
ObjectObjectOrderedMap
Creates a new map identical to the specified map.- Parameters:
map- the map to copyordering- determines what implementationorder()will use
-
ObjectObjectOrderedMap
public ObjectObjectOrderedMap(ObjectObjectOrderedMap<? extends K, ? extends V> other, int offset, int count, OrderType ordering) Creates a new set by copyingcountitems from the given ObjectObjectOrderedMap, starting atoffsetin that Map, into this.- Parameters:
other- another ObjectObjectOrderedMap of the same typeoffset- the first index in other's ordering to draw an item fromcount- how many items to copy from otherordering- determines what implementationorder()will use
-
ObjectObjectOrderedMap
Given two side-by-side arrays, one of keys, one of values, this constructs a map and inserts each pair of key and value into it. If keys and values have different lengths, this only uses the length of the smaller array.- Parameters:
keys- an array of keysvalues- an array of valuesordering- determines what implementationorder()will use
-
ObjectObjectOrderedMap
public ObjectObjectOrderedMap(Collection<? extends K> keys, Collection<? extends V> values, OrderType ordering) Given two side-by-side collections, one of keys, one of values, this constructs a map and inserts each pair of key and value into it. If keys and values have different lengths, this only uses the length of the smaller collection.- Parameters:
keys- a Collection of keysvalues- a Collection of valuesordering- determines what implementationorder()will use
-
ObjectObjectOrderedMap
public ObjectObjectOrderedMap()Creates a new map with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor(). -
ObjectObjectOrderedMap
public ObjectObjectOrderedMap(int initialCapacity) Creates a new map with the given starting capacity and a load factor ofUtilities.getDefaultLoadFactor().- Parameters:
initialCapacity- If not a power of two, it is increased to the next nearest power of two.
-
ObjectObjectOrderedMap
public ObjectObjectOrderedMap(int initialCapacity, float loadFactor) Creates a new map with the specified initial capacity and load factor. This map will hold initialCapacity items before growing the backing table.- Parameters:
initialCapacity- If not a power of two, it is increased to the next nearest power of two.loadFactor- what fraction of the capacity can be filled before this has to resize; 0 < loadFactor <= 1
-
ObjectObjectOrderedMap
Creates a new map identical to the specified map.- Parameters:
map- the map to copy
-
ObjectObjectOrderedMap
public ObjectObjectOrderedMap(ObjectObjectOrderedMap<? extends K, ? extends V> other, int offset, int count) Creates a new set by copyingcountitems from the given ObjectObjectOrderedMap, starting atoffsetin that Map, into this.- Parameters:
other- another ObjectObjectOrderedMap of the same typeoffset- the first index in other's ordering to draw an item fromcount- how many items to copy from other
-
ObjectObjectOrderedMap
Creates a new map identical to the specified map.- Parameters:
map- the map to copy
-
ObjectObjectOrderedMap
Creates a new map identical to the specified map.- Parameters:
map- the map to copy
-
ObjectObjectOrderedMap
Given two side-by-side arrays, one of keys, one of values, this constructs a map and inserts each pair of key and value into it. If keys and values have different lengths, this only uses the length of the smaller array.- Parameters:
keys- an array of keysvalues- an array of values
-
ObjectObjectOrderedMap
Given two side-by-side collections, one of keys, one of values, this constructs a map and inserts each pair of key and value into it. If keys and values have different lengths, this only uses the length of the smaller collection.- Parameters:
keys- a Collection of keysvalues- a Collection of values
-
-
Method Details
-
put
Description copied from class:ObjectObjectMapReturns the old value associated with the specified key, or this map'sObjectObjectMap.defaultValueif there was no prior value. -
put
Puts the given key and value into this map at the given index in its order. If the key is already present at a different index, it is moved to the given index and its value is set to the given value.- Parameters:
key- a K key; must not be nullvalue- a V value; permitted to be nullindex- the index in the order to place the given key and value; must be non-negative and less thanObjectObjectMap.size()- Returns:
- the previous value associated with key, if there was one, or null otherwise
-
putOrDefault
- Overrides:
putOrDefaultin classObjectObjectMap<K,V>
-
putAll
Puts every key-value pair in the given map into this, with the values from the given map overwriting the previous values if two keys are identical. This will put keys in the order of the given map.- Parameters:
map- a map with compatible key and value types; will not be modified
-
putAll
Adds up tocountentries, starting fromoffset, in the mapotherto this set, inserting at the end of the iteration order.- Parameters:
other- a non-null ordered map with the same type and compatible generic typesoffset- the first index inotherto usecount- how many indices inotherto use
-
putAll
public void putAll(int insertionIndex, ObjectObjectOrderedMap<? extends K, ? extends V> other, int offset, int count) Adds up tocountentries, starting fromoffset, in the mapotherto this set, inserting starting atinsertionIndexin the iteration order.- Parameters:
insertionIndex- where to insert into the iteration orderother- a non-null ordered map with the same type and compatible generic typesoffset- the first index inotherto usecount- how many indices inotherto use
-
remove
-
removeAt
Removes the entry at the given index in the order, returning the value of that entry.- Parameters:
index- the index of the entry to remove; must be at least 0 and less thanObjectObjectMap.size()- Returns:
- the value of the removed entry
-
ensureCapacity
public void ensureCapacity(int additionalCapacity) Increases the size of the backing array to accommodate the specified number of additional items / loadFactor. Useful before adding many items to avoid multiple backing array resizes.- Overrides:
ensureCapacityin classObjectObjectMap<K,V> - Parameters:
additionalCapacity- how many additional items this should be able to hold without resizing (probably)
-
alter
Changes the keybeforetoafterwithout changing its position in the order or its value. Returns true ifafterhas been added to the ObjectObjectOrderedMap andbeforehas been removed; returns false ifafteris already present orbeforeis not present. If you are iterating over an ObjectObjectOrderedMap and have an index, you should preferalterAt(int, Object), which doesn't need to search for an index like this does and so can be faster.- Parameters:
before- a key that must be present for this to succeedafter- a key that must not be in this map for this to succeed- Returns:
- true if
beforewas removed andafterwas added, false otherwise
-
alterAt
Changes the key at the givenindexin the order toafter, without changing the ordering of other entries or any values. Ifafteris already present, this returns false; it will also return false ifindexis invalid for the size of this map. Otherwise, it returns true. Unlikealter(Object, Object), this operates in constant time.- Parameters:
index- the index in the order of the key to change; must be non-negative and less thanObjectObjectMap.sizeafter- the key that will replace the contents atindex; this key must not be present for this to succeed- Returns:
- true if
aftersuccessfully replaced the key atindex, false otherwise
-
setAt
Changes the value at a specifiedindexin the iteration order tov, without changing keys at all. Ifindexisn't currently a valid index in the iteration order, this returns null. Otherwise, it returns the value that was previously held atindex, which may also be null.- Parameters:
v- the new V value to assignindex- the index in the iteration order to setvat- Returns:
- the previous value held at
indexin the iteration order, which may be null if the value was null or ifindexwas invalid
-
getAt
Gets the V value at the givenindexin the insertion order. The index should be between 0 (inclusive) andObjectObjectMap.size()(exclusive).- Parameters:
index- an index in the insertion order, between 0 (inclusive) andObjectObjectMap.size()(exclusive)- Returns:
- the value at the given index
-
keyAt
Gets the K key at the givenindexin the insertion order. The index should be between 0 (inclusive) andObjectObjectMap.size()(exclusive).- Parameters:
index- an index in the insertion order, between 0 (inclusive) andObjectObjectMap.size()(exclusive)- Returns:
- the key at the given index
-
clear
public void clear(int maximumCapacity) Description copied from class:ObjectObjectMapClears the map and reduces the size of the backing arrays to be the specified capacity / loadFactor, if they are larger.- Overrides:
clearin classObjectObjectMap<K,V>
-
clear
public void clear() -
order
Gets the ObjectList of keys in the order this class will iterate through them. Returns a direct reference to the same ObjectList this uses, so changes to the returned list will also change the iteration order here. -
sort
public void sort()Sorts this ObjectObjectOrderedMap in-place by the keys' natural ordering;Kmust implementComparable. -
sort
Sorts this ObjectObjectOrderedMap in-place by the given Comparator used on the keys. Ifcompis null, then this will sort by the natural ordering of the keys, which requiresKtoComparable. -
sortByValue
Sorts this ObjectObjectOrderedMap in-place by the given Comparator used on the values.compmust be able to compareVvalues. If any null values are present in this ObjectObjectOrderedMap, then comp must be able to sort or otherwise handle null values. You can use passnullto do whatsort()does when given null (just sorting values in this case instead of keys) if the values implementComparable(requiring all of them to be non-null).- Parameters:
comp- a Comparator that can compareVvalues; may be null to use natural order of Comparable values
-
removeRange
public void removeRange(int start, int end) Removes the items between the specified start index, inclusive, and end index, exclusive. Note that this takes different arguments than some other range-related methods; this needs a start index and an end index, rather than a count of items. This matches the behavior in the JDK collections.- Specified by:
removeRangein interfaceOrdered<K>- Parameters:
start- the first index to remove, inclusiveend- the last index (after what should be removed), exclusive
-
truncate
public void truncate(int newSize) Reduces the size of the map to the specified size. If the map is already smaller than the specified size, no action is taken.- Overrides:
truncatein classObjectObjectMap<K,V> - Parameters:
newSize- the target size to try to reach by removing items, if smaller than the current size
-
keySet
Returns aSetview 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. If the map is modified while an iteration over the set is in progress (except through the iterator's ownremoveoperation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via theIterator.remove,Set.remove,removeAll,retainAll, andclearoperations. It does not support theaddoraddAlloperations.Note that the same Collection instance is returned each time this method is called. Use the
OrderedMapKeys(ObjectObjectOrderedMap)constructor for nested or multithreaded iteration. -
values
Returns a Collection for the values in the map. Remove is supported by the Collection's iterator.Note that the same Collection instance is returned each time this method is called. Use the
OrderedMapValues(ObjectObjectOrderedMap)constructor for nested or multithreaded iteration.- Specified by:
valuesin interfaceMap<K,V> - Overrides:
valuesin classObjectObjectMap<K,V> - Returns:
- a
Collectionof V values
-
entrySet
Returns a Set of Map.Entry, containing the entries in the map. Remove is supported by the Set's iterator.Note that the same iterator instance is returned each time this method is called. Use the
OrderedMapEntries(ObjectObjectOrderedMap)constructor for nested or multithreaded iteration. -
iterator
Reuses the iterator of the reusedObjectObjectMap.Entriesproduced byentrySet(); does not permit nested iteration. Iterate overOrderedMapEntries(ObjectObjectOrderedMap)if you need nested or multithreaded iteration. You can remove an Entry from this ObjectObjectOrderedMap using this Iterator. -
appendTo
public StringBuilder appendTo(StringBuilder sb, String entrySeparator, String keyValueSeparator, boolean braces, Appender<K> keyAppender, Appender<V> valueAppender) Appends to a StringBuilder from the contents of this ObjectObjectOrderedMap, but uses the givenAppenderandAppenderto convert each key and each value to a customizable representation and append them to a StringBuilder. To use the default String representation, you can useAppender::appendas an appender.- Overrides:
appendToin classObjectObjectMap<K,V> - Parameters:
sb- a StringBuilder that this can append toentrySeparator- how to separate entries, such as", "keyValueSeparator- how to separate each key from its value, such as"="or":"braces- true to wrap the output in curly braces, or false to omit themkeyAppender- a function that takes a StringBuilder and a K, and returns the modified StringBuildervalueAppender- a function that takes a StringBuilder and a V, and returns the modified StringBuilder- Returns:
sb, with the appended keys and values of this map
-
with
Constructs an empty map given the types as generic type arguments. This is usually less useful than just using the constructor, but can be handy in some code-generation scenarios when you don't know how many arguments you will have.- Type Parameters:
K- the type of keysV- the type of values- Returns:
- a new map containing nothing
-
with
Constructs a single-entry map given one key and one value. This is mostly useful as an optimization forwith(Object, Object, Object...)when there's no "rest" of the keys or values.- Type Parameters:
K- the type of key0V- the type of value0- Parameters:
key0- the first and only keyvalue0- the first and only value- Returns:
- a new map containing just the entry mapping key0 to value0
-
with
Constructs a single-entry map given two key-value pairs. This is mostly useful as an optimization forwith(Object, Object, Object...)when there's no "rest" of the keys or values.- Type Parameters:
K- the type of key0V- the type of value0- Parameters:
key0- a K keyvalue0- a V valuekey1- a K keyvalue1- a V value- Returns:
- a new map containing entries mapping each key to the following value
-
with
public static <K,V> ObjectObjectOrderedMap<K,V> with(K key0, V value0, K key1, V value1, K key2, V value2) Constructs a single-entry map given three key-value pairs. This is mostly useful as an optimization forwith(Object, Object, Object...)when there's no "rest" of the keys or values.- Type Parameters:
K- the type of key0V- the type of value0- Parameters:
key0- a K keyvalue0- a V valuekey1- a K keyvalue1- a V valuekey2- a K keyvalue2- a V value- Returns:
- a new map containing entries mapping each key to the following value
-
with
public static <K,V> ObjectObjectOrderedMap<K,V> with(K key0, V value0, K key1, V value1, K key2, V value2, K key3, V value3) Constructs a single-entry map given four key-value pairs. This is mostly useful as an optimization forwith(Object, Object, Object...)when there's no "rest" of the keys or values.- Type Parameters:
K- the type of key0V- the type of value0- Parameters:
key0- a K keyvalue0- a V valuekey1- a K keyvalue1- a V valuekey2- a K keyvalue2- a V valuekey3- a K keyvalue3- a V value- Returns:
- a new map containing entries mapping each key to the following value
-
with
Constructs a map given alternating keys and values. This can be useful in some code-generation scenarios, or when you want to make a map conveniently by-hand and have it populated at the start. You can also useObjectObjectOrderedMap(Object[], Object[]), which takes all keys and then all values. This needs all keys to have the same type and all values to have the same type, because it gets those types from the first key parameter and first value parameter. Any keys that don't have K as their type or values that don't have V as their type have that entry skipped.- Type Parameters:
K- the type of keys, inferred from key0V- the type of values, inferred from value0- Parameters:
key0- the first key; will be used to determine the type of all keysvalue0- the first value; will be used to determine the type of all valuesrest- a varargs or non-null array of alternating K, V, K, V... elements- Returns:
- a new map containing the given keys and values
-
parse
public static <K,V> ObjectObjectOrderedMap<K,V> parse(String str, String entrySeparator, String keyValueSeparator, PartialParser<K> keyParser, PartialParser<V> valueParser) Creates a new map by parsing all ofstrwith the given PartialParser for keys and for values, with entries separated byentrySeparator, such as", "and the keys separated from values bykeyValueSeparator, such as"=".
VariousPartialParserinstances are defined as constants, such asPartialParser.DEFAULT_STRING, and others can be created by static methods in PartialParser, such asPartialParser.objectListParser(PartialParser, String, boolean).- Parameters:
str- a String containing parseable textentrySeparator- the String separating every key-value pairkeyValueSeparator- the String separating every key from its corresponding valuekeyParser- a PartialParser that returns aKkey from a section ofstrvalueParser- a PartialParser that returns aVvalue from a section ofstr
-
parse
public static <K,V> ObjectObjectOrderedMap<K,V> parse(String str, String entrySeparator, String keyValueSeparator, PartialParser<K> keyParser, PartialParser<V> valueParser, boolean brackets) Creates a new map by parsing all ofstr(or ifbracketsis true, all but the first and last chars) with the given PartialParser for keys and for values, with entries separated byentrySeparator, such as", "and the keys separated from values bykeyValueSeparator, such as"=".
VariousPartialParserinstances are defined as constants, such asPartialParser.DEFAULT_STRING, and others can be created by static methods in PartialParser, such asPartialParser.objectListParser(PartialParser, String, boolean).- Parameters:
str- a String containing parseable textentrySeparator- the String separating every key-value pairkeyValueSeparator- the String separating every key from its corresponding valuekeyParser- a PartialParser that returns aKkey from a section ofstrvalueParser- a PartialParser that returns aVvalue from a section ofstrbrackets- if true, the first and last chars instrwill be ignored
-
parse
public static <K,V> ObjectObjectOrderedMap<K,V> parse(String str, String entrySeparator, String keyValueSeparator, PartialParser<K> keyParser, PartialParser<V> valueParser, int offset, int length) Creates a new map by parsing the given subrange ofstrwith the given PartialParser for keys and for values, with entries separated byentrySeparator, such as", "and the keys separated from values bykeyValueSeparator, such as"=".
VariousPartialParserinstances are defined as constants, such asPartialParser.DEFAULT_STRING, and others can be created by static methods in PartialParser, such asPartialParser.objectListParser(PartialParser, String, boolean).- Parameters:
str- a String containing parseable textentrySeparator- the String separating every key-value pairkeyValueSeparator- the String separating every key from its corresponding valuekeyParser- a PartialParser that returns aKkey from a section ofstrvalueParser- a PartialParser that returns aVvalue from a section ofstroffset- the first position to read parseable text from instrlength- how many chars to read; -1 is treated as maximum length
-