Package com.github.tommyettinger.ds
Class FilteredIterableOrderedMap<K,I extends Iterable<K>,V>
java.lang.Object
com.github.tommyettinger.ds.ObjectObjectMap<K,V>
com.github.tommyettinger.ds.ObjectObjectOrderedMap<I,V>
com.github.tommyettinger.ds.FilteredIterableOrderedMap<K,I,V>
- All Implemented Interfaces:
Arrangeable,Ordered<I>,Iterable<Map.Entry<I,,V>> Map<I,V>
public class FilteredIterableOrderedMap<K,I extends Iterable<K>,V>
extends ObjectObjectOrderedMap<I,V>
A customizable variant on ObjectMap that uses Iterable keys made of K sub-keys, and only considers a sub-key (for
equality and hashing purposes) if that sub-key satisfies a predicate. This can also edit the sub-keys that pass
the filter, such as to normalize their data during comparisons (and hashing). You will usually want to call
This class is related to
This is very similar to
setFilter(ObjPredicate) and/or setEditor(ObjToSameFunction) to change the behavior of hashing and
equality before you enter any keys, unless you have specified the filter and/or editor you want in the constructor.
Calling setModifiers(ObjPredicate, ObjToSameFunction) is recommended if you need to set both the filter and
the editor; you could also set them in the constructor.
This class is related to
FilteredStringMap, which can be seen as using a String as a key and the characters
of that String as its sub-keys. That means this is also similar to CaseInsensitiveMap, which is essentially
a specialized version of FilteredIterableMap (which can be useful for serialization).
This is very similar to
FilteredIterableMap,
except that this class maintains insertion order and can be sorted with ObjectObjectOrderedMap.sort(), ObjectObjectOrderedMap.sort(Comparator), etc.
Note that because each Iterable is stored in here in its original form (not modified to make it use the filter and editor),
the sorted order might be different than you expect.
You can use FilteredComparators.makeComparator(Comparator, ObjPredicate, ObjToSameFunction) to create a Comparator
for I Iterable items that uses the same rules this class does.-
Nested Class Summary
Nested classes/interfaces inherited from class com.github.tommyettinger.ds.ObjectObjectOrderedMap
ObjectObjectOrderedMap.OrderedMapEntries<K,V>, ObjectObjectOrderedMap.OrderedMapKeys<K, V>, ObjectObjectOrderedMap.OrderedMapValues<K, V> Nested 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
FieldsModifier and TypeFieldDescriptionprotected com.github.tommyettinger.function.ObjToSameFunction<K>protected com.github.tommyettinger.function.ObjPredicate<K>Fields inherited from class com.github.tommyettinger.ds.ObjectObjectOrderedMap
keysFields 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().FilteredIterableOrderedMap(int initialCapacity) Creates a new map with the specified initial capacity and a load factor ofUtilities.getDefaultLoadFactor().FilteredIterableOrderedMap(int initialCapacity, float loadFactor) Creates a new map with the specified initial capacity and load factor.FilteredIterableOrderedMap(int initialCapacity, float loadFactor, OrderType type) Creates a new map with the specified initial capacity and load factor.FilteredIterableOrderedMap(int initialCapacity, OrderType type) Creates a new map with the specified initial capacity and a load factor ofUtilities.getDefaultLoadFactor().FilteredIterableOrderedMap(FilteredIterableOrderedMap<K, ? extends I, ? extends V> map) Creates a new map identical to the specified map.FilteredIterableOrderedMap(FilteredIterableOrderedMap<K, ? extends I, ? extends V> map, OrderType type) Creates a new map identical to the specified map.Creates a new map with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor().FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor) Creates a new map with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor().FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, int initialCapacity) Creates a new map with the specified initial capacity and a load factor ofUtilities.getDefaultLoadFactor().FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, int initialCapacity, float loadFactor) Creates a new map with the specified initial capacity and load factor.FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, int initialCapacity, float loadFactor, OrderType type) Creates a new map with the specified initial capacity and load factor.FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, int initialCapacity, OrderType type) Creates a new map with the specified initial capacity and a load factor ofUtilities.getDefaultLoadFactor().FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, OrderType type) Creates a new map with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor().FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, I[] keys, V[] values) Creates a new map using all the keys from the givenkeysandvalues.FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, I[] keys, V[] values, OrderType type) Creates a new map using all the keys from the givenkeysandvalues.FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, Collection<? extends I> 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.FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, Collection<? extends I> keys, Collection<? extends V> values, OrderType type) 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.FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, Map<? extends I, ? extends V> map) Creates a new map with the given filter and editor, and attempts to insert every entry from the givenmapinto the new data structure.FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, Map<? extends I, ? extends V> map, OrderType type) Creates a new map with the given filter and editor, and attempts to insert every entry from the givenmapinto the new data structure. -
Method Summary
Modifier and TypeMethodDescriptionbooleanCompares two objects for equality by the rules this filtered data structure uses for keys.com.github.tommyettinger.function.ObjToSameFunction<K>com.github.tommyettinger.function.ObjPredicate<K>inthashCode()protected inthashHelper(I s) static <K,I extends Iterable<K>, V>
FilteredIterableOrderedMap<K,I, V> parse(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, String str, String entrySeparator, String keyValueSeparator, PartialParser<I> 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,I extends Iterable<K>, V>
FilteredIterableOrderedMap<K,I, V> parse(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, String str, String entrySeparator, String keyValueSeparator, PartialParser<I> 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,I extends Iterable<K>, V>
FilteredIterableOrderedMap<K,I, V> parse(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, String str, String entrySeparator, String keyValueSeparator, PartialParser<I> 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"=".protected intReturns an index >= 0 and <=ObjectObjectMap.maskfor the specifieditem, mixed.Sets the editor that can alter the sub-keys in an Iterable key when they are being used for equality and hashing.Sets the filter that determines which sub-keys in an Iterable are considered for equality and hashing, then returns this object, for chaining.setModifiers(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor) Equivalent to callingmyMap.setFilter(filter).setEditor(editor), but only clears the data structure once.static <K,I extends Iterable<K>, V>
FilteredIterableOrderedMap<K,I, V> with(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor) The same aswith(ObjPredicate, ObjToSameFunction, Iterable, Object, Object...), except this takes no keys or values, and doesn't allocate an array from using varargs.static <K,I extends Iterable<K>, V>
FilteredIterableOrderedMap<K,I, V> with(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, I key, V value) The same aswith(ObjPredicate, ObjToSameFunction, Iterable, Object, Object...), except this only takes one key-value pair, and doesn't allocate an array from using varargs.static <K,I extends Iterable<K>, V>
FilteredIterableOrderedMap<K,I, V> with(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, I key0, V value0, I key1, V value1) The same aswith(ObjPredicate, ObjToSameFunction, Iterable, Object, Object...), except this only takes the given key-value pairs, and doesn't allocate an array from using varargs.static <K,I extends Iterable<K>, V>
FilteredIterableOrderedMap<K,I, V> with(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, I key0, V value0, I key1, V value1, I key2, V value2) The same aswith(ObjPredicate, ObjToSameFunction, Iterable, Object, Object...), except this only takes the given key-value pairs, and doesn't allocate an array from using varargs.static <K,I extends Iterable<K>, V>
FilteredIterableOrderedMap<K,I, V> with(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, I key0, V value0, I key1, V value1, I key2, V value2, I key3, V value3) The same aswith(ObjPredicate, ObjToSameFunction, Iterable, Object, Object...), except this only takes the given key-value pairs, and doesn't allocate an array from using varargs.static <K,I extends Iterable<K>, V>
FilteredIterableOrderedMap<K,I, V> with(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, I key0, V value0, Object... rest) Constructs a map given a filter, an editor, and then alternating keys and values.Methods inherited from class com.github.tommyettinger.ds.ObjectObjectOrderedMap
alter, alterAt, appendTo, clear, clear, ensureCapacity, entrySet, getAt, iterator, keyAt, keySet, order, parse, parse, parse, put, put, putAll, putAll, putAll, putOrDefault, remove, removeAt, removeRange, setAt, sort, sort, sortByValue, truncate, values, with, with, with, with, with, withMethods inherited from class com.github.tommyettinger.ds.ObjectObjectMap
appendTo, combine, combine, containsKey, containsValue, containsValue, equals, equalsIdentity, findKey, findKey, get, getDefaultValue, getHashMultiplier, getLoadFactor, getOrDefault, getTableSize, isEmpty, locateKey, notEmpty, 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
-
filter
-
editor
-
-
Constructor Details
-
FilteredIterableOrderedMap
Creates a new map with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor(). This considers all sub-keys in an Iterable key and does not edit any sub-keys.- Parameters:
type- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
FilteredIterableOrderedMap
Creates a new map with the specified initial capacity and a load factor ofUtilities.getDefaultLoadFactor(). This set will hold initialCapacity keys before growing the backing table. This considers all sub-keys in an Iterable key and does not edit any sub-keys.- Parameters:
initialCapacity- If not a power of two, it is increased to the next nearest power of two.type- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
FilteredIterableOrderedMap
Creates a new map with the specified initial capacity and load factor. This set will hold initialCapacity keys before growing the backing table. This considers all sub-keys in an Iterable key and does not edit any sub-keys.- 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 <= 1type- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
FilteredIterableOrderedMap
public FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, OrderType type) Creates a new map with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor(). This uses the specified filter and editor.- Parameters:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-keytype- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
FilteredIterableOrderedMap
public FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, int initialCapacity, OrderType type) Creates a new map with the specified initial capacity and a load factor ofUtilities.getDefaultLoadFactor(). This set will hold initialCapacity keys before growing the backing table. This uses the specified filter and editor.- Parameters:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-keyinitialCapacity- If not a power of two, it is increased to the next nearest power of two.type- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
FilteredIterableOrderedMap
public FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, int initialCapacity, float loadFactor, OrderType type) Creates a new map with the specified initial capacity and load factor. This set will hold initialCapacity keys before growing the backing table. This uses the specified filter and editor.- Parameters:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-keyinitialCapacity- 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 <= 1type- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
FilteredIterableOrderedMap
public FilteredIterableOrderedMap(FilteredIterableOrderedMap<K, ? extends I, ? extends V> map, OrderType type) Creates a new map identical to the specified map.- Parameters:
map- another FilteredIterableMap to copytype- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
FilteredIterableOrderedMap
public FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, Map<? extends I, ? extends V> map, OrderType type) Creates a new map with the given filter and editor, and attempts to insert every entry from the givenmapinto the new data structure. Not all keys frommapmight be entered if the filter and editor consider some as equal.- Parameters:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-keymap- a Map to copytype- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
FilteredIterableOrderedMap
public FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, Collection<? extends I> keys, Collection<? extends V> values, OrderType type) 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. This uses the specified filter and editor, including while it enters the keys and values.- Parameters:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-keykeys- a Collection of keysvalues- a Collection of valuestype- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
FilteredIterableOrderedMap
public FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, I[] keys, V[] values, OrderType type) Creates a new map using all the keys from the givenkeysandvalues. This uses the specified filter and editor, including while it enters the keys and values.- Parameters:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-keykeys- an array to draw keys fromvalues- an array to draw values fromtype- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
FilteredIterableOrderedMap
public FilteredIterableOrderedMap()Creates a new map with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor(). This considers all sub-keys in an Iterable key and does not edit any sub-keys. -
FilteredIterableOrderedMap
public FilteredIterableOrderedMap(int initialCapacity) Creates a new map with the specified initial capacity and a load factor ofUtilities.getDefaultLoadFactor(). This set will hold initialCapacity keys before growing the backing table. This considers all sub-keys in an Iterable key and does not edit any sub-keys.- Parameters:
initialCapacity- If not a power of two, it is increased to the next nearest power of two.
-
FilteredIterableOrderedMap
public FilteredIterableOrderedMap(int initialCapacity, float loadFactor) Creates a new map with the specified initial capacity and load factor. This set will hold initialCapacity keys before growing the backing table. This considers all sub-keys in an Iterable key and does not edit any sub-keys.- 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
-
FilteredIterableOrderedMap
public FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor) Creates a new map with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor(). This uses the specified filter and editor.- Parameters:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-key
-
FilteredIterableOrderedMap
public FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, int initialCapacity) Creates a new map with the specified initial capacity and a load factor ofUtilities.getDefaultLoadFactor(). This set will hold initialCapacity keys before growing the backing table. This uses the specified filter and editor.- Parameters:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-keyinitialCapacity- If not a power of two, it is increased to the next nearest power of two.
-
FilteredIterableOrderedMap
public FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, int initialCapacity, float loadFactor) Creates a new map with the specified initial capacity and load factor. This set will hold initialCapacity keys before growing the backing table. This uses the specified filter and editor.- Parameters:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-keyinitialCapacity- 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
-
FilteredIterableOrderedMap
Creates a new map identical to the specified map.- Parameters:
map- another FilteredIterableMap to copy
-
FilteredIterableOrderedMap
public FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, Map<? extends I, ? extends V> map) Creates a new map with the given filter and editor, and attempts to insert every entry from the givenmapinto the new data structure. Not all keys frommapmight be entered if the filter and editor consider some as equal.- Parameters:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-keymap- a Map to copy
-
FilteredIterableOrderedMap
public FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, Collection<? extends I> 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. If keys and values have different lengths, this only uses the length of the smaller collection. This uses the specified filter and editor, including while it enters the keys and values.- Parameters:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-keykeys- a Collection of keysvalues- a Collection of values
-
FilteredIterableOrderedMap
public FilteredIterableOrderedMap(com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, I[] keys, V[] values) Creates a new map using all the keys from the givenkeysandvalues. This uses the specified filter and editor, including while it enters the keys and values.- Parameters:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-keykeys- an array to draw keys fromvalues- an array to draw values from
-
-
Method Details
-
getFilter
-
setFilter
public FilteredIterableOrderedMap<K,I, setFilterV> (com.github.tommyettinger.function.ObjPredicate<K> filter) Sets the filter that determines which sub-keys in an Iterable are considered for equality and hashing, then returns this object, for chaining. ObjPredicatefilters could be lambdas or method references that take a sub-key and return true if that sub-key will be used for hashing/equality, or return false to ignore it. The default filter always returns true. If the filter changes, that invalidates anything previously entered into this, so before changing the filter this clears the entire data structure, removing all existing entries. - Parameters:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing - Returns:
- this, for chaining
-
getEditor
-
setEditor
public FilteredIterableOrderedMap<K,I, setEditorV> (com.github.tommyettinger.function.ObjToSameFunction<K> editor) Sets the editor that can alter the sub-keys in an Iterable key when they are being used for equality and hashing. This does not apply any changes to the keys in this data structure; it only affects how they are hashed or compared. An editor could be a lambda or method reference; the only real requirement is that it takes aKsub-key and returns aKsub-key. The default filter returns the sub-key it is passed without changes. If the editor changes, that invalidates anything previously entered into this, so before changing the editor this clears the entire data structure, removing all existing entries.- Parameters:
editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-key- Returns:
- this, for chaining
-
setModifiers
public FilteredIterableOrderedMap<K,I, setModifiersV> (com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor) Equivalent to callingmyMap.setFilter(filter).setEditor(editor), but only clears the data structure once.- Parameters:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-key- Returns:
- this, for chaining
- See Also:
-
hashHelper
-
place
Description copied from class:ObjectObjectMapReturns an index >= 0 and <=ObjectObjectMap.maskfor the specifieditem, mixed.- Overrides:
placein classObjectObjectMap<I extends Iterable<K>,V> - Parameters:
item- a non-null Object; its hashCode() method should be used by most implementations- Returns:
- an index between 0 and
ObjectObjectMap.mask(both inclusive)
-
equate
Compares two objects for equality by the rules this filtered data structure uses for keys. This will return true if the arguments are reference-equivalent or both null. Otherwise, it requires that both areIterables and compares them using thefilterandeditorof this object.- Overrides:
equatein classObjectObjectMap<I extends Iterable<K>,V> - Parameters:
left- must be non-null; typically a key being compared, but not necessarilyright- may be null; typically a key being compared, but can often be null for an empty key slot, or some other type- Returns:
- true if left and right are equivalent according to the rules this filtered type uses
-
hashCode
public int hashCode() -
with
public static <K,I extends Iterable<K>, FilteredIterableOrderedMap<K,V> I, withV> (com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor) The same aswith(ObjPredicate, ObjToSameFunction, Iterable, Object, Object...), except this takes no keys or values, and doesn't allocate an array from using varargs.- Type Parameters:
K- the type of sub-keys inside each Iterable keyI- the type of keys, which must extend Iterable; inferred from key0V- the type of values, inferred from value0- Parameters:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-key- Returns:
- a new FilteredIterableOrderedMap containing only the given key and value
- See Also:
-
with
public static <K,I extends Iterable<K>, FilteredIterableOrderedMap<K,V> I, withV> (com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, I key, V value) The same aswith(ObjPredicate, ObjToSameFunction, Iterable, Object, Object...), except this only takes one key-value pair, and doesn't allocate an array from using varargs.- Type Parameters:
K- the type of sub-keys inside each Iterable keyI- the type of keys, which must extend Iterable; inferred from key0V- the type of values, inferred from value0- Parameters:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-keykey- the only key that will be present in the returned mapvalue- the only value that will be present in the returned map- Returns:
- a new FilteredIterableOrderedMap containing only the given key and value
- See Also:
-
with
public static <K,I extends Iterable<K>, FilteredIterableOrderedMap<K,V> I, withV> (com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, I key0, V value0, I key1, V value1) The same aswith(ObjPredicate, ObjToSameFunction, Iterable, Object, Object...), except this only takes the given key-value pairs, and doesn't allocate an array from using varargs.- Type Parameters:
K- the type of sub-keys inside each Iterable keyI- the type of keys, which must extend Iterable; inferred from key0V- the type of values, inferred from value0- Parameters:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-keykey0- a key that will be present in the returned mapvalue0- a value that will be present in the returned mapkey1- a key that will be present in the returned mapvalue1- a value that will be present in the returned map- Returns:
- a new FilteredIterableOrderedMap containing only the given keys and values
- See Also:
-
with
public static <K,I extends Iterable<K>, FilteredIterableOrderedMap<K,V> I, withV> (com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, I key0, V value0, I key1, V value1, I key2, V value2) The same aswith(ObjPredicate, ObjToSameFunction, Iterable, Object, Object...), except this only takes the given key-value pairs, and doesn't allocate an array from using varargs.- Type Parameters:
K- the type of sub-keys inside each Iterable keyI- the type of keys, which must extend Iterable; inferred from key0V- the type of values, inferred from value0- Parameters:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-keykey0- a key that will be present in the returned mapvalue0- a value that will be present in the returned mapkey1- a key that will be present in the returned mapvalue1- a value that will be present in the returned mapkey2- a key that will be present in the returned mapvalue2- a value that will be present in the returned map- Returns:
- a new FilteredIterableOrderedMap containing only the given keys and values
- See Also:
-
with
public static <K,I extends Iterable<K>, FilteredIterableOrderedMap<K,V> I, withV> (com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, I key0, V value0, I key1, V value1, I key2, V value2, I key3, V value3) The same aswith(ObjPredicate, ObjToSameFunction, Iterable, Object, Object...), except this only takes the given key-value pairs, and doesn't allocate an array from using varargs.- Type Parameters:
K- the type of sub-keys inside each Iterable keyI- the type of keys, which must extend Iterable; inferred from key0V- the type of values, inferred from value0- Parameters:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-keykey0- a key that will be present in the returned mapvalue0- a value that will be present in the returned mapkey1- a key that will be present in the returned mapvalue1- a value that will be present in the returned mapkey2- a key that will be present in the returned mapvalue2- a value that will be present in the returned mapkey3- a key that will be present in the returned mapvalue3- a value that will be present in the returned map- Returns:
- a new FilteredIterableOrderedMap containing only the given keys and values
- See Also:
-
with
public static <K,I extends Iterable<K>, FilteredIterableOrderedMap<K,V> I, withV> (com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, I key0, V value0, Object... rest) Constructs a map given a filter, an editor, and then 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 useFilteredIterableOrderedMap(ObjPredicate, ObjToSameFunction, Iterable[], 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 I as their type or values that don't have V as their type have that entry skipped.- Type Parameters:
K- the type of sub-keys inside each Iterable keyI- the type of keys, which must extend Iterable; inferred from key0V- the type of values, inferred from value0- Parameters:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-keykey0- 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- an array or varargs of alternating I, V, I, V... elements- Returns:
- a new map containing the given keys and values
-
parse
public static <K,I extends Iterable<K>, FilteredIterableOrderedMap<K,V> I, parseV> (com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, String str, String entrySeparator, String keyValueSeparator, PartialParser<I> 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:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-keystr- 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 aIIterable from a section ofstrvalueParser- a PartialParser that returns aVvalue from a section ofstr
-
parse
public static <K,I extends Iterable<K>, FilteredIterableOrderedMap<K,V> I, parseV> (com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, String str, String entrySeparator, String keyValueSeparator, PartialParser<I> 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:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-keystr- 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 aIIterable 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,I extends Iterable<K>, FilteredIterableOrderedMap<K,V> I, parseV> (com.github.tommyettinger.function.ObjPredicate<K> filter, com.github.tommyettinger.function.ObjToSameFunction<K> editor, String str, String entrySeparator, String keyValueSeparator, PartialParser<I> 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:
filter- a ObjPredicatethat should return true iff a sub-key should be considered for equality/hashing editor- a ObjToSameFunctionthat will be given a sub-key and may return a potentially different Ksub-keystr- 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 aIIterable 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
-