Package com.github.tommyettinger.ds
Class CharList
java.lang.Object
com.github.tommyettinger.ds.CharList
- All Implemented Interfaces:
Arrangeable,Ordered.OfChar,PrimitiveCollection<Character>,PrimitiveCollection.OfChar,Appendable,CharSequence,Comparable<CharList>
public class CharList
extends Object
implements PrimitiveCollection.OfChar, Ordered.OfChar, Arrangeable, CharSequence, Appendable, Comparable<CharList>
A resizable, insertion-ordered char list. Primitive-backed, so it avoids the boxing that occurs with an ArrayList of Character.
This tries to imitate most of the
List interface, though it can't implement it without boxing its items.
Has a primitive iterator accessible via iterator().-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classACharIterator, plusListIteratormethods, over the elements of a CharList.Nested classes/interfaces inherited from interface com.github.tommyettinger.ds.Arrangeable
Arrangeable.ArrangeableList<T>Nested classes/interfaces inherited from interface com.github.tommyettinger.ds.PrimitiveCollection
PrimitiveCollection.OfBoolean, PrimitiveCollection.OfByte, PrimitiveCollection.OfChar, PrimitiveCollection.OfDouble, PrimitiveCollection.OfFloat, PrimitiveCollection.OfInt, PrimitiveCollection.OfLong, PrimitiveCollection.OfShort -
Field Summary
FieldsModifier and TypeFieldDescriptionchar[]protected CharList.CharListIteratorprotected CharList.CharListIteratorprotected int -
Constructor Summary
ConstructorsConstructorDescriptionCharList()Creates an ordered list with a capacity of 10.CharList(boolean ordered, char[] array, int startIndex, int count) Deprecated.CharList(boolean ordered, int capacity) Deprecated.CharList is always ordered; for an unordered list useCharBagCharList(char[] array) Creates a new list containing the elements in the specified array.CharList(char[] array, int startIndex, int count) Creates a new list containing the elements in the specified array.CharList(int capacity) Creates an ordered list with the specified capacity.Creates a new list containing the elements in the given list.CharList(Ordered.OfChar other) Copies the given Ordered.OfChar into a new CharList.CharList(Ordered.OfChar other, int offset, int count) Creates a new list by copyingcountitems from the given Ordered, starting atoffsetin that Ordered, into this.Creates a new list containing the items in the specified PrimitiveCollection.OfChar.CharList(CharIterator coll) Creates a new instance containing the items in the specified iterator.CharList(CharSequence other) CharList(CharSequence other, int start, int end) Creates a new CharList from part of another CharSequence; start is inclusive and end is exclusive. -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(char value) voidadd(char value1, char value2) voidadd(char value1, char value2, char value3) voidadd(char value1, char value2, char value3, char value4) booleanaddAll(char... array) booleanaddAll(char[] array, int offset, int length) booleanaddAll(int insertionIndex, Ordered.OfChar other, int offset, int count) Adds up tocountitems, starting fromoffset, in the Ordered.OfCharotherto this list, inserting starting atinsertionIndexin the iteration order.booleanbooleanbooleanaddAll(Ordered.OfChar other, int offset, int count) Adds up tocountitems, starting fromoffset, in the Ordered.OfCharotherto this list, inserting at the end of the iteration order.append(boolean value) Appends either the four chars't', 'r', 'u', 'e'ifvalueis true, or the five chars'f', 'a', 'l', 's', 'e'if it is false.append(char c) append(double number) Appends the base-10 decimal or engineering textual form of the given number, without allocating.append(float number) Appends the base-10 decimal or engineering textual form of the given number, without allocating.append(int number) Appends the base-10 signed textual form of the given number, without allocating.append(long number) Appends the base-10 signed textual form of the given number, without allocating.append(CharSequence csq) append(CharSequence csq, int start, int end) Appends a literal newline (Unicode character u000A).charcharAt(int index) Equivalent to callingget(int)onOrdered.OfChar.order().voidclear()Effectively removes all items from this CharList.intintcompareWith(CharSequence other) Compares this CharList with an arbitrary CharSequence type, returning the lexicographical comparison of the two as if Java 11'sCharSequence.compare()was called on this andother.intCompares this CharList with an arbitrary CharSequence type, returning the lexicographical comparison of the two as if Java 11'sCharSequence.compare()was called on this if it had been entirely raised to upper case andotherif it also had been entirely raised to upper case.booleancontains(char value) booleancontains(CharSequence csq) Simply callsindexOf(CharSequence)and checks that it doesn't return-1.booleancontainsAll(CharList other) Returns true if this CharList contains, at least once, every item inother; otherwise returns false.booleanSimply callsindexOfIgnoreCase(CharSequence)and checks that it doesn't return-1.booleanduplicateRange(int index, int count) Inserts the specified number of items at the specified index.char[]ensureCapacity(int additionalCapacity) Increases the size of the backing array to accommodate the specified number of additional items.booleanbooleanChecks if this is equal to another CharSequence, but runs all chars in both the given text and this throughCasing.caseUp(char)before comparing (making the comparison case-insensitive for almost all scripts in use today, except some situations for Georgian).charfirst()Returns the first item.charget(int index) inthashCode()intindexOf(char search) Returns the first index in this list that containssearch, or -1 if it is not present.intindexOf(char search, int fromIndex) Tries to return the first indexsearchappears at in this list, starting atfromIndex; ifsearchis not present, this returns -1.intindexOf(CharSequence search) Tries to return the first indexsearchappears at in this list, starting at index 0; ifsearchis not present, this returns -1.intindexOf(CharSequence search, int fromIndex) Tries to return the first indexsearchappears at in this list, starting atfromIndex; ifsearchis not present, this returns -1.intindexOfIgnoreCase(char search) Returns the first index in this list that containssearch, or -1 if it is not present.intindexOfIgnoreCase(char search, int fromIndex) Tries to return the first indexsearchappears at in this list, starting atfromIndex; ifsearchis not present, this returns -1.intindexOfIgnoreCase(CharSequence search) Tries to return the first indexsearchappears at in this list, starting at index 0; ifsearchis not present, this returns -1.intindexOfIgnoreCase(CharSequence search, int fromIndex) Tries to return the first indexsearchappears at in this list, starting atfromIndex; ifsearchis not present, this returns -1.voidinsert(int index, char value) booleanisEmpty()Returns true if the list is empty.iterator()Returns a Java 8 primitive iterator over the int items in this CharList.booleanReturns true if this implementation retains order, which it does.intlastIndexOf(char search) Returns the last index in this list that containssearch, or -1 if it is not present.intlastIndexOf(char search, int fromIndex) Returns the last index in this list that containssearch, starting the search atfromIndex(inclusive) and moving toward the start, or -1 if it is not present.intlastIndexOf(CharSequence search) Tries to return the first indexsearchappears at in this list, starting the search at the end and working toward the start; ifsearchis not present, this returns -1.intlastIndexOf(CharSequence search, int fromIndex) Tries to return the first indexsearchappears at in this list, starting the search atfromIndexand working toward the start; ifsearchis not present, this returns -1.intlastIndexOfIgnoreCase(char search) Returns the last index in this list that containssearch, or -1 if it is not present.intlastIndexOfIgnoreCase(char search, int fromIndex) Returns the last index in this list that containssearch, starting the search atfromIndex(inclusive) and moving toward the start, or -1 if it is not present.intlastIndexOfIgnoreCase(CharSequence search) Tries to return the first indexsearchappears at in this list, starting the search at the end and working toward the start; ifsearchis not present, this returns -1.intlastIndexOfIgnoreCase(CharSequence search, int fromIndex) Tries to return the first indexsearchappears at in this list, starting the search atfromIndexand working toward the start; ifsearchis not present, this returns -1.leftString(int length) Creates a new String by copying the given subrange of this CharList, from index 0 (inclusive) tolength(exclusive).intlength()Compatibility alias forArrangeable.size().line()Appends a literal newline (Unicode character u000A).booleannotEmpty()Returns true if the list has one or more items, or false otherwise.order()Returns this CharList, since it is its own order.padLeft(int count, char padWith) Addscountrepetitions ofpadWithto the start (left) of this list.padRight(int count, char padWith) Addscountrepetitions ofpadWithto the end (right) of this list.static CharListCallsparse(String, String, boolean)with brackets set to false.static CharListCreates a new collection and fills it by callingPrimitiveCollection.OfChar.addLegible(String, String, int, int)on either all ofstr(ifbracketsis false) orstrwithout its first and last chars (ifbracketsis true).static CharListCreates a new collection and fills it by callingPrimitiveCollection.OfChar.addLegible(String, String, int, int)with the given four parameters as-is.charpeek()Returns the last item.charpop()Removes and returns the last item.charReturns a random item from the list, or zero if the list is empty, using the given random number generator.booleanremove(char value) Removes the first occurrence ofvaluefrom this CharList, returning true if anything was removed.booleanRemoves from this CharList all occurrences of any elements contained in the specified collection.charremoveAt(int index) Removes and returns the item at the specified index.booleanRemoves from this CharList element-wise occurrences of elements contained in the specified collection.voidremoveRange(int start, int end) Removes the items between the specified start index, inclusive, and end index, exclusive.voidreplaceAll(com.github.tommyettinger.function.CharToCharFunction operator) Replaces each element of this list with the result of applying the given operator to that element.protected char[]resize(int newSize) booleanRemoves all items from this CharList that are not present somewhere inother, any number of times.voidreverse()Reverses the order of this Ordered in-place.rightString(int length) Creates a new String by copying the given subrange of this CharList, from indexsize() - length(inclusive) tosize()(exclusive).voidset(int index, char value) char[]setSize(int newSize) Sets the list size, leaving any values beyond the current size undefined.char[]shrink()Reduces the size of the backing array to the size of the actual items.voidPseudo-randomly shuffles the order of this Ordered in-place.intsize()Returns the number of elements in this Arrangeable.voidsort()Sorts this entire collection usingArrays.sort(char[], int, int)in ascending order.voidsort(int from, int to) UsesArrays.sort(char[], int, int)to sort a (clamped) subrange of this collection in ascending order.voidsort(int from, int to, CharComparator c) Sorts the specified range of elements according to the order induced by the specified comparator using mergesort, orArrays.sort(char[], int, int)ifcis null.voidSorts all elements according to the order induced by the specified comparator usingCharComparators.sort(char[], int, int, CharComparator).subSequence(int start, int end) Gets a new CharList from the given subrange, clamping start and end so they will not throw any Exception.substring(int start, int end) Creates a new String by copying the given subrange of this CharList.voidswap(int first, int second) Switches the ordering of positionsfirstandsecond, without changing any items beyond that.char[]toArray()Allocates a new char array withsizeelements and fills it with the items in this.char[]toArray(char[] array) Ifarray.lengthat least equal tosize(), this copies the contents of this intoarrayand returns it; otherwise, it allocates a new char array that can fit all the items in this, and proceeds to copy into that and return that.Simply returns all the char items in this as one String, with no delimiters.toString()voidvoidtruncate(int newSize) Reduces the size of the list to the specified size.static CharListwith()Constructs an empty list.static CharListwith(char item) Creates a new CharList that holds only the given item, but can be resized.static CharListwith(char... varargs) Creates a new CharList that holds only the given items, but can be resized.static CharListwith(char item0, char item1) Creates a new CharList that holds only the given items, but can be resized.static CharListwith(char item0, char item1, char item2) Creates a new CharList that holds only the given items, but can be resized.static CharListwith(char item0, char item1, char item2, char item3) Creates a new CharList that holds only the given items, but can be resized.static CharListwith(char item0, char item1, char item2, char item3, char item4) Creates a new CharList that holds only the given items, but can be resized.static CharListwith(char item0, char item1, char item2, char item3, char item4, char item5) Creates a new CharList that holds only the given items, but can be resized.static CharListwith(char item0, char item1, char item2, char item3, char item4, char item5, char item6) Creates a new CharList that holds only the given items, but can be resized.static CharListwith(char item0, char item1, char item2, char item3, char item4, char item5, char item6, char item7) Creates a new CharList 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 com.github.tommyettinger.ds.Arrangeable
rearrange, shuffleMethods inherited from interface java.lang.CharSequence
chars, codePointsMethods inherited from interface com.github.tommyettinger.ds.Ordered.OfChar
getOrderType, random, selectRanked, selectRankedIndexMethods inherited from interface com.github.tommyettinger.ds.PrimitiveCollection.OfChar
addAll, addAll, addDense, addDense, addLegible, addLegible, addVarargs, appendTo, appendTo, containsAll, containsAll, containsAll, containsAll, containsAny, containsAny, containsAny, containsAny, denseAppendTo, equalContents, forEach, removeAll, removeAll, removeAll, removeEach, removeEach, removeEach, removeIf, retainAll, retainAll, toDenseString, toString, toString, toString
-
Field Details
-
items
public char[] items -
size
protected int size -
iterator1
-
iterator2
-
-
Constructor Details
-
CharList
public CharList()Creates an ordered list with a capacity of 10. -
CharList
public CharList(int capacity) Creates an ordered list with the specified capacity.- Parameters:
capacity- Any elements added beyond this will cause the backing array to be grown.
-
CharList
Deprecated.CharList is always ordered; for an unordered list useCharBagCreates an ordered list with the specified capacity.- Parameters:
ordered- ignored; for an unordered list useCharBagcapacity- Any elements added beyond this will cause the backing array to be grown.
-
CharList
Creates a new list containing the elements in the given list. The new list will be ordered. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown.- Parameters:
list- another CharList (or CharBag) to copy from
-
CharList
public CharList(char[] array) Creates a new list containing the elements in the specified array. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown.- Parameters:
array- a char array to copy from
-
CharList
public CharList(char[] array, int startIndex, int count) Creates a new list containing the elements in the specified array. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown.- Parameters:
array- a non-null char array to add to this liststartIndex- the first index inarrayto usecount- how many items to use fromarray
-
CharList
Deprecated.CharList is always ordered; for an unordered list useCharBagCreates a new list containing the elements in the specified array. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown.- Parameters:
ordered- ignored; for an unordered list useCharBagarray- a non-null char array to add to this liststartIndex- the first index inarrayto usecount- how many items to use fromarray
-
CharList
Creates a new list containing the items in the specified PrimitiveCollection.OfChar.- Parameters:
coll- a primitive collection that will have its contents added to this
-
CharList
Creates a new instance containing the items in the specified iterator.- Parameters:
coll- an iterator that will have its remaining contents added to this
-
CharList
Copies the given Ordered.OfChar into a new CharList.- Parameters:
other- another Ordered.OfChar that will have its contents copied into this
-
CharList
Creates a new list by copyingcountitems from the given Ordered, starting atoffsetin that Ordered, into this.- Parameters:
other- another Ordered.OfCharoffset- the first index in other's ordering to draw an item fromcount- how many items to copy from other
-
CharList
-
CharList
Creates a new CharList from part of another CharSequence; start is inclusive and end is exclusive.- Parameters:
other- a CharSequence to use part of, such as a String or a CharListstart- first index inotherto use, inclusiveend- last index inotherto use, exclusive
-
-
Method Details
-
keepsOrder
public boolean keepsOrder()Returns true if this implementation retains order, which it does.- Returns:
- true
-
size
public int size()Description copied from interface:ArrangeableReturns the number of elements in this Arrangeable. Often this is shared withCollection.size(), but isn't always.- Specified by:
sizein interfaceArrangeable- Specified by:
sizein interfacePrimitiveCollection<Character>- Returns:
- the number of elements in this Arrangeable
-
add
public boolean add(char value) - Specified by:
addin interfacePrimitiveCollection.OfChar
-
add
public void add(char value1, char value2) -
add
public void add(char value1, char value2, char value3) -
add
public void add(char value1, char value2, char value3, char value4) -
addAll
-
addAll
-
addAll
Adds up tocountitems, starting fromoffset, in the Ordered.OfCharotherto this list, inserting at the end of the iteration order.- Parameters:
other- a non-nullOrdered.OfCharoffset- the first index inotherto usecount- how many indices inotherto use- Returns:
- true if this is modified by this call, as
addAll(CharList)does
-
addAll
Adds up tocountitems, starting fromoffset, in the Ordered.OfCharotherto this list, inserting starting atinsertionIndexin the iteration order.- Parameters:
insertionIndex- where to insert into the iteration orderother- a non-nullOrdered.OfCharoffset- the first index inotherto usecount- how many indices inotherto use- Returns:
- true if this is modified by this call, as
addAll(CharList)does
-
addAll
public boolean addAll(char... array) - Specified by:
addAllin interfacePrimitiveCollection.OfChar
-
addAll
public boolean addAll(char[] array, int offset, int length) - Specified by:
addAllin interfacePrimitiveCollection.OfChar
-
get
public char get(int index) -
set
public void set(int index, char value) -
insert
public void insert(int index, char value) -
duplicateRange
public boolean duplicateRange(int index, int count) Inserts the specified number of items at the specified index. The new items will have values equal to the values at those indices before the insertion, and the previous values will be pushed to after the duplicated range.- Parameters:
index- the first index to duplicatecount- how many items to duplicate
-
order
Returns this CharList, since it is its own order. This is only here to satisfy theOrdered.OfCharinterface.- Specified by:
orderin interfaceOrdered.OfChar- Returns:
- this CharList
-
swap
public void swap(int first, int second) Description copied from interface:Ordered.OfCharSwitches the ordering of positionsfirstandsecond, without changing any items beyond that.- Specified by:
swapin interfaceArrangeable- Specified by:
swapin interfaceOrdered.OfChar- 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()
-
contains
public boolean contains(char value) - Specified by:
containsin interfacePrimitiveCollection.OfChar
-
contains
Simply callsindexOf(CharSequence)and checks that it doesn't return-1.- Parameters:
csq- a CharSequence, such as a String or another CharList- Returns:
- true if this CharList contains the chars in
csqconsecutively and in order
-
containsIgnoreCase
Simply callsindexOfIgnoreCase(CharSequence)and checks that it doesn't return-1.- Parameters:
csq- a CharSequence, such as a String or another CharList- Returns:
- true if this CharList contains the chars in
csqconsecutively and in order, ignoring case
-
containsAll
Returns true if this CharList contains, at least once, every item inother; otherwise returns false.- Parameters:
other- an CharList- Returns:
- true if this contains every item in
other, otherwise false
-
indexOf
public int indexOf(char search) Returns the first index in this list that containssearch, or -1 if it is not present.- Parameters:
search- a char to search for- Returns:
- the first index of the given char, or -1 if it is not present
-
indexOf
public int indexOf(char search, int fromIndex) Tries to return the first indexsearchappears at in this list, starting atfromIndex; ifsearchis not present, this returns -1.- Parameters:
search- the char to search forfromIndex- the initial index in this list to start searching (inclusive)- Returns:
- the index
searchwas found at, or -1 if it was not found
-
indexOfIgnoreCase
public int indexOfIgnoreCase(char search) Returns the first index in this list that containssearch, or -1 if it is not present. This compares the given char as if both it and this CharSequence have had every character converted to upper case byCasing.caseUp(char).- Parameters:
search- a char to search for- Returns:
- the first index of the given char, or -1 if it is not present
-
indexOfIgnoreCase
public int indexOfIgnoreCase(char search, int fromIndex) Tries to return the first indexsearchappears at in this list, starting atfromIndex; ifsearchis not present, this returns -1. This compares the given char as if both it and this CharSequence have had every character converted to upper case byCasing.caseUp(char).- Parameters:
search- the char to search forfromIndex- the initial index in this list to start searching (inclusive)- Returns:
- the index
searchwas found at, or -1 if it was not found
-
indexOf
Tries to return the first indexsearchappears at in this list, starting at index 0; ifsearchis not present, this returns -1.- Parameters:
search- the CharSequence (such as a String or another CharList) to search for- Returns:
- the index
searchwas found at, or -1 if it was not found
-
indexOf
Tries to return the first indexsearchappears at in this list, starting atfromIndex; ifsearchis not present, this returns -1.
Mostly copied from libGDX, like the rest of this class, but from the latest version instead of a much-older version.- Parameters:
search- the CharSequence (such as a String or another CharList) to search forfromIndex- the initial index in this list to start searching (inclusive)- Returns:
- the index
searchwas found at, or -1 if it was not found
-
indexOfIgnoreCase
Tries to return the first indexsearchappears at in this list, starting at index 0; ifsearchis not present, this returns -1. This compares the given CharSequence as if both it and this CharSequence have had every character converted to upper case byCasing.caseUp(char).- Parameters:
search- the CharSequence (such as a String or another CharList) to search for- Returns:
- the index
searchwas found at, or -1 if it was not found
-
indexOfIgnoreCase
Tries to return the first indexsearchappears at in this list, starting atfromIndex; ifsearchis not present, this returns -1. This compares the given CharSequence as if both it and this CharSequence have had every character converted to upper case byCasing.caseUp(char).
Mostly copied from libGDX, like the rest of this class, but from the latest version instead of a much-older version.- Parameters:
search- the CharSequence (such as a String or another CharList) to search forfromIndex- the initial index in this list to start searching (inclusive)- Returns:
- the index
searchwas found at, or -1 if it was not found
-
lastIndexOf
public int lastIndexOf(char search) Returns the last index in this list that containssearch, or -1 if it is not present.- Parameters:
search- a char to search for- Returns:
- the last index of the given value, or -1 if it is not present
-
lastIndexOf
public int lastIndexOf(char search, int fromIndex) Returns the last index in this list that containssearch, starting the search atfromIndex(inclusive) and moving toward the start, or -1 if it is not present.- Parameters:
search- a char to search forfromIndex- the initial index to check (zero-indexed, starts at 0, inclusive)- Returns:
- the last index of the given value, or -1 if it is not present
-
lastIndexOf
Tries to return the first indexsearchappears at in this list, starting the search at the end and working toward the start; ifsearchis not present, this returns -1.- Parameters:
search- the CharSequence (such as a String or another CharList) to search for- Returns:
- the index
searchwas found at, or -1 if it was not found
-
lastIndexOf
Tries to return the first indexsearchappears at in this list, starting the search atfromIndexand working toward the start; ifsearchis not present, this returns -1.- Parameters:
search- the CharSequence (such as a String or another CharList) to search forfromIndex- the initial index in this list to start searching (zero-indexed, starts at 0, inclusive)- Returns:
- the index
searchwas found at, or -1 if it was not found
-
lastIndexOfIgnoreCase
public int lastIndexOfIgnoreCase(char search) Returns the last index in this list that containssearch, or -1 if it is not present. This compares the given char as if both it and this CharSequence have had every character converted to upper case byCasing.caseUp(char).- Parameters:
search- a char to search for- Returns:
- the last index of the given value, or -1 if it is not present
-
lastIndexOfIgnoreCase
public int lastIndexOfIgnoreCase(char search, int fromIndex) Returns the last index in this list that containssearch, starting the search atfromIndex(inclusive) and moving toward the start, or -1 if it is not present. This compares the given char as if both it and this CharSequence have had every character converted to upper case byCasing.caseUp(char).- Parameters:
search- a char to search forfromIndex- the initial index to check (zero-indexed, starts at 0, inclusive)- Returns:
- the last index of the given value, or -1 if it is not present
-
lastIndexOfIgnoreCase
Tries to return the first indexsearchappears at in this list, starting the search at the end and working toward the start; ifsearchis not present, this returns -1. This compares the given CharSequence as if both it and this CharSequence have had every character converted to upper case byCasing.caseUp(char).- Parameters:
search- the CharSequence (such as a String or another CharList) to search for- Returns:
- the index
searchwas found at, or -1 if it was not found
-
lastIndexOfIgnoreCase
Tries to return the first indexsearchappears at in this list, starting the search atfromIndexand working toward the start; ifsearchis not present, this returns -1. This compares the given CharSequence as if both it and this CharSequence have had every character converted to upper case byCasing.caseUp(char).- Parameters:
search- the CharSequence (such as a String or another CharList) to search forfromIndex- the initial index in this list to start searching (zero-indexed, starts at 0, inclusive)- Returns:
- the index
searchwas found at, or -1 if it was not found
-
remove
public boolean remove(char value) Removes the first occurrence ofvaluefrom this CharList, returning true if anything was removed. Otherwise, this returns false.- Specified by:
removein interfacePrimitiveCollection.OfChar- Parameters:
value- the value to (attempt to) remove- Returns:
- true if a value was removed, false if the CharList is unchanged
-
removeAt
public char removeAt(int index) Removes and returns the item at the specified index. Note that this is equivalent toList.remove(int), but can't have that name because we also haveremove(char)that removes a value, rather than an index.- Parameters:
index- the index of the item to remove and return- Returns:
- the removed item
-
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.OfChar- Parameters:
start- the first index to remove, inclusiveend- the last index (after what should be removed), exclusive
-
removeAll
Removes from this CharList all occurrences of any elements contained in the specified collection.- Specified by:
removeAllin interfacePrimitiveCollection.OfChar- Parameters:
c- a primitive collection of int items to remove fully, such as another CharList or a CharDeque- Returns:
- true if this list was modified.
-
removeEach
Removes from this CharList element-wise occurrences of elements contained in the specified collection. Note that if a value is present more than once in this CharList, only one of those occurrences will be removed for each occurrence of that value inc. Ifchas the same contents as this CharList or has additional items, then removing each ofcwill clear this.- Specified by:
removeEachin interfacePrimitiveCollection.OfChar- Parameters:
c- a primitive collection of int items to remove one-by-one, such as another CharList or a CharDeque- Returns:
- true if this list was modified.
-
retainAll
Removes all items from this CharList that are not present somewhere inother, any number of times.- Specified by:
retainAllin interfacePrimitiveCollection.OfChar- Parameters:
other- a PrimitiveCollection.OfChar that contains the items that this should keep, whenever present- Returns:
- true if this CharList changed as a result of this call, otherwise false
-
replaceAll
public void replaceAll(com.github.tommyettinger.function.CharToCharFunction operator) Replaces each element of this list with the result of applying the given operator to that element.- Parameters:
operator- a CharToCharFunction (a functional interface defined in funderby)
-
pop
public char pop()Removes and returns the last item.- Returns:
- the last item, removed from this
-
peek
public char peek()Returns the last item.- Returns:
- the last item, without modifying this
-
first
public char first()Returns the first item.- Specified by:
firstin interfacePrimitiveCollection.OfChar- Returns:
- the first item, without modifying this
-
notEmpty
public boolean notEmpty()Returns true if the list has one or more items, or false otherwise.- Specified by:
notEmptyin interfacePrimitiveCollection<Character>- Returns:
- true if the list has one or more items, or false otherwise
-
length
public int length()Description copied from interface:Ordered.OfCharCompatibility alias forArrangeable.size(). Here for compatibility with CharSequence.- Specified by:
lengthin interfaceCharSequence- Specified by:
lengthin interfaceOrdered.OfChar- Returns:
- how many items are contained in this data structure
-
charAt
public char charAt(int index) Description copied from interface:Ordered.OfCharEquivalent to callingget(int)onOrdered.OfChar.order(). Here for compatibility with CharSequence.- Specified by:
charAtin interfaceCharSequence- Specified by:
charAtin interfaceOrdered.OfChar- Parameters:
index- the index of thecharvalue to be returned- Returns:
- the char at the given index in the ordering
-
isEmpty
public boolean isEmpty()Returns true if the list is empty.- Specified by:
isEmptyin interfaceCharSequence- Specified by:
isEmptyin interfaceOrdered.OfChar- Specified by:
isEmptyin interfacePrimitiveCollection<Character>- Returns:
- true if the list is empty, or false if it has any items
-
subSequence
Gets a new CharList from the given subrange, clamping start and end so they will not throw any Exception.- Specified by:
subSequencein interfaceCharSequence- Specified by:
subSequencein interfaceOrdered.OfChar- Parameters:
start- the start index, inclusive; clampedend- the end index, exclusive; clamped- Returns:
- a new CharList copied from the given subrange bounds
-
substring
Creates a new String by copying the given subrange of this CharList. Clamps start and end so that this will never throw an Exception.- Parameters:
start- the start index, inclusiveend- the end index, exclusive- Returns:
- a new String copying the given subrange of this CharList
-
leftString
Creates a new String by copying the given subrange of this CharList, from index 0 (inclusive) tolength(exclusive).- Parameters:
length- how many chars to use from the start onward- Returns:
- a new String copying the given subrange of this CharList
-
rightString
Creates a new String by copying the given subrange of this CharList, from indexsize() - length(inclusive) tosize()(exclusive).- Parameters:
length- how many chars to use from the start onward- Returns:
- a new String copying the given subrange of this CharList
-
clear
public void clear()Effectively removes all items from this CharList. This is done simply by setting size to 0; because acharitem isn't a reference, it doesn't need to be set to null.- Specified by:
clearin interfacePrimitiveCollection<Character>
-
shrink
public char[] shrink()Reduces the size of the backing array to the size of the actual items. This is useful to release memory when many items have been removed, or if it is known that more items will not be added.- Returns:
items; this will be a different reference if this resized
-
trimToSize
public void trimToSize() -
ensureCapacity
public char[] ensureCapacity(int additionalCapacity) Increases the size of the backing array to accommodate the specified number of additional items. Useful before adding many items to avoid multiple backing array resizes.- Returns:
items; this will be a different reference if this resized
-
setSize
public char[] setSize(int newSize) Sets the list size, leaving any values beyond the current size undefined.- Returns:
items; this will be a different reference if this resized to a larger capacity
-
resize
protected char[] resize(int newSize) -
sort
public void sort()Sorts this entire collection usingArrays.sort(char[], int, int)in ascending order. -
sort
public void sort(int from, int to) UsesArrays.sort(char[], int, int)to sort a (clamped) subrange of this collection in ascending order.- Parameters:
from- the index of the first element (inclusive) to be sortedto- the index of the last element (exclusive) to be sorted
-
sort
Sorts all elements according to the order induced by the specified comparator usingCharComparators.sort(char[], int, int, CharComparator). Ifcis null, this instead delegates tosort(), which usesArrays.sort(char[]), and does not always run in-place.This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort. The sorting algorithm is an in-place mergesort that is significantly slower than a standard mergesort, as its running time is O(n (log n)2), but it does not allocate additional memory; as a result, it can be used as a generic sorting algorithm.
- Specified by:
sortin interfaceOrdered.OfChar- Parameters:
c- the comparator to determine the order of the CharList
-
sort
Sorts the specified range of elements according to the order induced by the specified comparator using mergesort, orArrays.sort(char[], int, int)ifcis null. This purely usesCharComparators.sort(char[], int, int, CharComparator), and you can see its docs for more information. This clampsfromandtoto the valid range.- Parameters:
from- the index of the first element (inclusive) to be sortedto- the index of the last element (exclusive) to be sortedc- the comparator to determine the order of the CharList
-
reverse
public void reverse()Description copied from interface:Ordered.OfCharReverses the order of this Ordered in-place.- Specified by:
reversein interfaceArrangeable- Specified by:
reversein interfaceOrdered.OfChar
-
shuffle
Description copied from interface:Ordered.OfCharPseudo-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- Specified by:
shufflein interfaceOrdered.OfChar- Parameters:
random- anyRandomclass, such as one from juniper
-
truncate
public void truncate(int newSize) Reduces the size of the list to the specified size. If the list is already smaller than the specified size, no action is taken. -
random
Returns a random item from the list, or zero if the list is empty, using the given random number generator.- Specified by:
randomin interfaceOrdered.OfChar- Parameters:
random- aRandomor a subclass, such as any from juniper- Returns:
- a randomly selected item from this, or
0if this is empty
-
toArray
public char[] toArray()Allocates a new char array withsizeelements and fills it with the items in this.- Specified by:
toArrayin interfacePrimitiveCollection.OfChar- Returns:
- a new char array with the same contents as this
-
toArray
public char[] toArray(char[] array) Ifarray.lengthat least equal tosize(), this copies the contents of this intoarrayand returns it; otherwise, it allocates a new char array that can fit all the items in this, and proceeds to copy into that and return that.- Specified by:
toArrayin interfacePrimitiveCollection.OfChar- Parameters:
array- a char array that will be modified if it can fitsize()items- Returns:
array, if it had sufficient size, or a new array otherwise, either with a copy of this
-
hashCode
public int hashCode()- Specified by:
hashCodein interfacePrimitiveCollection<Character>- Overrides:
hashCodein classObject
-
equals
- Specified by:
equalsin interfacePrimitiveCollection<Character>- Overrides:
equalsin classObject
-
equalsIgnoreCase
Checks if this is equal to another CharSequence, but runs all chars in both the given text and this throughCasing.caseUp(char)before comparing (making the comparison case-insensitive for almost all scripts in use today, except some situations for Georgian).- Parameters:
csq- any other CharSequence, such as a String, StringBuilder, or CharList- Returns:
- true if the chars in this are equivalent to those in
csqif compared as case-insensitive
-
toString
- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-
toDenseString
Simply returns all the char items in this as one String, with no delimiters. This is the same as callingString.valueOf(charList.items, 0, charList.size()).- Specified by:
toDenseStringin interfacePrimitiveCollection.OfChar- Returns:
- a String containing only the char items in this CharList
-
iterator
Returns a Java 8 primitive iterator over the int items in this CharList. Iterates in order ifkeepsOrder()returns true, which it does for a CharList but not a CharBag.
This will reuse one of two iterators in this CharList; this does not allow nested iteration. UseCharListIterator(CharList)to nest iterators.- Specified by:
iteratorin interfacePrimitiveCollection<Character>- Specified by:
iteratorin interfacePrimitiveCollection.OfChar- Returns:
- a
CharIterator; use its nextChar() method instead of next()
-
append
- Specified by:
appendin interfaceAppendable
-
append
- Specified by:
appendin interfaceAppendable
-
append
- Specified by:
appendin interfaceAppendable
-
appendLine
Appends a literal newline (Unicode character u000A).- Returns:
- this, for chaining.
-
line
Appends a literal newline (Unicode character u000A). This is identical toappendLine()but is faster to type or recommend.- Returns:
- this, for chaining.
-
append
Appends the base-10 signed textual form of the given number, without allocating. This usesBase.appendSigned(CharSequence, int).- Parameters:
number- the int to append- Returns:
- this, for chaining
-
append
Appends the base-10 signed textual form of the given number, without allocating. This usesBase.appendSigned(CharSequence, long). This does not append a trailing'L'.- Parameters:
number- the long to append- Returns:
- this, for chaining
-
append
Appends the base-10 decimal or engineering textual form of the given number, without allocating. This usesBase.appendGeneral(CharSequence, float). This does not append a trailing'f'.- Parameters:
number- the float to append- Returns:
- this, for chaining
-
append
Appends the base-10 decimal or engineering textual form of the given number, without allocating. This usesBase.appendGeneral(CharSequence, double).- Parameters:
number- the double to append- Returns:
- this, for chaining
-
append
Appends either the four chars't', 'r', 'u', 'e'ifvalueis true, or the five chars'f', 'a', 'l', 's', 'e'if it is false.- Parameters:
value- either true or false- Returns:
- this, for chaining
-
padLeft
Addscountrepetitions ofpadWithto the start (left) of this list.- Parameters:
count- how many repetitions ofpadWithto addpadWith- the item to pad with- Returns:
- this, for chaining
-
padRight
Addscountrepetitions ofpadWithto the end (right) of this list.- Parameters:
count- how many repetitions ofpadWithto addpadWith- the item to pad with- Returns:
- this, for chaining
-
compareTo
- Specified by:
compareToin interfaceComparable<CharList>
-
compareWith
Compares this CharList with an arbitrary CharSequence type, returning the lexicographical comparison of the two as if Java 11'sCharSequence.compare()was called on this andother. This does not need Java 11.
The name here is different fromcompareTo(CharList)because this does not satisfy an important constraint of theComparableinterface (while this has a compareWith method that can take a CharSequence, an arbitrary CharSequence cannot be compared to this type with compareTo() or compareWith() ).- Parameters:
other- any other CharSequence; if null, the comparison will returnInteger.MAX_VALUE- Returns:
- a positive number, zero, or a negative number if this is lexicographically greater than, equal to, or less than other, respectively
-
compareWithIgnoreCase
Compares this CharList with an arbitrary CharSequence type, returning the lexicographical comparison of the two as if Java 11'sCharSequence.compare()was called on this if it had been entirely raised to upper case andotherif it also had been entirely raised to upper case. This does not need Java 11. This usesCasing.caseUp(char)to perform its case conversion, which works for all alphabets that have case except for the Georgian alphabet.
The name here is different fromcompareTo(CharList)because this does not satisfy an important constraint of theComparableinterface (while this has a compareWith method that can take a CharSequence, an arbitrary CharSequence cannot be compared to this type with compareTo() or compareWith() ).- Parameters:
other- any other CharSequence; if null, the comparison will returnInteger.MAX_VALUE- Returns:
- a positive number, zero, or a negative number if this is lexicographically greater than, equal to, or less than other, respectively, using case-insensitive comparison
-
with
Constructs an empty list. This is usually less useful than just using the constructor, but can be handy in some code-generation scenarios when you don't know how many arguments you will have.- Returns:
- a new list containing nothing
-
with
Creates a new CharList that holds only the given item, but can be resized.- Parameters:
item- a char item- Returns:
- a new CharList that holds the given item
-
with
Creates a new CharList that holds only the given items, but can be resized.- Parameters:
item0- a char itemitem1- a char item- Returns:
- a new CharList that holds the given items
-
with
Creates a new CharList that holds only the given items, but can be resized.- Parameters:
item0- a char itemitem1- a char itemitem2- a char item- Returns:
- a new CharList that holds the given items
-
with
Creates a new CharList that holds only the given items, but can be resized.- Parameters:
item0- a char itemitem1- a char itemitem2- a char itemitem3- a char item- Returns:
- a new CharList that holds the given items
-
with
Creates a new CharList that holds only the given items, but can be resized.- Parameters:
item0- a char itemitem1- a char itemitem2- a char itemitem3- a char itemitem4- a char item- Returns:
- a new CharList that holds the given items
-
with
Creates a new CharList that holds only the given items, but can be resized.- Parameters:
item0- a char itemitem1- a char itemitem2- a char itemitem3- a char itemitem4- a char itemitem5- a char item- Returns:
- a new CharList that holds the given items
-
with
public static CharList with(char item0, char item1, char item2, char item3, char item4, char item5, char item6) Creates a new CharList that holds only the given items, but can be resized.- Parameters:
item0- a char itemitem1- a char itemitem2- a char itemitem3- a char itemitem4- a char itemitem5- a char itemitem6- a char item- Returns:
- a new CharList that holds the given items
-
with
public static CharList with(char item0, char item1, char item2, char item3, char item4, char item5, char item6, char item7) Creates a new CharList that holds only the given items, but can be resized.- Parameters:
item0- a char itemitem1- a char itemitem2- a char itemitem3- a char itemitem4- a char itemitem5- a char itemitem6- a char item- Returns:
- a new CharList that holds the given items
-
with
Creates a new CharList 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.- Parameters:
varargs- a char varargs or char array; remember that varargs allocate- Returns:
- a new CharList that holds the given items
-
parse
Callsparse(String, String, boolean)with brackets set to false.- Parameters:
str- a String that will be parsed in fulldelimiter- the delimiter between items in str- Returns:
- a new collection parsed from str
-
parse
Creates a new collection and fills it by callingPrimitiveCollection.OfChar.addLegible(String, String, int, int)on either all ofstr(ifbracketsis false) orstrwithout its first and last chars (ifbracketsis true). Each item is expected to be separated bydelimiter.- Parameters:
str- a String that will be parsed in full (depending on brackets)delimiter- the delimiter between items in strbrackets- if true, the first and last chars in str will be ignored- Returns:
- a new collection parsed from str
-
parse
Creates a new collection and fills it by callingPrimitiveCollection.OfChar.addLegible(String, String, int, int)with the given four parameters as-is.- Parameters:
str- a String that will have the given section parseddelimiter- the delimiter between items in stroffset- the first position to parse in str, inclusivelength- how many chars to parse, starting from offset- Returns:
- a new collection parsed from str
-
CharBag