Class HolderOrderedSet<T,K>
- All Implemented Interfaces:
Arrangeable,EnhancedCollection<T>,Ordered<T>,Iterable<T>,Collection<T>,Set<T>
HolderSet that also stores items in an ObjectList using the insertion order. This acts like
HolderSet instead of like ObjectSet, with the constructors typically taking an extractor function,
HolderSet.contains(Object) and remove(Object) accepting a K key instead of a T item, and
HolderSet.get(Object) used to get a T item from a K key. Neither null items nor null keys are allowed.
No allocation is done except when growing the table size.
Iteration is ordered over items and faster than an unordered set. Items 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
HolderOrderedSet and ObjectObjectOrderedMap.
You can customize most behavior of this set by extending it. HolderSet.place(Object) can be overridden to change how hashCodes
are calculated on K keys (which can be useful for types like StringBuilder that don't implement hashCode()), and
HolderSet.locateKey(Object) can be overridden to change how equality is calculated for K keys.
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 ClassesNested classes/interfaces inherited from class com.github.tommyettinger.ds.HolderSet
HolderSet.HolderSetIterator<T,K> 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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new set with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor().HolderOrderedSet(HolderOrderedSet<T, K> set) Creates a new set identical to the specified set.HolderOrderedSet(HolderOrderedSet<T, K> set, OrderType type) Creates a new set identical to the specified set.HolderOrderedSet(OrderType type) Creates a new set with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor().HolderOrderedSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor) Creates a new set with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor().HolderOrderedSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, int initialCapacity) Creates a new set with a load factor ofUtilities.getDefaultLoadFactor().HolderOrderedSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, int initialCapacity, float loadFactor) Creates a new set with the specified initial capacity and load factor.HolderOrderedSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, int initialCapacity, float loadFactor, OrderType type) Creates a new set with the specified initial capacity and load factor.HolderOrderedSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, int initialCapacity, OrderType type) Creates a new set with a load factor ofUtilities.getDefaultLoadFactor().HolderOrderedSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, Ordered<T> other, int offset, int count) Creates a new set by copyingcountitems from the given Ordered, starting atoffsetin that Ordered, into this, usingextractorto get the keys that determine distinctness.HolderOrderedSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, Ordered<T> other, int offset, int count, OrderType type) Creates a new set by copyingcountitems from the given Ordered, starting atoffsetin that Ordered, into this, usingextractorto get the keys that determine distinctness.HolderOrderedSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, OrderType type) Creates a new set with an initial capacity ofUtilities.getDefaultTableCapacity()and a load factor ofUtilities.getDefaultLoadFactor().HolderOrderedSet(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.HolderOrderedSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, Collection<? extends T> coll, OrderType type) Creates a new set that contains all distinct elements incoll, usingextractorto get the keys that determine distinctness.HolderOrderedSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, Iterator<? extends T> coll) Creates a new instance containing the items in the specified iterator.HolderOrderedSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, Iterator<? extends T> coll, OrderType type) Creates a new instance containing the items in the specified iterator.HolderOrderedSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T[] items) Creates a new set that contains all distinct elements initems, usingextractorto get the keys that determine distinctness.HolderOrderedSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T[] items, OrderType type) Creates a new set that contains all distinct elements initems, usingextractorto get the keys that determine distinctness. -
Method Summary
Modifier and TypeMethodDescriptionbooleanSets the key at the specified index.booleanReturns true if the item was not already in the set.booleanAdds up tocountitems, starting fromoffset, in the Orderedotherto this set, inserting starting atinsertionIndexin the iteration order.booleanaddAll(HolderOrderedSet<T, ?> set) booleanAdds up tocountitems, starting fromoffset, in the Orderedotherto this set, inserting at the end of the iteration order.booleanChanges the itembeforetoafterwithout changing its position in the order.booleanChanges the item at the givenindexin the order toafter, without changing the ordering of other items.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.voidensureCapacity(int additionalCapacity) Increases the size of the backing array to accommodate the specified number of additional items / loadFactor.first()Gets the first item in the order.getAt(int index) Gets the T item at the givenindexin the insertion order.inthashCode()iterator()Iterates through items in the same order asorder().order()Gets the ObjectList of T items in the order this class will iterate through them.static <T,K> HolderOrderedSet<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> HolderOrderedSet<T, K> parse(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, String str, String delimiter, PartialParser<T> parser, boolean brackets) Creates a new HolderOrderedSet 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> HolderOrderedSet<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 HolderOrderedSet usingextractorand fills it by callingEnhancedCollection.addLegible(String, String, PartialParser, int, int)with the other five parameters as-is.booleanTakes a K key to remove from this HolderOrderedSet, not a T item.removeAt(int index) Removes and returns the item at the given index in this set's order.voidremoveRange(int start, int end) Removes the items between the specified start index, inclusive, and end index, exclusive.voidsort()Sorts this ObjectOrderedSet in-place by the T items' natural ordering;Tmust implementComparable.voidsort(Comparator<? super T> comp) Sorts this ObjectOrderedSet in-place by the given Comparator used on the T items.toString()Delegates toEnhancedCollection.toString(String, boolean)with the given itemSeparator and without surrounding brackets.voidtruncate(int newSize) Reduces the size of the set to the specified size.static <T,K> HolderOrderedSet<T, K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor) Constructs an empty set given only an extractor function.static <T,K> HolderOrderedSet<T, K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item) Creates a new HolderOrderedSet that holds only the given item, but can be resized.static <T,K> HolderOrderedSet<T, K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T... varargs) Creates a new HolderOrderedSet that holds only the given items, but can be resized.static <T,K> HolderOrderedSet<T, K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item0, T item1) Creates a new HolderOrderedSet that holds only the given items, but can be resized.static <T,K> HolderOrderedSet<T, K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item0, T item1, T item2) Creates a new HolderOrderedSet that holds only the given items, but can be resized.static <T,K> HolderOrderedSet<T, K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item0, T item1, T item2, T item3) Creates a new HolderOrderedSet that holds only the given items, but can be resized.static <T,K> HolderOrderedSet<T, K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item0, T item1, T item2, T item3, T item4) Creates a new HolderOrderedSet that holds only the given items, but can be resized.static <T,K> HolderOrderedSet<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 HolderOrderedSet that holds only the given items, but can be resized.static <T,K> HolderOrderedSet<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 HolderOrderedSet that holds only the given items, but can be resized.static <T,K> HolderOrderedSet<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 HolderOrderedSet that holds only the given items, but can be resized.Methods inherited from class com.github.tommyettinger.ds.HolderSet
addAll, addAll, addAll, addAll, addResize, contains, containsAll, containsAll, containsAll, containsAny, containsAny, containsAnyIterable, equals, equate, get, getExtractor, getHashMultiplier, getLoadFactor, getOrDefault, getTableSize, isEmpty, locateKey, notEmpty, place, removeAll, removeAll, removeAll, resize, retainAll, setExtractor, setHashMultiplier, setLoadFactor, shrink, size, toArray, toArrayMethods 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.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, toStringMethods inherited from interface com.github.tommyettinger.ds.Ordered
getOrderType, random, random, reverse, selectRanked, selectRankedIndex, shuffle, swapMethods inherited from interface java.util.Set
spliterator
-
Field Details
-
items
-
-
Constructor Details
-
HolderOrderedSet
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 untilHolderSet.setExtractor(ObjToObjFunction)is called with a valid ObjToObjFunction that gets K keys from T items.- 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
-
HolderOrderedSet
public HolderOrderedSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, OrderType type) 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 thistype- 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
-
HolderOrderedSet
public HolderOrderedSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, int initialCapacity, OrderType type) 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.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
-
HolderOrderedSet
public HolderOrderedSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, int initialCapacity, float loadFactor, OrderType type) 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 <= 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
-
HolderOrderedSet
public HolderOrderedSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, Iterator<? extends T> coll, OrderType type) Creates a new instance containing the items in the specified iterator.- Parameters:
coll- an iterator that will have its remaining contents added to thistype- 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
-
HolderOrderedSet
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.- Parameters:
set- another HolderOrderedSet which will have its contents copiedtype- 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
-
HolderOrderedSet
public HolderOrderedSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, Collection<? extends T> coll, OrderType type) 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 equaltype- 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
-
HolderOrderedSet
public HolderOrderedSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T[] items, OrderType type) 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 equaltype- 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
-
HolderOrderedSet
public HolderOrderedSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, Ordered<T> other, int offset, int count, OrderType type) Creates a new set by copyingcountitems from the given Ordered, starting atoffsetin that Ordered, into this, usingextractorto get the keys that determine distinctness.- Parameters:
extractor- a function that will be used to extract K keys from the T items in collother- another Ordered of the same typeoffset- the first index in other's ordering to draw an item fromcount- how many items to copy from othertype- 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
-
HolderOrderedSet
public HolderOrderedSet()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 untilHolderSet.setExtractor(ObjToObjFunction)is called with a valid ObjToObjFunction that gets K keys from T items. -
HolderOrderedSet
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
-
HolderOrderedSet
public HolderOrderedSet(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.
-
HolderOrderedSet
public HolderOrderedSet(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
-
HolderOrderedSet
public HolderOrderedSet(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
-
HolderOrderedSet
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. -
HolderOrderedSet
public HolderOrderedSet(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
-
HolderOrderedSet
public HolderOrderedSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T[] items) 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
-
HolderOrderedSet
public HolderOrderedSet(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, Ordered<T> other, int offset, int count) Creates a new set by copyingcountitems from the given Ordered, starting atoffsetin that Ordered, into this, usingextractorto get the keys that determine distinctness.- Parameters:
extractor- a function that will be used to extract K keys from the T items in collother- another Ordered 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
-
add
Description copied from class:HolderSetReturns 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 -
add
Sets the key at the specified index. Returns true if the key was not already in the set. If this set already contains the key, the existing key's index is changed if needed and false is returned. Note, the order of the parameters matches the order inObjectListand the rest of the JDK, not OrderedSet in libGDX.- Parameters:
index- where in the iteration order to add the given key, or to move it if already presentkey- what T item to try to add, if not already present- Returns:
- true if the key was added for the first time, or false if the key was already present (even if moved)
-
addAll
-
addAll
Adds up tocountitems, starting fromoffset, in the Orderedotherto this set, inserting at the end of the iteration order.- Parameters:
other- a non-nullOrderedofToffset- the first index inotherto usecount- how many indices inotherto use- Returns:
- true if this is modified by this call, as
HolderSet.addAll(Collection)does
-
addAll
Adds up tocountitems, starting fromoffset, in the Orderedotherto this set, inserting starting atinsertionIndexin the iteration order.- Parameters:
insertionIndex- where to insert into the iteration orderother- a non-nullOrderedofToffset- the first index inotherto usecount- how many indices inotherto use- Returns:
- true if this is modified by this call, as
HolderSet.addAll(Collection)does
-
remove
Takes a K key to remove from this HolderOrderedSet, not a T item. -
removeAt
Removes and returns the item at the given index in this set's order.- Parameters:
index- the index of the item to remove- Returns:
- the removed item
-
first
Gets the first item in the order. If the set is empty, this returns null. Note that this set cannot contain null. -
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 classHolderSet<T,K> - Parameters:
additionalCapacity- how many additional items this should be able to hold without resizing (probably)
-
alter
Changes the itembeforetoafterwithout changing its position in the order. Returns true ifafterhas been added to the ObjectOrderedSet andbeforehas been removed; returns false ifafteris already present orbeforeis not present. If you are iterating over an ObjectOrderedSet and have an index, you should preferalterAt(int, Object), which doesn't need to search for an index like this does and so can be faster.- Parameters:
before- an item that must be present for this to succeedafter- an item that must not be in this set for this to succeed- Returns:
- true if
beforewas removed andafterwas added, false otherwise
-
alterAt
Changes the item at the givenindexin the order toafter, without changing the ordering of other items. Ifafteris already present, this returns false; it will also return false ifindexis invalid for the size of this set. Otherwise, it returns true. Unlikealter(Object, Object), this operates in constant time.- Parameters:
index- the index in the order of the item to change; must be non-negative and less thanHolderSet.sizeafter- the item that will replace the contents atindex; this item must not be present for this to succeed- Returns:
- true if
aftersuccessfully replaced the contents atindex, false otherwise
-
getAt
Gets the T item at the givenindexin the insertion order. The index should be between 0 (inclusive) andHolderSet.size()(exclusive).- Parameters:
index- an index in the insertion order, between 0 (inclusive) andHolderSet.size()(exclusive)- Returns:
- the item at the given index
-
clear
public void clear(int maximumCapacity) Description copied from class:HolderSetClears 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()Description copied from class:HolderSetClears 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.HolderSet.clear(int)can be used to reduce the capacity. -
order
Gets the ObjectList of T items in the order this class will iterate through them. Returns a direct reference to the same ObjectList this uses, so changes to the returned list will also change the iteration order here. -
sort
public void sort()Sorts this ObjectOrderedSet in-place by the T items' natural ordering;Tmust implementComparable. -
sort
Sorts this ObjectOrderedSet in-place by the given Comparator used on the T items. Ifcompis null, then this will sort by the natural ordering of the items, which requiresTtoComparable. -
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<T>- 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 set to the specified size. If the set is already smaller than the specified size, no action is taken. -
iterator
Iterates through items in the same order asorder(). Reuses one of two iterators, and does not permit nested iteration; useHolderOrderedSetIterator(HolderOrderedSet)to nest iterators. -
hashCode
public int hashCode() -
toString
Description copied from interface:EnhancedCollectionDelegates toEnhancedCollection.toString(String, boolean)with the given itemSeparator and without surrounding brackets.- Specified by:
toStringin interfaceEnhancedCollection<T>- Parameters:
itemSeparator- how to separate items, such as", "- Returns:
- a new String representing this map
-
toString
-
with
public static <T,K> HolderOrderedSet<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> HolderOrderedSet<T,K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item) Creates a new HolderOrderedSet 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 HolderOrderedSet that holds the given item
-
with
public static <T,K> HolderOrderedSet<T,K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item0, T item1) Creates a new HolderOrderedSet 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 HolderOrderedSet that holds the given items
-
with
public static <T,K> HolderOrderedSet<T,K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item0, T item1, T item2) Creates a new HolderOrderedSet 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 HolderOrderedSet that holds the given items
-
with
public static <T,K> HolderOrderedSet<T,K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item0, T item1, T item2, T item3) Creates a new HolderOrderedSet 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 HolderOrderedSet that holds the given items
-
with
public static <T,K> HolderOrderedSet<T,K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T item0, T item1, T item2, T item3, T item4) Creates a new HolderOrderedSet 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 HolderOrderedSet that holds the given items
-
with
public static <T,K> HolderOrderedSet<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 HolderOrderedSet 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 HolderOrderedSet that holds the given items
-
with
public static <T,K> HolderOrderedSet<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 HolderOrderedSet 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 HolderOrderedSet that holds the given items
-
with
public static <T,K> HolderOrderedSet<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 HolderOrderedSet 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 HolderOrderedSet that holds the given items
-
with
@SafeVarargs public static <T,K> HolderOrderedSet<T,K> with(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, T... varargs) Creates a new HolderOrderedSet 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 HolderOrderedSet that holds the given items
-
parse
public static <T,K> HolderOrderedSet<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> HolderOrderedSet<T,K> parse(com.github.tommyettinger.function.ObjToObjFunction<T, K> extractor, String str, String delimiter, PartialParser<T> parser, boolean brackets) Creates a new HolderOrderedSet 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> HolderOrderedSet<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 HolderOrderedSet 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
-