Package com.github.tommyettinger.ds
Interface Ordered.OfChar
- All Superinterfaces:
Arrangeable,CharSequence
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.github.tommyettinger.ds.Arrangeable
Arrangeable.ArrangeableList<T> -
Method Summary
Modifier and TypeMethodDescriptiondefault charcharAt(int index) Equivalent to callingCharList.get(int)onorder().default OrderTypedefault booleanisEmpty()Returns true if this data structure has no items (itsArrangeable.size()is 0), or false otherwise.default intlength()Compatibility alias forArrangeable.size().order()Gets the CharList of char items that this data structure holds, in the order it uses for iteration.default charrandom()Returns a random item from the list, or zero if the list is empty.default charGets a random char value from this Ordered, using the given random number generator.default voidremoveRange(int start, int end) Removes items from the ordering (and potentially only the ordering, depending on implementation) between start, inclusive, and end, exclusive.default voidreverse()Reverses the order of this Ordered in-place.default charselectRanked(CharComparator comparator, int kthLowest) Selects the kth-lowest element from this Ordered according to CharComparator ranking.default intselectRankedIndex(CharComparator comparator, int kthLowest) Gets the index of the kth-lowest element from this Ordered according to CharComparator ranking.default voidPseudo-randomly shuffles the order of this Ordered in-place.default voidsort(CharComparator comparator) Sorts this Ordered according to the order induced by the specifiedCharComparator.default CharListsubSequence(int start, int end) Creates a new sub-list (not a view) of the given range of this data structure.default voidswap(int first, int second) Switches the ordering of positionsfirstandsecond, without changing any items beyond that.Methods inherited from interface com.github.tommyettinger.ds.Arrangeable
rearrange, shuffle, sizeMethods inherited from interface java.lang.CharSequence
chars, codePoints, toString
-
Method Details
-
order
CharList order()Gets the CharList of char items that this data structure holds, in the order it uses for iteration. This should usually return a direct reference to an CharList used inside this object, so changes to the list will affect this.- Returns:
- the CharList of char items that this data structure holds
-
swap
default void swap(int first, int second) Switches the ordering of positionsfirstandsecond, without changing any items beyond that.- Specified by:
swapin interfaceArrangeable- Parameters:
first- the first position, must not be negative and must be less thanArrangeable.size()second- the second position, must not be negative and must be less thanArrangeable.size()
-
shuffle
Pseudo-randomly shuffles the order of this Ordered in-place. You can seedrng, the random number generator, with an identical seed to reproduce a shuffle on two Ordered with the sameArrangeable.size().- Specified by:
shufflein interfaceArrangeable- Parameters:
rng- anyRandomclass, such as one from juniper
-
reverse
default void reverse()Reverses the order of this Ordered in-place.- Specified by:
reversein interfaceArrangeable
-
random
default char random()Returns a random item from the list, or zero if the list is empty. UsesArrayTools.RANDOMas its random number generator, which is randomly seeded.- Returns:
- a randomly selected item from this, or
0if this is empty
-
random
Gets a random char value from this Ordered, using the given random number generator.
This should return(char)(0)if the Ordered is empty.- Parameters:
rng- anyRandomclass- Returns:
- a random char value from this Ordered.OfChar
-
sort
Sorts this Ordered according to the order induced by the specifiedCharComparator. The sort is stable: this method must not reorder equal elements.
If the specified comparator isnullthen the numeric elements' natural ordering should be used.- Parameters:
comparator- used to sort the T items this contains; may be null to use natural ordering
-
selectRanked
Selects the kth-lowest element from this Ordered according to CharComparator ranking. This might partially sort the Ordered, changing its order. The Ordered must have a size greater than 0, or aRuntimeExceptionwill be thrown.- Parameters:
comparator- used for comparisonkthLowest- rank of desired object according to comparison; k is based on ordinal numbers, not array indices. For min value use 1, for max value use size of the Ordered; using 0 results in a runtime exception.- Returns:
- the value of the kth lowest ranked item.
- See Also:
-
selectRankedIndex
Gets the index of the kth-lowest element from this Ordered according to CharComparator ranking. This might partially sort the Ordered, changing its order. The Ordered must have a size greater than 0, or aRuntimeExceptionwill be thrown.- Parameters:
comparator- used for comparisonkthLowest- rank of desired object according to comparison; k is based on ordinal numbers, not array indices. For min value use 1, for max value use size of the Ordered; using 0 results in a runtime exception.- Returns:
- the index of the kth lowest ranked item.
- See Also:
-
removeRange
default void removeRange(int start, int end) Removes items from the ordering (and potentially only the ordering, depending on implementation) between start, inclusive, and end, exclusive.- Parameters:
start- inclusive start of the range to remove from the orderingend- exclusive end of the range to remove from the ordering
-
getOrderType
-
length
default int length()Compatibility alias forArrangeable.size(). Here for compatibility with CharSequence.- Specified by:
lengthin interfaceCharSequence- Returns:
- how many items are contained in this data structure
-
charAt
default char charAt(int index) Equivalent to callingCharList.get(int)onorder(). Here for compatibility with CharSequence.- Specified by:
charAtin interfaceCharSequence- Parameters:
index- the index of thecharvalue to be returned- Returns:
- the char at the given index in the ordering
-
isEmpty
default boolean isEmpty()Returns true if this data structure has no items (itsArrangeable.size()is 0), or false otherwise. Here for compatibility with CharSequence.- Specified by:
isEmptyin interfaceCharSequence- Returns:
- true if this data structure has no items, or false otherwise.
-
subSequence
Creates a new sub-list (not a view) of the given range of this data structure. Here for compatibility with CharSequence.
This is typically overridden to return the same type as this data structure, though this is not required.- Specified by:
subSequencein interfaceCharSequence- Parameters:
start- the start index, inclusiveend- the end index, exclusive- Returns:
- a new sub-list of this data structure, which is also a CharSequence
-