Class CharList

java.lang.Object
com.github.tommyettinger.ds.CharList
All Implemented Interfaces:
Arrangeable, Ordered.OfChar, PrimitiveCollection<Character>, PrimitiveCollection.OfChar, Appendable, CharSequence, Comparable<CharList>
Direct Known Subclasses:
CharBag, CharDeque

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().
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    A CharIterator, plus ListIterator methods, over the elements of a CharList.

    Nested classes/interfaces inherited from interface com.github.tommyettinger.ds.Arrangeable

    Arrangeable.ArrangeableList<T>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    char[]
     
     
     
    protected int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an ordered list with a capacity of 10.
    CharList(boolean ordered, char[] array, int startIndex, int count)
    Deprecated.
    CharList is always ordered; for an unordered list use CharBag
    CharList(boolean ordered, int capacity)
    Deprecated.
    CharList is always ordered; for an unordered list use CharBag
    CharList(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.
    Copies the given Ordered.OfChar into a new CharList.
    CharList(Ordered.OfChar other, int offset, int count)
    Creates a new list by copying count items from the given Ordered, starting at offset in that Ordered, into this.
    Creates a new list containing the items in the specified PrimitiveCollection.OfChar.
    Creates a new instance containing the items in the specified iterator.
     
    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 Type
    Method
    Description
    boolean
    add(char value)
     
    void
    add(char value1, char value2)
     
    void
    add(char value1, char value2, char value3)
     
    void
    add(char value1, char value2, char value3, char value4)
     
    boolean
    addAll(char... array)
     
    boolean
    addAll(char[] array, int offset, int length)
     
    boolean
    addAll(int insertionIndex, Ordered.OfChar other, int offset, int count)
    Adds up to count items, starting from offset, in the Ordered.OfChar other to this list, inserting starting at insertionIndex in the iteration order.
    boolean
     
    boolean
    addAll(CharList list, int offset, int count)
     
    boolean
    addAll(Ordered.OfChar other, int offset, int count)
    Adds up to count items, starting from offset, in the Ordered.OfChar other to this list, inserting at the end of the iteration order.
    append(boolean value)
    Appends either the four chars 't', 'r', 'u', 'e' if value is 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, int start, int end)
     
    Appends a literal newline (Unicode character u000A).
    char
    charAt(int index)
    Equivalent to calling get(int) on Ordered.OfChar.order().
    void
    Effectively removes all items from this CharList.
    int
     
    int
    Compares this CharList with an arbitrary CharSequence type, returning the lexicographical comparison of the two as if Java 11's CharSequence.compare() was called on this and other.
    int
    Compares this CharList with an arbitrary CharSequence type, returning the lexicographical comparison of the two as if Java 11's CharSequence.compare() was called on this if it had been entirely raised to upper case and other if it also had been entirely raised to upper case.
    boolean
    contains(char value)
     
    boolean
    Simply calls indexOf(CharSequence) and checks that it doesn't return -1.
    boolean
    Returns true if this CharList contains, at least once, every item in other; otherwise returns false.
    boolean
    Simply calls indexOfIgnoreCase(CharSequence) and checks that it doesn't return -1.
    boolean
    duplicateRange(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.
    boolean
    equals(Object object)
     
    boolean
    Checks if this is equal to another CharSequence, but runs all chars in both the given text and this through Casing.caseUp(char) before comparing (making the comparison case-insensitive for almost all scripts in use today, except some situations for Georgian).
    char
    Returns the first item.
    char
    get(int index)
     
    int
     
    int
    indexOf(char search)
    Returns the first index in this list that contains search, or -1 if it is not present.
    int
    indexOf(char search, int fromIndex)
    Tries to return the first index search appears at in this list, starting at fromIndex; if search is not present, this returns -1.
    int
    Tries to return the first index search appears at in this list, starting at index 0; if search is not present, this returns -1.
    int
    indexOf(CharSequence search, int fromIndex)
    Tries to return the first index search appears at in this list, starting at fromIndex; if search is not present, this returns -1.
    int
    indexOfIgnoreCase(char search)
    Returns the first index in this list that contains search, or -1 if it is not present.
    int
    indexOfIgnoreCase(char search, int fromIndex)
    Tries to return the first index search appears at in this list, starting at fromIndex; if search is not present, this returns -1.
    int
    Tries to return the first index search appears at in this list, starting at index 0; if search is not present, this returns -1.
    int
    indexOfIgnoreCase(CharSequence search, int fromIndex)
    Tries to return the first index search appears at in this list, starting at fromIndex; if search is not present, this returns -1.
    void
    insert(int index, char value)
     
    boolean
    Returns true if the list is empty.
    Returns a Java 8 primitive iterator over the int items in this CharList.
    boolean
    Returns true if this implementation retains order, which it does.
    int
    lastIndexOf(char search)
    Returns the last index in this list that contains search, or -1 if it is not present.
    int
    lastIndexOf(char search, int fromIndex)
    Returns the last index in this list that contains search, starting the search at fromIndex (inclusive) and moving toward the start, or -1 if it is not present.
    int
    Tries to return the first index search appears at in this list, starting the search at the end and working toward the start; if search is not present, this returns -1.
    int
    lastIndexOf(CharSequence search, int fromIndex)
    Tries to return the first index search appears at in this list, starting the search at fromIndex and working toward the start; if search is not present, this returns -1.
    int
    lastIndexOfIgnoreCase(char search)
    Returns the last index in this list that contains search, or -1 if it is not present.
    int
    lastIndexOfIgnoreCase(char search, int fromIndex)
    Returns the last index in this list that contains search, starting the search at fromIndex (inclusive) and moving toward the start, or -1 if it is not present.
    int
    Tries to return the first index search appears at in this list, starting the search at the end and working toward the start; if search is not present, this returns -1.
    int
    lastIndexOfIgnoreCase(CharSequence search, int fromIndex)
    Tries to return the first index search appears at in this list, starting the search at fromIndex and working toward the start; if search is not present, this returns -1.
    leftString(int length)
    Creates a new String by copying the given subrange of this CharList, from index 0 (inclusive) to length (exclusive).
    int
    Compatibility alias for Arrangeable.size().
    Appends a literal newline (Unicode character u000A).
    boolean
    Returns true if the list has one or more items, or false otherwise.
    Returns this CharList, since it is its own order.
    padLeft(int count, char padWith)
    Adds count repetitions of padWith to the start (left) of this list.
    padRight(int count, char padWith)
    Adds count repetitions of padWith to the end (right) of this list.
    static CharList
    parse(String str, String delimiter)
    Calls parse(String, String, boolean) with brackets set to false.
    static CharList
    parse(String str, String delimiter, boolean brackets)
    Creates a new collection and fills it by calling PrimitiveCollection.OfChar.addLegible(String, String, int, int) on either all of str (if brackets is false) or str without its first and last chars (if brackets is true).
    static CharList
    parse(String str, String delimiter, int offset, int length)
    Creates a new collection and fills it by calling PrimitiveCollection.OfChar.addLegible(String, String, int, int) with the given four parameters as-is.
    char
    Returns the last item.
    char
    pop()
    Removes and returns the last item.
    char
    random(Random random)
    Returns a random item from the list, or zero if the list is empty, using the given random number generator.
    boolean
    remove(char value)
    Removes the first occurrence of value from this CharList, returning true if anything was removed.
    boolean
    Removes from this CharList all occurrences of any elements contained in the specified collection.
    char
    removeAt(int index)
    Removes and returns the item at the specified index.
    boolean
    Removes from this CharList element-wise occurrences of elements contained in the specified collection.
    void
    removeRange(int start, int end)
    Removes the items between the specified start index, inclusive, and end index, exclusive.
    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.
    protected char[]
    resize(int newSize)
     
    boolean
    Removes all items from this CharList that are not present somewhere in other, any number of times.
    void
    Reverses the order of this Ordered in-place.
    rightString(int length)
    Creates a new String by copying the given subrange of this CharList, from index size() - length (inclusive) to size() (exclusive).
    void
    set(int index, char value)
     
    char[]
    setSize(int newSize)
    Sets the list size, leaving any values beyond the current size undefined.
    char[]
    Reduces the size of the backing array to the size of the actual items.
    void
    shuffle(Random random)
    Pseudo-randomly shuffles the order of this Ordered in-place.
    int
    Returns the number of elements in this Arrangeable.
    void
    Sorts this entire collection using Arrays.sort(char[], int, int) in ascending order.
    void
    sort(int from, int to)
    Uses Arrays.sort(char[], int, int) to sort a (clamped) subrange of this collection in ascending order.
    void
    sort(int from, int to, CharComparator c)
    Sorts the specified range of elements according to the order induced by the specified comparator using mergesort, or Arrays.sort(char[], int, int) if c is null.
    void
    Sorts all elements according to the order induced by the specified comparator using CharComparators.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.
    void
    swap(int first, int second)
    Switches the ordering of positions first and second, without changing any items beyond that.
    char[]
    Allocates a new char array with size elements and fills it with the items in this.
    char[]
    toArray(char[] array)
    If array.length at least equal to size(), this copies the contents of this into array and 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.
     
    void
     
    void
    truncate(int newSize)
    Reduces the size of the list to the specified size.
    static CharList
    Constructs an empty list.
    static CharList
    with(char item)
    Creates a new CharList that holds only the given item, but can be resized.
    static CharList
    with(char... varargs)
    Creates a new CharList that holds only the given items, but can be resized.
    static CharList
    with(char item0, char item1)
    Creates a new CharList that holds only the given items, but can be resized.
    static CharList
    with(char item0, char item1, char item2)
    Creates a new CharList that holds only the given items, but can be resized.
    static CharList
    with(char item0, char item1, char item2, char item3)
    Creates a new CharList that holds only the given items, but can be resized.
    static CharList
    with(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 CharList
    with(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 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.
    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.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface com.github.tommyettinger.ds.Arrangeable

    rearrange, shuffle

    Methods inherited from interface java.lang.CharSequence

    chars, codePoints

    Methods inherited from interface com.github.tommyettinger.ds.Ordered.OfChar

    getOrderType, random, selectRanked, selectRankedIndex
  • Field Details

  • 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 public CharList(boolean ordered, int capacity)
      Deprecated.
      CharList is always ordered; for an unordered list use CharBag
      Creates an ordered list with the specified capacity.
      Parameters:
      ordered - ignored; for an unordered list use CharBag
      capacity - Any elements added beyond this will cause the backing array to be grown.
    • CharList

      public CharList(CharList list)
      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 list
      startIndex - the first index in array to use
      count - how many items to use from array
    • CharList

      @Deprecated public CharList(boolean ordered, char[] array, int startIndex, int count)
      Deprecated.
      CharList is always ordered; for an unordered list use CharBag
      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:
      ordered - ignored; for an unordered list use CharBag
      array - a non-null char array to add to this list
      startIndex - the first index in array to use
      count - how many items to use from array
    • CharList

      public CharList(PrimitiveCollection.OfChar coll)
      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

      public CharList(CharIterator 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
    • CharList

      public CharList(Ordered.OfChar other)
      Copies the given Ordered.OfChar into a new CharList.
      Parameters:
      other - another Ordered.OfChar that will have its contents copied into this
    • CharList

      public CharList(Ordered.OfChar other, int offset, int count)
      Creates a new list by copying count items from the given Ordered, starting at offset in that Ordered, into this.
      Parameters:
      other - another Ordered.OfChar
      offset - the first index in other's ordering to draw an item from
      count - how many items to copy from other
    • CharList

      public CharList(CharSequence other)
    • CharList

      public CharList(CharSequence other, int start, int end)
      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 CharList
      start - first index in other to use, inclusive
      end - last index in other to 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: Arrangeable
      Returns the number of elements in this Arrangeable. Often this is shared with Collection.size(), but isn't always.
      Specified by:
      size in interface Arrangeable
      Specified by:
      size in interface PrimitiveCollection<Character>
      Returns:
      the number of elements in this Arrangeable
    • add

      public boolean add(char value)
      Specified by:
      add in interface PrimitiveCollection.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

      public boolean addAll(CharList list)
    • addAll

      public boolean addAll(CharList list, int offset, int count)
    • addAll

      public boolean addAll(Ordered.OfChar other, int offset, int count)
      Adds up to count items, starting from offset, in the Ordered.OfChar other to this list, inserting at the end of the iteration order.
      Parameters:
      other - a non-null Ordered.OfChar
      offset - the first index in other to use
      count - how many indices in other to use
      Returns:
      true if this is modified by this call, as addAll(CharList) does
    • addAll

      public boolean addAll(int insertionIndex, Ordered.OfChar other, int offset, int count)
      Adds up to count items, starting from offset, in the Ordered.OfChar other to this list, inserting starting at insertionIndex in the iteration order.
      Parameters:
      insertionIndex - where to insert into the iteration order
      other - a non-null Ordered.OfChar
      offset - the first index in other to use
      count - how many indices in other to use
      Returns:
      true if this is modified by this call, as addAll(CharList) does
    • addAll

      public boolean addAll(char... array)
      Specified by:
      addAll in interface PrimitiveCollection.OfChar
    • addAll

      public boolean addAll(char[] array, int offset, int length)
      Specified by:
      addAll in interface PrimitiveCollection.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 duplicate
      count - how many items to duplicate
    • order

      public CharList order()
      Returns this CharList, since it is its own order. This is only here to satisfy the Ordered.OfChar interface.
      Specified by:
      order in interface Ordered.OfChar
      Returns:
      this CharList
    • swap

      public void swap(int first, int second)
      Description copied from interface: Ordered.OfChar
      Switches the ordering of positions first and second, without changing any items beyond that.
      Specified by:
      swap in interface Arrangeable
      Specified by:
      swap in interface Ordered.OfChar
      Parameters:
      first - the first position, must not be negative and must be less than Arrangeable.size()
      second - the second position, must not be negative and must be less than Arrangeable.size()
    • contains

      public boolean contains(char value)
      Specified by:
      contains in interface PrimitiveCollection.OfChar
    • contains

      public boolean contains(CharSequence csq)
      Simply calls indexOf(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 csq consecutively and in order
    • containsIgnoreCase

      public boolean containsIgnoreCase(CharSequence csq)
      Simply calls indexOfIgnoreCase(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 csq consecutively and in order, ignoring case
    • containsAll

      public boolean containsAll(CharList other)
      Returns true if this CharList contains, at least once, every item in other; 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 contains search, 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 index search appears at in this list, starting at fromIndex; if search is not present, this returns -1.
      Parameters:
      search - the char to search for
      fromIndex - the initial index in this list to start searching (inclusive)
      Returns:
      the index search was found at, or -1 if it was not found
    • indexOfIgnoreCase

      public int indexOfIgnoreCase(char search)
      Returns the first index in this list that contains search, 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 by Casing.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 index search appears at in this list, starting at fromIndex; if search is 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 by Casing.caseUp(char).
      Parameters:
      search - the char to search for
      fromIndex - the initial index in this list to start searching (inclusive)
      Returns:
      the index search was found at, or -1 if it was not found
    • indexOf

      public int indexOf(CharSequence search)
      Tries to return the first index search appears at in this list, starting at index 0; if search is not present, this returns -1.
      Parameters:
      search - the CharSequence (such as a String or another CharList) to search for
      Returns:
      the index search was found at, or -1 if it was not found
    • indexOf

      public int indexOf(CharSequence search, int fromIndex)
      Tries to return the first index search appears at in this list, starting at fromIndex; if search is 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 for
      fromIndex - the initial index in this list to start searching (inclusive)
      Returns:
      the index search was found at, or -1 if it was not found
    • indexOfIgnoreCase

      public int indexOfIgnoreCase(CharSequence search)
      Tries to return the first index search appears at in this list, starting at index 0; if search is 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 by Casing.caseUp(char).
      Parameters:
      search - the CharSequence (such as a String or another CharList) to search for
      Returns:
      the index search was found at, or -1 if it was not found
    • indexOfIgnoreCase

      public int indexOfIgnoreCase(CharSequence search, int fromIndex)
      Tries to return the first index search appears at in this list, starting at fromIndex; if search is 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 by Casing.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 for
      fromIndex - the initial index in this list to start searching (inclusive)
      Returns:
      the index search was found at, or -1 if it was not found
    • lastIndexOf

      public int lastIndexOf(char search)
      Returns the last index in this list that contains search, 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 contains search, starting the search at fromIndex (inclusive) and moving toward the start, or -1 if it is not present.
      Parameters:
      search - a char to search for
      fromIndex - 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

      public int lastIndexOf(CharSequence search)
      Tries to return the first index search appears at in this list, starting the search at the end and working toward the start; if search is not present, this returns -1.
      Parameters:
      search - the CharSequence (such as a String or another CharList) to search for
      Returns:
      the index search was found at, or -1 if it was not found
    • lastIndexOf

      public int lastIndexOf(CharSequence search, int fromIndex)
      Tries to return the first index search appears at in this list, starting the search at fromIndex and working toward the start; if search is not present, this returns -1.
      Parameters:
      search - the CharSequence (such as a String or another CharList) to search for
      fromIndex - the initial index in this list to start searching (zero-indexed, starts at 0, inclusive)
      Returns:
      the index search was found at, or -1 if it was not found
    • lastIndexOfIgnoreCase

      public int lastIndexOfIgnoreCase(char search)
      Returns the last index in this list that contains search, 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 by Casing.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 contains search, starting the search at fromIndex (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 by Casing.caseUp(char).
      Parameters:
      search - a char to search for
      fromIndex - 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

      public int lastIndexOfIgnoreCase(CharSequence search)
      Tries to return the first index search appears at in this list, starting the search at the end and working toward the start; if search is 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 by Casing.caseUp(char).
      Parameters:
      search - the CharSequence (such as a String or another CharList) to search for
      Returns:
      the index search was found at, or -1 if it was not found
    • lastIndexOfIgnoreCase

      public int lastIndexOfIgnoreCase(CharSequence search, int fromIndex)
      Tries to return the first index search appears at in this list, starting the search at fromIndex and working toward the start; if search is 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 by Casing.caseUp(char).
      Parameters:
      search - the CharSequence (such as a String or another CharList) to search for
      fromIndex - the initial index in this list to start searching (zero-indexed, starts at 0, inclusive)
      Returns:
      the index search was found at, or -1 if it was not found
    • remove

      public boolean remove(char value)
      Removes the first occurrence of value from this CharList, returning true if anything was removed. Otherwise, this returns false.
      Specified by:
      remove in interface PrimitiveCollection.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 to List.remove(int), but can't have that name because we also have remove(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:
      removeRange in interface Ordered.OfChar
      Parameters:
      start - the first index to remove, inclusive
      end - the last index (after what should be removed), exclusive
    • removeAll

      public boolean removeAll(PrimitiveCollection.OfChar c)
      Removes from this CharList all occurrences of any elements contained in the specified collection.
      Specified by:
      removeAll in interface PrimitiveCollection.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

      public boolean removeEach(PrimitiveCollection.OfChar c)
      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 in c. If c has the same contents as this CharList or has additional items, then removing each of c will clear this.
      Specified by:
      removeEach in interface PrimitiveCollection.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

      public boolean retainAll(PrimitiveCollection.OfChar other)
      Removes all items from this CharList that are not present somewhere in other, any number of times.
      Specified by:
      retainAll in interface PrimitiveCollection.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:
      first in interface PrimitiveCollection.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:
      notEmpty in interface PrimitiveCollection<Character>
      Returns:
      true if the list has one or more items, or false otherwise
    • length

      public int length()
      Description copied from interface: Ordered.OfChar
      Compatibility alias for Arrangeable.size(). Here for compatibility with CharSequence.
      Specified by:
      length in interface CharSequence
      Specified by:
      length in interface Ordered.OfChar
      Returns:
      how many items are contained in this data structure
    • charAt

      public char charAt(int index)
      Description copied from interface: Ordered.OfChar
      Equivalent to calling get(int) on Ordered.OfChar.order(). Here for compatibility with CharSequence.
      Specified by:
      charAt in interface CharSequence
      Specified by:
      charAt in interface Ordered.OfChar
      Parameters:
      index - the index of the char value 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:
      isEmpty in interface CharSequence
      Specified by:
      isEmpty in interface Ordered.OfChar
      Specified by:
      isEmpty in interface PrimitiveCollection<Character>
      Returns:
      true if the list is empty, or false if it has any items
    • subSequence

      public CharList subSequence(int start, int end)
      Gets a new CharList from the given subrange, clamping start and end so they will not throw any Exception.
      Specified by:
      subSequence in interface CharSequence
      Specified by:
      subSequence in interface Ordered.OfChar
      Parameters:
      start - the start index, inclusive; clamped
      end - the end index, exclusive; clamped
      Returns:
      a new CharList copied from the given subrange bounds
    • substring

      public String substring(int start, int end)
      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, inclusive
      end - the end index, exclusive
      Returns:
      a new String copying the given subrange of this CharList
    • leftString

      public String leftString(int length)
      Creates a new String by copying the given subrange of this CharList, from index 0 (inclusive) to length (exclusive).
      Parameters:
      length - how many chars to use from the start onward
      Returns:
      a new String copying the given subrange of this CharList
    • rightString

      public String rightString(int length)
      Creates a new String by copying the given subrange of this CharList, from index size() - length (inclusive) to size() (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 a char item isn't a reference, it doesn't need to be set to null.
      Specified by:
      clear in interface PrimitiveCollection<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 using Arrays.sort(char[], int, int) in ascending order.
    • sort

      public void sort(int from, int to)
      Uses Arrays.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 sorted
      to - the index of the last element (exclusive) to be sorted
    • sort

      public void sort(CharComparator c)
      Sorts all elements according to the order induced by the specified comparator using CharComparators.sort(char[], int, int, CharComparator). If c is null, this instead delegates to sort(), which uses Arrays.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:
      sort in interface Ordered.OfChar
      Parameters:
      c - the comparator to determine the order of the CharList
    • sort

      public void sort(int from, int to, CharComparator c)
      Sorts the specified range of elements according to the order induced by the specified comparator using mergesort, or Arrays.sort(char[], int, int) if c is null. This purely uses CharComparators.sort(char[], int, int, CharComparator), and you can see its docs for more information. This clamps from and to to the valid range.
      Parameters:
      from - the index of the first element (inclusive) to be sorted
      to - the index of the last element (exclusive) to be sorted
      c - the comparator to determine the order of the CharList
    • reverse

      public void reverse()
      Description copied from interface: Ordered.OfChar
      Reverses the order of this Ordered in-place.
      Specified by:
      reverse in interface Arrangeable
      Specified by:
      reverse in interface Ordered.OfChar
    • shuffle

      public void shuffle(Random random)
      Description copied from interface: Ordered.OfChar
      Pseudo-randomly shuffles the order of this Ordered in-place. You can seed rng, the random number generator, with an identical seed to reproduce a shuffle on two Ordered with the same Arrangeable.size().
      Specified by:
      shuffle in interface Arrangeable
      Specified by:
      shuffle in interface Ordered.OfChar
      Parameters:
      random - any Random class, 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

      public char random(Random random)
      Returns a random item from the list, or zero if the list is empty, using the given random number generator.
      Specified by:
      random in interface Ordered.OfChar
      Parameters:
      random - a Random or a subclass, such as any from juniper
      Returns:
      a randomly selected item from this, or 0 if this is empty
    • toArray

      public char[] toArray()
      Allocates a new char array with size elements and fills it with the items in this.
      Specified by:
      toArray in interface PrimitiveCollection.OfChar
      Returns:
      a new char array with the same contents as this
    • toArray

      public char[] toArray(char[] array)
      If array.length at least equal to size(), this copies the contents of this into array and 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:
      toArray in interface PrimitiveCollection.OfChar
      Parameters:
      array - a char array that will be modified if it can fit size() 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:
      hashCode in interface PrimitiveCollection<Character>
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object object)
      Specified by:
      equals in interface PrimitiveCollection<Character>
      Overrides:
      equals in class Object
    • equalsIgnoreCase

      public boolean equalsIgnoreCase(CharSequence csq)
      Checks if this is equal to another CharSequence, but runs all chars in both the given text and this through Casing.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 csq if compared as case-insensitive
    • toString

      public String toString()
      Specified by:
      toString in interface CharSequence
      Overrides:
      toString in class Object
    • toDenseString

      public String toDenseString()
      Simply returns all the char items in this as one String, with no delimiters. This is the same as calling String.valueOf(charList.items, 0, charList.size()) .
      Specified by:
      toDenseString in interface PrimitiveCollection.OfChar
      Returns:
      a String containing only the char items in this CharList
    • iterator

      public CharList.CharListIterator iterator()
      Returns a Java 8 primitive iterator over the int items in this CharList. Iterates in order if keepsOrder() 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. Use CharListIterator(CharList) to nest iterators.
      Specified by:
      iterator in interface PrimitiveCollection<Character>
      Specified by:
      iterator in interface PrimitiveCollection.OfChar
      Returns:
      a CharIterator; use its nextChar() method instead of next()
    • append

      public CharList append(CharSequence csq)
      Specified by:
      append in interface Appendable
    • append

      public CharList append(CharSequence csq, int start, int end)
      Specified by:
      append in interface Appendable
    • append

      public CharList append(char c)
      Specified by:
      append in interface Appendable
    • appendLine

      public CharList appendLine()
      Appends a literal newline (Unicode character u000A).
      Returns:
      this, for chaining.
    • line

      public CharList line()
      Appends a literal newline (Unicode character u000A). This is identical to appendLine() but is faster to type or recommend.
      Returns:
      this, for chaining.
    • append

      public CharList append(int number)
      Appends the base-10 signed textual form of the given number, without allocating. This uses Base.appendSigned(CharSequence, int).
      Parameters:
      number - the int to append
      Returns:
      this, for chaining
    • append

      public CharList append(long number)
      Appends the base-10 signed textual form of the given number, without allocating. This uses Base.appendSigned(CharSequence, long). This does not append a trailing 'L'.
      Parameters:
      number - the long to append
      Returns:
      this, for chaining
    • append

      public CharList append(float number)
      Appends the base-10 decimal or engineering textual form of the given number, without allocating. This uses Base.appendGeneral(CharSequence, float). This does not append a trailing 'f'.
      Parameters:
      number - the float to append
      Returns:
      this, for chaining
    • append

      public CharList append(double number)
      Appends the base-10 decimal or engineering textual form of the given number, without allocating. This uses Base.appendGeneral(CharSequence, double).
      Parameters:
      number - the double to append
      Returns:
      this, for chaining
    • append

      public CharList append(boolean value)
      Appends either the four chars 't', 'r', 'u', 'e' if value is 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

      public CharList padLeft(int count, char padWith)
      Adds count repetitions of padWith to the start (left) of this list.
      Parameters:
      count - how many repetitions of padWith to add
      padWith - the item to pad with
      Returns:
      this, for chaining
    • padRight

      public CharList padRight(int count, char padWith)
      Adds count repetitions of padWith to the end (right) of this list.
      Parameters:
      count - how many repetitions of padWith to add
      padWith - the item to pad with
      Returns:
      this, for chaining
    • compareTo

      public int compareTo(CharList o)
      Specified by:
      compareTo in interface Comparable<CharList>
    • compareWith

      public int compareWith(CharSequence other)
      Compares this CharList with an arbitrary CharSequence type, returning the lexicographical comparison of the two as if Java 11's CharSequence.compare() was called on this and other. This does not need Java 11.
      The name here is different from compareTo(CharList) because this does not satisfy an important constraint of the Comparable interface (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 return Integer.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

      public int compareWithIgnoreCase(CharSequence other)
      Compares this CharList with an arbitrary CharSequence type, returning the lexicographical comparison of the two as if Java 11's CharSequence.compare() was called on this if it had been entirely raised to upper case and other if it also had been entirely raised to upper case. This does not need Java 11. This uses Casing.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 from compareTo(CharList) because this does not satisfy an important constraint of the Comparable interface (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 return Integer.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

      public static CharList 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

      public static CharList with(char item)
      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

      public static CharList with(char item0, char item1)
      Creates a new CharList that holds only the given items, but can be resized.
      Parameters:
      item0 - a char item
      item1 - a char item
      Returns:
      a new CharList that holds the given items
    • with

      public static CharList with(char item0, char item1, char item2)
      Creates a new CharList that holds only the given items, but can be resized.
      Parameters:
      item0 - a char item
      item1 - a char item
      item2 - 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)
      Creates a new CharList that holds only the given items, but can be resized.
      Parameters:
      item0 - a char item
      item1 - a char item
      item2 - a char item
      item3 - 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)
      Creates a new CharList that holds only the given items, but can be resized.
      Parameters:
      item0 - a char item
      item1 - a char item
      item2 - a char item
      item3 - a char item
      item4 - 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)
      Creates a new CharList that holds only the given items, but can be resized.
      Parameters:
      item0 - a char item
      item1 - a char item
      item2 - a char item
      item3 - a char item
      item4 - a char item
      item5 - 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 item
      item1 - a char item
      item2 - a char item
      item3 - a char item
      item4 - a char item
      item5 - a char item
      item6 - 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 item
      item1 - a char item
      item2 - a char item
      item3 - a char item
      item4 - a char item
      item5 - a char item
      item6 - a char item
      Returns:
      a new CharList that holds the given items
    • with

      public static CharList with(char... varargs)
      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

      public static CharList parse(String str, String delimiter)
      Calls parse(String, String, boolean) with brackets set to false.
      Parameters:
      str - a String that will be parsed in full
      delimiter - the delimiter between items in str
      Returns:
      a new collection parsed from str
    • parse

      public static CharList parse(String str, String delimiter, boolean brackets)
      Creates a new collection and fills it by calling PrimitiveCollection.OfChar.addLegible(String, String, int, int) on either all of str (if brackets is false) or str without its first and last chars (if brackets is true). Each item is expected to be separated by delimiter.
      Parameters:
      str - a String that will be parsed in full (depending on brackets)
      delimiter - the delimiter between items in str
      brackets - if true, the first and last chars in str will be ignored
      Returns:
      a new collection parsed from str
    • parse

      public static CharList parse(String str, String delimiter, int offset, int length)
      Creates a new collection and fills it by calling PrimitiveCollection.OfChar.addLegible(String, String, int, int) with the given four parameters as-is.
      Parameters:
      str - a String that will have the given section parsed
      delimiter - the delimiter between items in str
      offset - the first position to parse in str, inclusive
      length - how many chars to parse, starting from offset
      Returns:
      a new collection parsed from str