Package com.github.tommyettinger.ds
Class HolderSet<T,K>
java.lang.Object
com.github.tommyettinger.ds.HolderSet<T,K>
- Type Parameters:
T- the type of full items stored in the set; each T must have a way to get a K from itK- the type of lookup keys stored in each T item
- All Implemented Interfaces:
EnhancedCollection<T>,Iterable<T>,Collection<T>,Set<T>
- Direct Known Subclasses:
HolderOrderedSet
An unordered set where the items are objects but access to items is done with a specific key component
held by each item, and the component is extracted from an item by a given Function. Neither null items
nor null keys are allowed. No allocation is done except when growing the table size. The function is
called the extractor, and is often a method reference.
Some operations are different here from a normal Set;
Some operations are different here from a normal Set;
contains(Object) expects a K key, and
remove(Object) does as well. You can use get(Object) to go back to a T value from a
K key.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intUsed byplace(Object)to mix hashCode() results.protected HolderSet.HolderSetIterator<T,K> protected HolderSet.HolderSetIterator<T,K> protected T[]protected floatBetween 0f (exclusive) and 1f (inclusive, if you're careful), this determines how full the backing table can get before this increases its size.protected intA bitmask used to confine hashcodes to the size of the table.protected intUsed byplace(Object)typically, this should always equalcom.github.tommyettinger.digital.BitConversion.countLeadingZeros(mask).protected intprotected intPrecalculated value of(int)(keyTable.length * loadFactor), used to determine when to resize. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new set with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor().Creates a new set identical to the specified set.Creates a new set with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor().Creates a new set with a load factor ofUtilities.getDefaultLoadFactor().HolderSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, int initialCapacity, float loadFactor) Creates a new set with the specified initial capacity and load factor.HolderSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, Collection<? extends T> coll) Creates a new set that contains all distinct elements incoll, usingextractorto get the keys that determine distinctness.HolderSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, Iterator<? extends T> coll) Creates a new instance containing the items in the specified iterator.Creates a new set that contains all distinct elements initems, usingextractorto get the keys that determine distinctness. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns true if the item was not already in the set.booleanbooleanaddAll(Collection<? extends T> coll) booleanbooleanprotected voidSkips checks for existing keys, doesn't increment size.voidclear()Clears the set, leaving the backing arrays at the current capacity.voidclear(int maximumCapacity) Clears the set and reduces the size of the backing arrays to be the specified capacity / loadFactor, if they are larger.booleanChecks for the presence of a K key, not a T value.booleancontainsAll(Object[] array) Exactly likecontainsAll(Collection), but takes an array instead of a Collection.booleancontainsAll(Object[] array, int offset, int length) booleancontainsAll(Collection<?> c) booleancontainsAny(Object[] values) Returns true if this set contains any of the specified values.booleancontainsAny(Object[] values, int offset, int length) Returns true if this set contains any items from the specified range of values.booleancontainsAnyIterable(Iterable<?> values) Returns true if this set contains any of the specified values.voidensureCapacity(int additionalCapacity) Increases the size of the backing array to accommodate the specified number of additional items / loadFactor.booleanprotected booleanCompares the objects left and right, which should be K keys (not T items), for equality, returning true if they are considered equal.first()Gets the (arbitrarily-chosen) first item in this HolderSet.Given a K key that could have been extracted or extractable from a T item in this, this returns the T item that holds that key, or null if no item holds key.Gets the function this uses to extract keys from items.intGets the current hashMultiplier, used inplace(Object)to mix hash codes.floatgetOrDefault(Object key, T defaultValue) Given a K key that could have been extracted or extractable from a T item in this, this returns the T item that holds that key, ordefaultValueif no item holds key.intGets the length of the internal array used to store all items, as well as empty space awaiting more items to be entered.inthashCode()booleanisEmpty()Returns true if the set is empty.iterator()Returns an iterator for the keys in the set.protected intReturns the index of the key if already present, else~indexfor the next empty index.booleannotEmpty()Returns true if the set has one or more items.static <T,K> HolderSet<T, K> parse(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, String str, String delimiter, PartialParser<T> parser) Callsparse(ObjToObjFunction, String, String, PartialParser, boolean)with brackets set to false.static <T,K> HolderSet<T, K> parse(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, String str, String delimiter, PartialParser<T> parser, boolean brackets) Creates a new HolderSet usingextractorand fills it by callingEnhancedCollection.addLegible(String, String, PartialParser, int, int)on either all ofstr(ifbracketsis false) orstrwithout its first and last chars (ifbracketsis true).static <T,K> HolderSet<T, K> parse(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, String str, String delimiter, PartialParser<T> parser, int offset, int length) Creates a new HolderSet usingextractorand fills it by callingEnhancedCollection.addLegible(String, String, PartialParser, int, int)with the other five parameters as-is.protected intReturns an index >= 0 and <=maskfor the specifieditem, mixed.booleanTakes a K key and not a T value! Returns true if the key was removed.booleanRemoves from this collection all occurrences of any elements contained in the specified array.booleanRemoves from this collection all occurrences of any elements contained in the specified array, but only starts reading elements from the array starting at the givenoffsetand only useslengthitems.booleanremoveAll(Collection<?> c) Removes from this Set a Collection of K key types (not T items).protected voidresize(int newSize) booleanretainAll(Collection<?> c) Makes this Set retain a Collection of K key types (not T items).voidsetExtractor(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor) Sets the function this will use to extract keys from items; this will only have an effect if the extractor function is currently null/invalid.voidsetHashMultiplier(int hashMultiplier) Sets the hashMultiplier to the given int, which will be made odd if even and always negative (by OR-ing with 0x80000001).voidsetLoadFactor(float loadFactor) voidshrink(int maximumCapacity) Reduces the size of the backing arrays to be the specified capacity / loadFactor, or less.intsize()Returns the number of elements in this set (its cardinality).Object[]toArray()<E> E[]toArray(E[] a) Returns an array containing all the elements in this set; the runtime type of the returned array is that of the specified array.toString()voidtruncate(int newSize) Reduces the size of the set to the specified size.static <T,K> HolderSet<T, K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor) Constructs an empty set given only an extractor function.static <T,K> HolderSet<T, K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item) Creates a new HolderSet that holds only the given item, but can be resized.static <T,K> HolderSet<T, K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T... varargs) Creates a new HolderSet that holds only the given items, but can be resized.static <T,K> HolderSet<T, K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item0, T item1) Creates a new HolderSet that holds only the given items, but can be resized.static <T,K> HolderSet<T, K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item0, T item1, T item2) Creates a new HolderSet that holds only the given items, but can be resized.static <T,K> HolderSet<T, K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item0, T item1, T item2, T item3) Creates a new HolderSet that holds only the given items, but can be resized.static <T,K> HolderSet<T, K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item0, T item1, T item2, T item3, T item4) Creates a new HolderSet that holds only the given items, but can be resized.static <T,K> HolderSet<T, K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item0, T item1, T item2, T item3, T item4, T item5) Creates a new HolderSet that holds only the given items, but can be resized.static <T,K> HolderSet<T, K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item0, T item1, T item2, T item3, T item4, T item5, T item6) Creates a new HolderSet that holds only the given items, but can be resized.static <T,K> HolderSet<T, K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item0, T item1, T item2, T item3, T item4, T item5, T item6, T item7) Creates a new HolderSet that holds only the given items, but can be resized.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface com.github.tommyettinger.ds.EnhancedCollection
add, add, add, addAll, addAllIterable, addLegible, addLegible, addVarargs, appendTo, appendTo, containsAll, containsAllIterable, containsAny, removeAll, removeAllIterable, removeEach, removeEach, removeEach, removeEachIterable, toString, toString, toStringMethods inherited from interface java.util.Set
spliterator
-
Field Details
-
size
protected int size -
keyTable
-
loadFactor
protected float loadFactorBetween 0f (exclusive) and 1f (inclusive, if you're careful), this determines how full the backing table can get before this increases its size. Larger values use less memory but make the data structure slower. -
threshold
protected int thresholdPrecalculated value of(int)(keyTable.length * loadFactor), used to determine when to resize. -
shift
protected int shiftUsed byplace(Object)typically, this should always equalcom.github.tommyettinger.digital.BitConversion.countLeadingZeros(mask). For a table that could hold 2 items (with 1 bit indices), this would be64 - 1 == 63. For a table that could hold 256 items (with 8 bit indices), this would be64 - 8 == 56. -
mask
protected int maskA bitmask used to confine hashcodes to the size of the table. Must be all 1 bits in its low positions, ie a power of two minus 1. Ifplace(Object)is overridden, this can be used instead ofshiftto isolate usable bits of a hash. -
hashMultiplier
protected int hashMultiplierUsed byplace(Object)to mix hashCode() results. Changes on every call toresize(int)by default. This should always change whenshiftchanges, meaning, when the backing table resizes. This only needs to be serialized if the full key and value tables are serialized, or if the iteration order should be the same before and after serialization. Iteration order is better handled by usingHolderOrderedSet. -
iterator1
-
iterator2
-
extractor
-
-
Constructor Details
-
HolderSet
public HolderSet()Creates a new set with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor(). This does not set the extractor, so the HolderSet will not be usable untilsetExtractor(ObjToObjFunction)is called with a valid ObjToObjFunction that gets K keys from T items. -
HolderSet
Creates a new set with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor().- Parameters:
extractor- a function that will be used to extract K keys from the T items put into this
-
HolderSet
public HolderSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, int initialCapacity) Creates a new set with a load factor ofUtilities.getDefaultLoadFactor().- Parameters:
extractor- a function that will be used to extract K keys from the T items put into thisinitialCapacity- If not a power of two, it is increased to the next nearest power of two.
-
HolderSet
public HolderSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, int initialCapacity, float loadFactor) Creates a new set with the specified initial capacity and load factor. This set will hold initialCapacity items before growing the backing table.- Parameters:
extractor- a function that will be used to extract K keys from the T items put into thisinitialCapacity- 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
-
HolderSet
public HolderSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, Iterator<? extends T> coll) Creates a new instance containing the items in the specified iterator.- Parameters:
coll- an iterator that will have its remaining contents added to this
-
HolderSet
Creates a new set identical to the specified set. This doesn't copy the extractor; instead it references the same ObjToObjFunction from the argument. This can have issues if the extractor causes side effects or is stateful. -
HolderSet
public HolderSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, Collection<? extends T> coll) Creates a new set that contains all distinct elements incoll, usingextractorto get the keys that determine distinctness.- Parameters:
extractor- a function that will be used to extract K keys from the T items in collcoll- a Collection of T items; depending on extractor, some different T items may not be added because their K key is equal
-
HolderSet
Creates a new set that contains all distinct elements initems, usingextractorto get the keys that determine distinctness.- Parameters:
extractor- a function that will be used to extract K keys from the T items in collitems- an array of T items; depending on extractor, some different T items may not be added because their K key is equal
-
-
Method Details
-
getExtractor
Gets the function this uses to extract keys from items. This may be null ifHolderSet()was used to construct this object (or technically ifHolderSet(HolderSet)was used to copy a HolderSet with an invalid extractor); in that case, this cannot have items added, removed, or inserted until a valid extractor is set withsetExtractor(ObjToObjFunction).- Returns:
- the extractor function this uses to get keys from items
-
setExtractor
Sets the function this will use to extract keys from items; this will only have an effect if the extractor function is currently null/invalid. This is typically needed ifHolderSet()was used to construct the HolderSet, but can also be required ifHolderSet(HolderSet)was used to copy another HolderSet with an invalid extractor. All other cases should require the extractor function to be specified at construction-time.- Parameters:
extractor- a ObjToObjFunction that takes a T and gets a unique K from it; often a method reference
-
place
Returns an index >= 0 and <=maskfor the specifieditem, mixed.- Parameters:
item- a non-null Object; its hashCode() method should be used by most implementations- Returns:
- an index between 0 and
mask(both inclusive)
-
equate
Compares the objects left and right, which should be K keys (not T items), for equality, returning true if they are considered equal. This is used by the rest of this class to determine whether two keys are considered equal. Normally, this returnsleft.equals(right), but subclasses can override it to use reference equality, fuzzy equality, deep array equality, or any other custom definition of equality. Usually,place(Object)is also overridden if this method is.- Parameters:
left- must be non-null; typically a K key being compared, but not necessarilyright- may be null; typically a K key being compared, but can often be null for an empty key slot, or some other type- Returns:
- true if left and right are considered equal for the purposes of this class
-
locateKey
Returns the index of the key if already present, else~indexfor the next empty index. This callsequate(Object, Object)to determine if two keys are equivalent. This expects key to be a K object, not a T item, and will extract keys from existing items to compare against.- Parameters:
key- a non-null Object that should probably be a K
-
add
Returns true if the item was not already in the set. If this set already contains the item, the call leaves the set unchanged and returns false. Note that this does not take a K key, but a T item -
addAll
-
addAll
- Specified by:
addAllin interfaceEnhancedCollection<T>
-
addAll
- Specified by:
addAllin interfaceEnhancedCollection<T>
-
addAll
-
retainAll
Makes this Set retain a Collection of K key types (not T items). -
removeAll
Removes from this Set a Collection of K key types (not T items). -
removeAll
Description copied from interface:EnhancedCollectionRemoves from this collection all occurrences of any elements contained in the specified array.- Specified by:
removeAllin interfaceEnhancedCollection<T>- Parameters:
values- a non-null array of items to remove fully- Returns:
- true if this collection was modified.
-
removeAll
Description copied from interface:EnhancedCollectionRemoves from this collection all occurrences of any elements contained in the specified array, but only starts reading elements from the array starting at the givenoffsetand only useslengthitems.- Specified by:
removeAllin interfaceEnhancedCollection<T>- Parameters:
values- a non-null array of items to remove fullyoffset- the first index inarrayto uselength- how many items fromarrayshould be used- Returns:
- true if this collection was modified.
-
containsAll
- Specified by:
containsAllin interfaceCollection<T>- Specified by:
containsAllin interfaceSet<T>
-
containsAll
Exactly likecontainsAll(Collection), but takes an array instead of a Collection.- Specified by:
containsAllin interfaceEnhancedCollection<T>- Parameters:
array- array to be checked for containment in this set- Returns:
trueif this set contains all the elements in the specified array- See Also:
-
containsAll
- Specified by:
containsAllin interfaceEnhancedCollection<T>- Parameters:
array- array to be checked for containment in this setoffset- the index of the first item in array to checklength- how many items, at most, to check from array- Returns:
trueif this set contains all the elements in the specified range of array- See Also:
-
containsAnyIterable
Returns true if this set contains any of the specified values.- Specified by:
containsAnyIterablein interfaceEnhancedCollection<T>- Parameters:
values- must not contain nulls, and must not be null itself- Returns:
- true if this set contains any of the items in
values, false otherwise
-
containsAny
Returns true if this set contains any of the specified values.- Specified by:
containsAnyin interfaceEnhancedCollection<T>- Parameters:
values- must not contain nulls, and must not be null itself- Returns:
- true if this set contains any of the items in
values, false otherwise
-
containsAny
Returns true if this set contains any items from the specified range of values.- Specified by:
containsAnyin interfaceEnhancedCollection<T>- Parameters:
values- must not contain nulls, and must not be null itselfoffset- the index to start checking in valueslength- how many items to check from values- Returns:
- true if this set contains any of the items in the given range of
values, false otherwise
-
addResize
Skips checks for existing keys, doesn't increment size. -
remove
Takes a K key and not a T value! Returns true if the key was removed. -
notEmpty
public boolean notEmpty()Returns true if the set has one or more items. -
size
public int size()Returns the number of elements in this set (its cardinality). If this set contains more thanInteger.MAX_VALUEelements, returnsInteger.MAX_VALUE. -
isEmpty
public boolean isEmpty()Returns true if the set is empty. -
shrink
public void shrink(int maximumCapacity) Reduces the size of the backing arrays to be the specified capacity / loadFactor, or less. If the capacity is already less, nothing is done. If the set contains more items than the specified capacity, the next highest power of two capacity is used instead. -
clear
public void clear(int maximumCapacity) Clears the set and reduces the size of the backing arrays to be the specified capacity / loadFactor, if they are larger. The reduction is done by allocating new arrays, though for large arrays this can be faster than clearing the existing array. -
clear
public void clear()Clears the set, leaving the backing arrays at the current capacity. When the capacity is high and the population is low, iteration can be unnecessarily slow.clear(int)can be used to reduce the capacity. -
contains
Checks for the presence of a K key, not a T value. -
get
Given a K key that could have been extracted or extractable from a T item in this, this returns the T item that holds that key, or null if no item holds key.- Parameters:
key- a K key that could have been extracted from a T item in this- Returns:
- the T item that holds the given key, or null if none was found
-
getOrDefault
Given a K key that could have been extracted or extractable from a T item in this, this returns the T item that holds that key, ordefaultValueif no item holds key.- Parameters:
key- a K key that could have been extracted from a T item in thisdefaultValue- the T value to return if key could not be found- Returns:
- the T item that holds the given key, or
defaultValueif none was found
-
first
Gets the (arbitrarily-chosen) first item in this HolderSet. Which item is "first" can change when this resizes, and you can't rely on the order of items in an unordered set like this. If this HolderSet is empty, this will return null. Note that this set cannot contain null.- Specified by:
firstin interfaceEnhancedCollection<T>- Returns:
- the "first" item in this HolderSet; really an arbitrary item in this
-
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.- Parameters:
additionalCapacity- how many additional items this should be able to hold without resizing (probably)
-
resize
protected void resize(int newSize) -
getHashMultiplier
public int getHashMultiplier()Gets the current hashMultiplier, used inplace(Object)to mix hash codes. IfsetHashMultiplier(int)is never called, the hashMultiplier will always be drawn fromUtilities.GOOD_MULTIPLIERS, with the index equal to64 - shift.- Returns:
- the current hashMultiplier
-
setHashMultiplier
public void setHashMultiplier(int hashMultiplier) Sets the hashMultiplier to the given int, which will be made odd if even and always negative (by OR-ing with 0x80000001). This can be any negative, odd int, but should almost always be drawn fromUtilities.GOOD_MULTIPLIERSor something like it.- Parameters:
hashMultiplier- any int; will be made odd if even.
-
getTableSize
public int getTableSize()Gets the length of the internal array used to store all items, as well as empty space awaiting more items to be entered. This is also called the capacity.- Returns:
- the length of the internal array that holds all items
-
toArray
-
toArray
public <E> E[] toArray(E[] a) Returns an array containing all the elements in this set; the runtime type of the returned array is that of the specified array. If the set fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this set.
Implementation is mostly copied from GWT, but uses Arrays.copyOf() instead of their internal APIs.- Specified by:
toArrayin interfaceCollection<T>- Specified by:
toArrayin interfaceSet<T>- Type Parameters:
E- must be the same asTor a superclass/interface of it; not checked- Parameters:
a- the array into which the elements of this set are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.- Returns:
- an array containing all the elements in this set
-
getLoadFactor
public float getLoadFactor() -
setLoadFactor
public void setLoadFactor(float loadFactor) -
hashCode
public int hashCode() -
equals
-
toString
-
truncate
public void truncate(int newSize) Reduces the size of the set to the specified size. If the set is already smaller than the specified size, no action is taken. This indiscriminately removes items from the backing array until the requested newSize is reached, or until the full backing array has had its elements removed.
This tries to remove from the end of the iteration order, but because the iteration order is not guaranteed by an unordered set, this can remove essentially any item(s) from the set if it is larger than newSize.- Parameters:
newSize- the target size to try to reach by removing items, if smaller than the current size
-
iterator
Returns an iterator for the keys in the set. Remove is supported.Reuses one of two iterators for this set. For nested or multithreaded iteration, use
HolderSetIterator(HolderSet). -
with
public static <T,K> HolderSet<T,K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor) Constructs an empty set given only an extractor function. 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:
T- the type of items; must be given explicitlyK- the type of keys that extractor pulls from T items- Parameters:
extractor- a ObjToObjFunction that takes a T and gets a unique K from it; often a method reference- Returns:
- a new set containing nothing
-
with
public static <T,K> HolderSet<T,K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item) Creates a new HolderSet that holds only the given item, but can be resized.- Type Parameters:
T- the type of item, typically inferredK- the type of keys that extractor pulls from T items- Parameters:
extractor- a ObjToObjFunction that takes a T and gets a unique K from it; often a method referenceitem- one T item- Returns:
- a new HolderSet that holds the given item
-
with
public static <T,K> HolderSet<T,K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item0, T item1) Creates a new HolderSet that holds only the given items, but can be resized.- Type Parameters:
T- the type of item, typically inferredK- the type of keys that extractor pulls from T items- Parameters:
extractor- a ObjToObjFunction that takes a T and gets a unique K from it; often a method referenceitem0- a T itemitem1- a T item- Returns:
- a new HolderSet that holds the given items
-
with
public static <T,K> HolderSet<T,K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item0, T item1, T item2) Creates a new HolderSet that holds only the given items, but can be resized.- Type Parameters:
T- the type of item, typically inferredK- the type of keys that extractor pulls from T items- Parameters:
extractor- a ObjToObjFunction that takes a T and gets a unique K from it; often a method referenceitem0- a T itemitem1- a T itemitem2- a T item- Returns:
- a new HolderSet that holds the given items
-
with
public static <T,K> HolderSet<T,K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item0, T item1, T item2, T item3) Creates a new HolderSet that holds only the given items, but can be resized.- Type Parameters:
T- the type of item, typically inferredK- the type of keys that extractor pulls from T items- Parameters:
extractor- a ObjToObjFunction that takes a T and gets a unique K from it; often a method referenceitem0- a T itemitem1- a T itemitem2- a T itemitem3- a T item- Returns:
- a new HolderSet that holds the given items
-
with
public static <T,K> HolderSet<T,K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item0, T item1, T item2, T item3, T item4) Creates a new HolderSet that holds only the given items, but can be resized.- Type Parameters:
T- the type of item, typically inferredK- the type of keys that extractor pulls from T items- Parameters:
extractor- a ObjToObjFunction that takes a T and gets a unique K from it; often a method referenceitem0- a T itemitem1- a T itemitem2- a T itemitem3- a T itemitem4- a T item- Returns:
- a new HolderSet that holds the given items
-
with
public static <T,K> HolderSet<T,K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item0, T item1, T item2, T item3, T item4, T item5) Creates a new HolderSet that holds only the given items, but can be resized.- Type Parameters:
T- the type of item, typically inferredK- the type of keys that extractor pulls from T items- Parameters:
extractor- a ObjToObjFunction that takes a T and gets a unique K from it; often a method referenceitem0- a T itemitem1- a T itemitem2- a T itemitem3- a T itemitem4- a T itemitem5- a T item- Returns:
- a new HolderSet that holds the given items
-
with
public static <T,K> HolderSet<T,K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item0, T item1, T item2, T item3, T item4, T item5, T item6) Creates a new HolderSet that holds only the given items, but can be resized.- Type Parameters:
T- the type of item, typically inferredK- the type of keys that extractor pulls from T items- Parameters:
extractor- a ObjToObjFunction that takes a T and gets a unique K from it; often a method referenceitem0- a T itemitem1- a T itemitem2- a T itemitem3- a T itemitem4- a T itemitem5- a T itemitem6- a T item- Returns:
- a new HolderSet that holds the given items
-
with
public static <T,K> HolderSet<T,K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item0, T item1, T item2, T item3, T item4, T item5, T item6, T item7) Creates a new HolderSet that holds only the given items, but can be resized.- Type Parameters:
T- the type of item, typically inferredK- the type of keys that extractor pulls from T items- Parameters:
extractor- a ObjToObjFunction that takes a T and gets a unique K from it; often a method referenceitem0- a T itemitem1- a T itemitem2- a T itemitem3- a T itemitem4- a T itemitem5- a T itemitem6- a T item- Returns:
- a new HolderSet that holds the given items
-
with
@SafeVarargs public static <T,K> HolderSet<T,K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T... varargs) Creates a new HolderSet that holds only the given items, but can be resized. This overload will only be used when an array is supplied and the type of the items requested is the component type of the array, or if varargs are used and there are 9 or more arguments.- Type Parameters:
T- the type of item, typically inferredK- the type of keys that extractor pulls from T items- Parameters:
extractor- a ObjToObjFunction that takes a T and gets a unique K from it; often a method referencevarargs- a T varargs or T array; remember that varargs allocate- Returns:
- a new HolderSet that holds the given items
-
parse
public static <T,K> HolderSet<T,K> parse(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, String str, String delimiter, PartialParser<T> parser) Callsparse(ObjToObjFunction, String, String, PartialParser, boolean)with brackets set to false.- Type Parameters:
T- the type of item, typically inferredK- the type of keys that extractor pulls from T items- Parameters:
extractor- a ObjToObjFunction that takes a T and gets a unique K from it; often a method referencestr- a String that will be parsed in fulldelimiter- the delimiter between items in strparser- a PartialParser that returns aTitem from a section ofstr- Returns:
- a new collection parsed from str
-
parse
public static <T,K> HolderSet<T,K> parse(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, String str, String delimiter, PartialParser<T> parser, boolean brackets) Creates a new HolderSet usingextractorand fills it by callingEnhancedCollection.addLegible(String, String, PartialParser, int, int)on either all ofstr(ifbracketsis false) orstrwithout its first and last chars (ifbracketsis true). Each item is expected to be separated bydelimiter.- Type Parameters:
T- the type of item, typically inferredK- the type of keys that extractor pulls from T items- Parameters:
extractor- a ObjToObjFunction that takes a T and gets a unique K from it; often a method referencestr- a String that will be parsed in full (depending on brackets)delimiter- the delimiter between items in strparser- a PartialParser that returns aTitem from a section ofstrbrackets- if true, the first and last chars in str will be ignored- Returns:
- a new collection parsed from str
-
parse
public static <T,K> HolderSet<T,K> parse(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, String str, String delimiter, PartialParser<T> parser, int offset, int length) Creates a new HolderSet usingextractorand fills it by callingEnhancedCollection.addLegible(String, String, PartialParser, int, int)with the other five parameters as-is.- Type Parameters:
T- the type of item, typically inferredK- the type of keys that extractor pulls from T items- Parameters:
extractor- a ObjToObjFunction that takes a T and gets a unique K from it; often a method referencestr- a String that will have the given section parseddelimiter- the delimiter between items in strparser- a PartialParser that returns aTitem from a section ofstroffset- the first position to parse in str, inclusivelength- how many chars to parse, starting from offset- Returns:
- a new collection parsed from str
-