Class LongLongOrderedMap
- All Implemented Interfaces:
Arrangeable,Ordered.OfLong,Iterable<LongLongMap.Entry>
LongLongMap that also stores keys in a LongList using the insertion order. 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 LongLongOrderedMap.
You can customize most behavior of this map by extending it. LongLongMap.place(long) can be overridden to change how hashCodes
are calculated (which can be useful for types like StringBuilder that don't implement hashCode()), and
LongLongMap.locateKey(long) 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, just more slowly.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic classNested classes/interfaces inherited from class com.github.tommyettinger.ds.LongLongMap
LongLongMap.Entries, LongLongMap.Entry, LongLongMap.EntryIterator, LongLongMap.KeyIterator, LongLongMap.Keys, LongLongMap.MapIterator, LongLongMap.ValueIterator, LongLongMap.ValuesNested classes/interfaces inherited from interface com.github.tommyettinger.ds.Arrangeable
Arrangeable.ArrangeableList<T> -
Field Summary
FieldsFields inherited from class com.github.tommyettinger.ds.LongLongMap
defaultValue, entries1, entries2, hashMultiplier, hasZeroValue, keys1, keys2, keyTable, loadFactor, mask, shift, size, threshold, values1, values2, valueTable, zeroValue -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new map with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor().LongLongOrderedMap(int initialCapacity) Creates a new map with the given starting capacity and a load factor ofUtilities.getDefaultLoadFactor().LongLongOrderedMap(int initialCapacity, float loadFactor) Creates a new map with the specified initial capacity and load factor.LongLongOrderedMap(int initialCapacity, float loadFactor, OrderType ordering) Creates a new map with the specified initial capacity and load factor.LongLongOrderedMap(int initialCapacity, OrderType ordering) Creates a new map with the given starting capacity and a load factor ofUtilities.getDefaultLoadFactor().LongLongOrderedMap(long[] keys, long[] 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.LongLongOrderedMap(long[] keys, long[] 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.Creates a new map identical to the specified map.LongLongOrderedMap(LongLongMap map, OrderType ordering) Creates a new map identical to the specified map.Creates a new map identical to the specified map.LongLongOrderedMap(LongLongOrderedMap other, int offset, int count) Creates a new set by copyingcountitems from the given LongLongOrderedMap, starting atoffsetin that Map, into this.LongLongOrderedMap(LongLongOrderedMap other, int offset, int count, OrderType ordering) Creates a new set by copyingcountitems from the given LongLongOrderedMap, starting atoffsetin that Map, into this.LongLongOrderedMap(OrderType ordering) Creates a new map with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor().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.LongLongOrderedMap(PrimitiveCollection.OfLong keys, PrimitiveCollection.OfLong 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. -
Method Summary
Modifier and TypeMethodDescriptionbooleanalter(long before, long after) Changes the keybeforetoafterwithout changing its position in the order or its value.booleanalterAt(int index, long after) Changes 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, LongAppender keyAppender, LongAppender valueAppender) Appends to a StringBuilder from the contents of this LongLongOrderedMap, but uses the givenLongAppenderandLongAppenderto convert each key and each value to a customizable representation and append them to a StringBuilder.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 aPrimitiveCollection.OfLongofLongLongMap.Entry, containing the entries in the map.longgetAndIncrement(long key, long defaultValue, long increment) Returns the key's current value and increments the stored value.longgetAt(int index) Gets the long value at the givenindexin the insertion order.iterator()Reuses the iterator of the reusedLongLongMap.Entriesproduced byentrySet(); does not permit nested iteration.longkeyAt(int index) Gets the long key at the givenindexin the insertion order.keySet()Returns aPrimitiveCollection.OfLongview of the keys contained in this map.order()Gets the LongList of keys in the order this class will iterate through them.static LongLongOrderedMapCreates a new map by parsing all ofstr, with entries separated byentrySeparator, such as", "and the keys separated from values bykeyValueSeparator, such as"=".static LongLongOrderedMapCreates a new map by parsing all ofstr(or ifbracketsis true, all but the first and last chars), with entries separated byentrySeparator, such as", "and the keys separated from values bykeyValueSeparator, such as"=".static LongLongOrderedMapCreates a new map by parsing the given subrange ofstr, with entries separated byentrySeparator, such as", "and the keys separated from values bykeyValueSeparator, such as"=".longput(long key, long value) Returns the old value associated with the specified key, or this map'sLongLongMap.defaultValueif there was no prior value.longput(long key, long value, int index) Puts the given key and value into this map at the given index in its order.voidputAll(int insertionIndex, LongLongOrderedMap other, int offset, int count) Adds up tocountentries, starting fromoffset, in the mapotherto this set, inserting starting atinsertionIndexin the iteration order.voidputAll(LongLongOrderedMap 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(LongLongOrderedMap other, int offset, int count) Adds up tocountentries, starting fromoffset, in the mapotherto this set, inserting at the end of the iteration order.longputOrDefault(long key, long value, long defaultValue) Returns the old value associated with the specified key, or the givendefaultValueif there was no prior value.longremove(long key) longremoveAt(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.longsetAt(int index, long v) Changes the value at a specifiedindexin the iteration order tov, without changing keys at all.voidsort()Sorts this LongLongOrderedMap in-place by the keys' natural ordering.voidsort(LongComparator comp) Sorts this LongLongOrderedMap in-place by the given LongComparator used on the keys.voidsortByValue(LongComparator comp) Sorts this LongLongOrderedMap in-place by the givenLongComparatorused on the values.voidtruncate(int newSize) Reduces the size of the map to the specified size.values()Returns aPrimitiveCollection.OfLongfor the values in the map.static LongLongOrderedMapwith()Constructs an empty map.static LongLongOrderedMapConstructs a single-entry map given one key and one value.static LongLongOrderedMapConstructs a map given alternating keys and values.static LongLongOrderedMapConstructs a map given alternating keys and values.static LongLongOrderedMapConstructs a map given alternating keys and values.static LongLongOrderedMapwith(Number key0, Number value0, Number key1, Number value1, Number key2, Number value2, Number key3, Number value3) Constructs a map given alternating keys and values.static LongLongOrderedMapConstructs an empty map.static LongLongOrderedMapwithPrimitive(long key0, long value0) Constructs a single-entry map given one key and one value.static LongLongOrderedMapwithPrimitive(long key0, long value0, long... rest) Constructs a map given alternating keys and values.static LongLongOrderedMapwithPrimitive(long key0, long value0, long key1, long value1) Constructs a map given alternating keys and values.static LongLongOrderedMapwithPrimitive(long key0, long value0, long key1, long value1, long key2, long value2) Constructs a map given alternating keys and values.static LongLongOrderedMapwithPrimitive(long key0, long value0, long key1, long value1, long key2, long value2, long key3, long value3) Constructs a map given alternating keys and values.Methods inherited from class com.github.tommyettinger.ds.LongLongMap
appendTo, combine, combine, computeIfAbsent, containsKey, containsValue, equals, findKey, forEach, get, getDefaultValue, getHashMultiplier, getLoadFactor, getOrDefault, getTableSize, hashCode, isEmpty, locateKey, notEmpty, place, putAll, putAll, putAll, putAll, putAll, putIfAbsent, putLegible, putLegible, putLegible, putLegible, putPairs, putPairsPrimitive, putResize, remove, replace, replace, replaceAll, 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 com.github.tommyettinger.ds.Ordered.OfLong
getOrderType, random, random, reverse, selectRanked, selectRankedIndex, shuffle, swap
-
Field Details
-
keys
-
-
Constructor Details
-
LongLongOrderedMap
Creates a new map with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor().- Parameters:
ordering- determines what implementationorder()will use
-
LongLongOrderedMap
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
-
LongLongOrderedMap
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
-
LongLongOrderedMap
Creates a new map identical to the specified map.- Parameters:
map- the map to copy
-
LongLongOrderedMap
Creates a new map identical to the specified map.- Parameters:
map- the map to copyordering- determines what implementationorder()will use
-
LongLongOrderedMap
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
-
LongLongOrderedMap
public LongLongOrderedMap(PrimitiveCollection.OfLong keys, PrimitiveCollection.OfLong 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 PrimitiveCollection of keysvalues- a PrimitiveCollection of valuesordering- determines what implementationorder()will use
-
LongLongOrderedMap
Creates a new set by copyingcountitems from the given LongLongOrderedMap, starting atoffsetin that Map, into this.- Parameters:
other- another LongLongOrderedMap 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
-
LongLongOrderedMap
public LongLongOrderedMap()Creates a new map with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor(). -
LongLongOrderedMap
public LongLongOrderedMap(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.
-
LongLongOrderedMap
public LongLongOrderedMap(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
-
LongLongOrderedMap
Creates a new map identical to the specified map.- Parameters:
map- the map to copy
-
LongLongOrderedMap
public LongLongOrderedMap(long[] keys, long[] 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. 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
-
LongLongOrderedMap
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 PrimitiveCollection of keysvalues- a PrimitiveCollection of values
-
LongLongOrderedMap
Creates a new set by copyingcountitems from the given LongLongOrderedMap, starting atoffsetin that Map, into this.- Parameters:
other- another LongLongOrderedMap of the same typeoffset- the first index in other's ordering to draw an item fromcount- how many items to copy from other
-
-
Method Details
-
put
public long put(long key, long value) Description copied from class:LongLongMapReturns the old value associated with the specified key, or this map'sLongLongMap.defaultValueif there was no prior value.- Overrides:
putin classLongLongMap
-
put
public long put(long key, long value, int index) 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 long keyvalue- a long valueindex- the index in the order to place the given key and value; must be non-negative and less thanLongLongMap.size()- Returns:
- the previous value associated with key, if there was one, or
LongLongMap.defaultValueotherwise
-
putOrDefault
public long putOrDefault(long key, long value, long defaultValue) Description copied from class:LongLongMapReturns the old value associated with the specified key, or the givendefaultValueif there was no prior value.- Overrides:
putOrDefaultin classLongLongMap
-
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 typeoffset- the first index inotherto usecount- how many indices inotherto use
-
putAll
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 typeoffset- the first index inotherto usecount- how many indices inotherto use
-
remove
public long remove(long key) - Overrides:
removein classLongLongMap
-
removeAt
public long removeAt(int index) 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 thanLongLongMap.size()- Returns:
- the value of the removed entry
-
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.OfLong- 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 classLongLongMap- Parameters:
newSize- the target size to try to reach by removing items, if smaller than the current size
-
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 classLongLongMap- Parameters:
additionalCapacity- how many additional items this should be able to hold without resizing (probably)
-
getAndIncrement
public long getAndIncrement(long key, long defaultValue, long increment) Description copied from class:LongLongMapReturns the key's current value and increments the stored value. If the key is not in the map, defaultValue + increment is put into the map and defaultValue is returned.- Overrides:
getAndIncrementin classLongLongMap
-
alter
public boolean alter(long before, long after) Changes the keybeforetoafterwithout changing its position in the order or its value. Returns true ifafterhas been added to the LongLongOrderedMap andbeforehas been removed; returns false ifafteris already present orbeforeis not present. If you are iterating over an LongLongOrderedMap and have an index, you should preferalterAt(int, long), 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
public boolean alterAt(int index, long after) 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(long, long), this operates in constant time.- Parameters:
index- the index in the order of the key to change; must be non-negative and less thanLongLongMap.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
public long setAt(int index, long v) 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 returnsLongLongMap.defaultValue. Otherwise, it returns the value that was previously held atindex, which may be equal toLongLongMap.defaultValue.- Parameters:
v- the new long 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
public long getAt(int index) Gets the long value at the givenindexin the insertion order. The index should be between 0 (inclusive) andLongLongMap.size()(exclusive).- Parameters:
index- an index in the insertion order, between 0 (inclusive) andLongLongMap.size()(exclusive)- Returns:
- the value at the given index
-
keyAt
public long keyAt(int index) Gets the long key at the givenindexin the insertion order. The index should be between 0 (inclusive) andLongLongMap.size()(exclusive).- Parameters:
index- an index in the insertion order, between 0 (inclusive) andLongLongMap.size()(exclusive)- Returns:
- the key at the given index
-
clear
public void clear(int maximumCapacity) Description copied from class:LongLongMapClears the map and reduces the size of the backing arrays to be the specified capacity / loadFactor, if they are larger.- Overrides:
clearin classLongLongMap
-
clear
public void clear()- Overrides:
clearin classLongLongMap
-
order
Gets the LongList of keys in the order this class will iterate through them. Returns a direct reference to the same LongList this uses, so changes to the returned list will also change the iteration order here.- Specified by:
orderin interfaceOrdered.OfLong- Returns:
- the LongList of keys, in iteration order (usually insertion-order), that this uses
-
sort
public void sort()Sorts this LongLongOrderedMap in-place by the keys' natural ordering. -
sort
Sorts this LongLongOrderedMap in-place by the given LongComparator used on the keys. Ifcompis null, then this will sort by the natural ordering of the keys.- Specified by:
sortin interfaceOrdered.OfLong- Parameters:
comp- a LongComparator, such as one fromLongComparators, or null to use the keys' natural ordering
-
sortByValue
Sorts this LongLongOrderedMap in-place by the givenLongComparatorused on the values.compmust not be null. You can useLongComparators.NATURAL_COMPARATORto do whatsort()does (just sorting values in this case instead of keys).- Parameters:
comp- a non-null LongComparator, such as one fromLongComparators
-
keySet
Returns aPrimitiveCollection.OfLongview 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(LongLongOrderedMap)constructor for nested or multithreaded iteration.- Overrides:
keySetin classLongLongMap- Returns:
- a set view of the keys contained in this map
-
values
Returns aPrimitiveCollection.OfLongfor 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(LongLongOrderedMap)constructor for nested or multithreaded iteration.- Overrides:
valuesin classLongLongMap- Returns:
- a
PrimitiveCollection.OfLongbacked by this map
-
entrySet
Returns aPrimitiveCollection.OfLongofLongLongMap.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(LongLongOrderedMap)constructor for nested or multithreaded iteration.- Overrides:
entrySetin classLongLongMap- Returns:
- a
PrimitiveCollection.OfLongofLongLongMap.Entrykey-value pairs
-
iterator
Reuses the iterator of the reusedLongLongMap.Entriesproduced byentrySet(); does not permit nested iteration. Iterate overOrderedMapEntries(LongLongOrderedMap)if you need nested or multithreaded iteration. You can remove an Entry from this LongLongOrderedMap using this Iterator.- Specified by:
iteratorin interfaceIterable<LongLongMap.Entry>- Overrides:
iteratorin classLongLongMap- Returns:
- an
Iteratorover key-value pairs asMap.Entryvalues
-
appendTo
public StringBuilder appendTo(StringBuilder sb, String entrySeparator, String keyValueSeparator, boolean braces, LongAppender keyAppender, LongAppender valueAppender) Appends to a StringBuilder from the contents of this LongLongOrderedMap, but uses the givenLongAppenderandLongAppenderto convert each key and each value to a customizable representation and append them to a StringBuilder. These functions are often method references to methods in Base, such asBase.appendUnsigned(CharSequence, long)andBase.appendUnsigned(CharSequence, long). To use the default String representation, you can useLongAppender.DEFAULTas an appender. To write values so that they can be read back as Java source code, useLongAppender.READABLEfor each appender.- Overrides:
appendToin classLongLongMap- 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 long, and returns the modified StringBuildervalueAppender- a function that takes a StringBuilder and a long, and returns the modified StringBuilder- Returns:
sb, with the appended keys and values of this map
-
with
Constructs an empty map. 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.- 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(Number, Number, Number...)when there's no "rest" of the keys or values. Like the more-argument with(), this will convert its Number keys and values to primitive long and long, regardless of which Number type was used.- Parameters:
key0- the first and only key; will be converted to primitive longvalue0- the first and only value; will be converted to primitive long- Returns:
- a new map containing just the entry mapping key0 to value0
-
with
Constructs a map given alternating keys and values. This is mostly useful as an optimization forwith(Number, Number, Number...)when there's no "rest" of the keys or values. Like the more-argument with(), this will convert its Number keys and values to primitive long and long, regardless of which Number type was used.- Parameters:
key0- a Number key; will be converted to primitive longvalue0- a Number for a value; will be converted to primitive longkey1- a Number key; will be converted to primitive longvalue1- a Number for a value; will be converted to primitive long- Returns:
- a new map containing the given key-value pairs
-
with
public static LongLongOrderedMap with(Number key0, Number value0, Number key1, Number value1, Number key2, Number value2) Constructs a map given alternating keys and values. This is mostly useful as an optimization forwith(Number, Number, Number...)when there's no "rest" of the keys or values. Like the more-argument with(), this will convert its Number keys and values to primitive long and long, regardless of which Number type was used.- Parameters:
key0- a Number key; will be converted to primitive longvalue0- a Number for a value; will be converted to primitive longkey1- a Number key; will be converted to primitive longvalue1- a Number for a value; will be converted to primitive longkey2- a Number key; will be converted to primitive longvalue2- a Number for a value; will be converted to primitive long- Returns:
- a new map containing the given key-value pairs
-
with
public static LongLongOrderedMap with(Number key0, Number value0, Number key1, Number value1, Number key2, Number value2, Number key3, Number value3) Constructs a map given alternating keys and values. This is mostly useful as an optimization forwith(Number, Number, Number...)when there's no "rest" of the keys or values. Like the more-argument with(), this will convert its Number keys and values to primitive long and long, regardless of which Number type was used.- Parameters:
key0- a Number key; will be converted to primitive longvalue0- a Number for a value; will be converted to primitive longkey1- a Number key; will be converted to primitive longvalue1- a Number for a value; will be converted to primitive longkey2- a Number key; will be converted to primitive longvalue2- a Number for a value; will be converted to primitive longkey3- a Number key; will be converted to primitive longvalue3- a Number for a value; will be converted to primitive long- Returns:
- a new map containing the given key-value pairs
-
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 useLongLongOrderedMap(long[], long[]), which takes all keys and then all values. This needs all keys to be some kind of (boxed) Number, and converts them to primitivelongs. It also needs all values to be a (boxed) Number, and converts them to primitivelongs. Any keys or values that aren'tNumbers have that entry skipped.- Parameters:
key0- the first key; will be converted to a primitive longvalue0- the first value; will be converted to a primitive longrest- an array or varargs of Number elements- Returns:
- a new map containing the given key-value pairs
-
withPrimitive
Constructs an empty map. 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.- Returns:
- a new map containing nothing
-
withPrimitive
Constructs a single-entry map given one key and one value. This is mostly useful as an optimization forwith(Number, Number, Number...)when there's no "rest" of the keys or values. Unlike the vararg with(), this doesn't box its arguments into Number items.- Parameters:
key0- the first and only keyvalue0- the first and only value- Returns:
- a new map containing just the entry mapping key0 to value0
-
withPrimitive
Constructs a map given alternating keys and values. This is mostly useful as an optimization forwith(Number, Number, Number...)when there's no "rest" of the keys or values. Unlike the vararg with(), this doesn't box its arguments into Number items.- Parameters:
key0- a long keyvalue0- a long valuekey1- a long keyvalue1- a long value- Returns:
- a new map containing the given key-value pairs
-
withPrimitive
public static LongLongOrderedMap withPrimitive(long key0, long value0, long key1, long value1, long key2, long value2) Constructs a map given alternating keys and values. This is mostly useful as an optimization forwith(Number, Number, Number...)when there's no "rest" of the keys or values. Unlike the vararg with(), this doesn't box its arguments into Number items.- Parameters:
key0- a long keyvalue0- a long valuekey1- a long keyvalue1- a long valuekey2- a long keyvalue2- a long value- Returns:
- a new map containing the given key-value pairs
-
withPrimitive
public static LongLongOrderedMap withPrimitive(long key0, long value0, long key1, long value1, long key2, long value2, long key3, long value3) Constructs a map given alternating keys and values. This is mostly useful as an optimization forwith(Number, Number, Number...)when there's no "rest" of the keys or values. Unlike the vararg with(), this doesn't box its arguments into Number items.- Parameters:
key0- a long keyvalue0- a long valuekey1- a long keyvalue1- a long valuekey2- a long keyvalue2- a long valuekey3- a long keyvalue3- a long value- Returns:
- a new map containing the given key-value pairs
-
withPrimitive
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 useLongLongOrderedMap(long[], long[]), which takes all keys and then all values. This needs all keys and all values to be primitivelongs; if any are boxed, then you should callwith(Number, Number, Number...).
This method has to be named differently fromwith(Number, Number, Number...)to disambiguate the two, which would otherwise both be callable with all primitives (due to auto-boxing).- Parameters:
key0- the first key; must not be boxedvalue0- the first value; must not be boxedrest- an array or varargs of primitive long elements- Returns:
- a new map containing the given keys and values
-
parse
Creates a new map by parsing all ofstr, with entries separated byentrySeparator, such as", "and the keys separated from values bykeyValueSeparator, such as"=".- Parameters:
str- a String containing parseable textentrySeparator- the String separating every key-value pairkeyValueSeparator- the String separating every key from its corresponding value
-
parse
public static LongLongOrderedMap parse(String str, String entrySeparator, String keyValueSeparator, boolean brackets) Creates a new map by parsing all ofstr(or ifbracketsis true, all but the first and last chars), with entries separated byentrySeparator, such as", "and the keys separated from values bykeyValueSeparator, such as"=".- Parameters:
str- a String containing parseable textentrySeparator- the String separating every key-value pairkeyValueSeparator- the String separating every key from its corresponding valuebrackets- if true, the first and last chars instrwill be ignored
-
parse
public static LongLongOrderedMap parse(String str, String entrySeparator, String keyValueSeparator, int offset, int length) Creates a new map by parsing the given subrange ofstr, with entries separated byentrySeparator, such as", "and the keys separated from values bykeyValueSeparator, such as"=".- Parameters:
str- a String containing parseable textentrySeparator- the String separating every key-value pairkeyValueSeparator- the String separating every key from its corresponding valueoffset- the first position to read parseable text from instrlength- how many chars to read; -1 is treated as maximum length
-