Class AbstractCharList
- java.lang.Object
-
- java.util.AbstractCollection<Character>
-
- org.codelibs.jhighlight.fastutil.chars.AbstractCharCollection
-
- org.codelibs.jhighlight.fastutil.chars.AbstractCharList
-
- All Implemented Interfaces:
Comparable<List<? extends Character>>
,Iterable<Character>
,Collection<Character>
,List<Character>
,CharCollection
,CharIterable
,CharList
,CharStack
,Stack<Character>
- Direct Known Subclasses:
AbstractCharList.CharSubList
,CharArrayList
public abstract class AbstractCharList extends AbstractCharCollection implements CharList, CharStack
An abstract class providing basic methods for lists implementing a type-specific list interface.As an additional bonus, this class implements on top of the list operations a type-specific stack.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractCharList.CharSubList
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractCharList()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
add(char k)
void
add(int index, char k)
void
add(int index, Character ok)
Delegates to the corresponding type-specific method.boolean
addAll(int index, Collection<? extends Character> c)
boolean
addAll(int index, CharCollection c)
Delegates to a more generic method.boolean
addAll(int index, CharList l)
Delegates to a more generic method.boolean
addAll(Collection<? extends Character> c)
Delegates to a more generic method.boolean
addAll(CharCollection c)
Adds all elements of the given type-specific collection to this collection.boolean
addAll(CharList l)
void
addElements(int index, char[] a)
Add (hopefully quickly) elements to this type-specific list.void
addElements(int index, char[] a, int offset, int length)
Adds elements to this type-specific list one-by-one.CharListIterator
charListIterator()
Deprecated.CharListIterator
charListIterator(int index)
Deprecated.CharList
charSubList(int from, int to)
Deprecated.int
compareTo(List<? extends Character> l)
Compares this list to another object.boolean
contains(char k)
protected void
ensureIndex(int index)
Ensures that the given index is nonnegative and not greater than the list size.protected void
ensureRestrictedIndex(int index)
Ensures that the given index is nonnegative and smaller than the list size.boolean
equals(Object o)
Character
get(int index)
Delegates to the corresponding type-specific method.void
getElements(int from, char[] a, int offset, int length)
Copies element of this type-specific list into the given array one-by-one.int
hashCode()
Returns the hash code for this list, which is identical toList.hashCode()
.int
indexOf(char k)
int
indexOf(Object ok)
Delegates to the corresponding type-specific method.CharListIterator
iterator()
Returns a type-specific iterator on the elements of this collection.int
lastIndexOf(char k)
int
lastIndexOf(Object ok)
Delegates to the corresponding type-specific method.CharListIterator
listIterator()
Returns a type-specific list iterator on the list.CharListIterator
listIterator(int index)
Returns a type-specific list iterator on the list starting at a given index.Character
peek(int i)
Delegates to the corresponding type-specific method.char
peekChar(int i)
Character
pop()
Delegates to the corresponding type-specific method.char
popChar()
void
push(char o)
void
push(Character o)
Delegates to the corresponding type-specific method.boolean
rem(char k)
Character
remove(int index)
Delegates to the corresponding type-specific method.boolean
remove(Object o)
Delegates torem()
.char
removeChar(int i)
void
removeElements(int from, int to)
Removes elements of this type-specific list one-by-one.char
set(int index, char k)
Character
set(int index, Character ok)
Delegates to the corresponding type-specific method.void
size(int size)
Sets the size of this list.CharList
subList(int from, int to)
Returns a type-specific view of the portion of this list from the indexfrom
, inclusive, to the indexto
, exclusive.Character
top()
Delegates to the corresponding type-specific method.char
topChar()
String
toString()
-
Methods inherited from class org.codelibs.jhighlight.fastutil.chars.AbstractCharCollection
add, charIterator, contains, containsAll, containsAll, isEmpty, rem, removeAll, removeAll, retainAll, retainAll, toArray, toArray, toArray, toCharArray, toCharArray
-
Methods inherited from class java.util.AbstractCollection
clear, size
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.codelibs.jhighlight.fastutil.chars.CharCollection
charIterator, containsAll, removeAll, retainAll, toArray, toArray, toCharArray, toCharArray
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
add, clear, contains, containsAll, isEmpty, removeAll, replaceAll, retainAll, size, sort, spliterator, toArray, toArray
-
-
-
-
Method Detail
-
ensureIndex
protected void ensureIndex(int index)
Ensures that the given index is nonnegative and not greater than the list size.- Parameters:
index
- an index.- Throws:
IndexOutOfBoundsException
- if the given index is negative or greater than the list size.
-
ensureRestrictedIndex
protected void ensureRestrictedIndex(int index)
Ensures that the given index is nonnegative and smaller than the list size.- Parameters:
index
- an index.- Throws:
IndexOutOfBoundsException
- if the given index is negative or not smaller than the list size.
-
add
public void add(int index, char k)
- Specified by:
add
in interfaceCharList
- See Also:
List.add(int,Object)
-
add
public boolean add(char k)
- Specified by:
add
in interfaceCharCollection
- Specified by:
add
in interfaceCharList
- Overrides:
add
in classAbstractCharCollection
- See Also:
Collection.add(Object)
-
removeChar
public char removeChar(int i)
- Specified by:
removeChar
in interfaceCharList
- See Also:
List.remove(int)
-
set
public char set(int index, char k)
- Specified by:
set
in interfaceCharList
- See Also:
List.set(int,Object)
-
addAll
public boolean addAll(int index, Collection<? extends Character> c)
-
addAll
public boolean addAll(Collection<? extends Character> c)
Delegates to a more generic method.- Specified by:
addAll
in interfaceCollection<Character>
- Specified by:
addAll
in interfaceList<Character>
- Overrides:
addAll
in classAbstractCharCollection
- Parameters:
c
- a collection.- Returns:
true
if this collection changed as a result of the call.
-
charListIterator
@Deprecated public CharListIterator charListIterator()
Deprecated.Delegates to the new covariantly stronger generic method.- Specified by:
charListIterator
in interfaceCharList
- See Also:
CharList.listIterator()
-
charListIterator
@Deprecated public CharListIterator charListIterator(int index)
Deprecated.Delegates to the new covariantly stronger generic method.- Specified by:
charListIterator
in interfaceCharList
- See Also:
CharList.listIterator(int)
-
iterator
public CharListIterator iterator()
Description copied from interface:CharCollection
Returns a type-specific iterator on the elements of this collection.Note that this specification strengthens the one given in
Iterable.iterator()
, which was already strengthened in the corresponding type-specific class, but was weakened by the fact that this interface extendsCollection
.- Specified by:
iterator
in interfaceCharCollection
- Specified by:
iterator
in interfaceCharIterable
- Specified by:
iterator
in interfaceCharList
- Specified by:
iterator
in interfaceCollection<Character>
- Specified by:
iterator
in interfaceIterable<Character>
- Specified by:
iterator
in interfaceList<Character>
- Specified by:
iterator
in classAbstractCharCollection
- Returns:
- a type-specific iterator on the elements of this collection.
-
listIterator
public CharListIterator listIterator()
Description copied from interface:CharList
Returns a type-specific list iterator on the list.- Specified by:
listIterator
in interfaceCharList
- Specified by:
listIterator
in interfaceList<Character>
- See Also:
List.listIterator()
-
listIterator
public CharListIterator listIterator(int index)
Description copied from interface:CharList
Returns a type-specific list iterator on the list starting at a given index.- Specified by:
listIterator
in interfaceCharList
- Specified by:
listIterator
in interfaceList<Character>
- See Also:
List.listIterator(int)
-
contains
public boolean contains(char k)
- Specified by:
contains
in interfaceCharCollection
- Overrides:
contains
in classAbstractCharCollection
- See Also:
Collection.contains(Object)
-
indexOf
public int indexOf(char k)
- Specified by:
indexOf
in interfaceCharList
- See Also:
List.indexOf(Object)
-
lastIndexOf
public int lastIndexOf(char k)
- Specified by:
lastIndexOf
in interfaceCharList
- See Also:
List.lastIndexOf(Object)
-
size
public void size(int size)
Description copied from interface:CharList
Sets the size of this list.If the specified size is smaller than the current size, the last elements are discarded. Otherwise, they are filled with 0/
null
/false
.
-
subList
public CharList subList(int from, int to)
Description copied from interface:CharList
Returns a type-specific view of the portion of this list from the indexfrom
, inclusive, to the indexto
, exclusive.Note that this specification strengthens the one given in
List.subList(int,int)
.
-
charSubList
@Deprecated public CharList charSubList(int from, int to)
Deprecated.Delegates to the new covariantly stronger generic method.- Specified by:
charSubList
in interfaceCharList
- See Also:
List.subList(int,int)
-
removeElements
public void removeElements(int from, int to)
Removes elements of this type-specific list one-by-one.This is a trivial iterator-based implementation. It is expected that implementations will override this method with a more optimized version.
- Specified by:
removeElements
in interfaceCharList
- Parameters:
from
- the start index (inclusive).to
- the end index (exclusive).
-
addElements
public void addElements(int index, char[] a, int offset, int length)
Adds elements to this type-specific list one-by-one.This is a trivial iterator-based implementation. It is expected that implementations will override this method with a more optimized version.
- Specified by:
addElements
in interfaceCharList
- Parameters:
index
- the index at which to add elements.a
- the array containing the elements.offset
- the offset of the first element to add.length
- the number of elements to add.
-
addElements
public void addElements(int index, char[] a)
Description copied from interface:CharList
Add (hopefully quickly) elements to this type-specific list.- Specified by:
addElements
in interfaceCharList
- Parameters:
index
- the index at which to add elements.a
- the array containing the elements.
-
getElements
public void getElements(int from, char[] a, int offset, int length)
Copies element of this type-specific list into the given array one-by-one.This is a trivial iterator-based implementation. It is expected that implementations will override this method with a more optimized version.
- Specified by:
getElements
in interfaceCharList
- Parameters:
from
- the start index (inclusive).a
- the destination array.offset
- the offset into the destination array where to store the first element copied.length
- the number of elements to be copied.
-
equals
public boolean equals(Object o)
-
compareTo
public int compareTo(List<? extends Character> l)
Compares this list to another object. If the argument is aList
, this method performs a lexicographical comparison; otherwise, it throws aClassCastException
.- Specified by:
compareTo
in interfaceComparable<List<? extends Character>>
- Parameters:
l
- a list.- Returns:
- if the argument is a
List
, a negative integer, zero, or a positive integer as this list is lexicographically less than, equal to, or greater than the argument. - Throws:
ClassCastException
- if the argument is not a list.
-
hashCode
public int hashCode()
Returns the hash code for this list, which is identical toList.hashCode()
.
-
push
public void push(char o)
- Specified by:
push
in interfaceCharStack
- See Also:
Stack.push(Object)
-
popChar
public char popChar()
- Specified by:
popChar
in interfaceCharStack
- See Also:
Stack.pop()
-
topChar
public char topChar()
- Specified by:
topChar
in interfaceCharStack
- See Also:
Stack.top()
-
peekChar
public char peekChar(int i)
- Specified by:
peekChar
in interfaceCharStack
- See Also:
Stack.peek(int)
-
rem
public boolean rem(char k)
Description copied from interface:CharCollection
Note that this method should be calledremove()
, but the clash with the similarly named index-based method in theList
interface forces us to use a distinguished name. For simplicity, the set interfaces reinstatesremove()
.- Specified by:
rem
in interfaceCharCollection
- Overrides:
rem
in classAbstractCharCollection
- See Also:
Collection.remove(Object)
-
remove
public boolean remove(Object o)
Delegates torem()
.- Specified by:
remove
in interfaceCollection<Character>
- Specified by:
remove
in interfaceList<Character>
- Overrides:
remove
in classAbstractCharCollection
-
addAll
public boolean addAll(int index, CharCollection c)
Delegates to a more generic method.- Specified by:
addAll
in interfaceCharList
- See Also:
List.add(int,Object)
-
addAll
public boolean addAll(int index, CharList l)
Delegates to a more generic method.- Specified by:
addAll
in interfaceCharList
- See Also:
List.add(int,Object)
-
addAll
public boolean addAll(CharCollection c)
Description copied from class:AbstractCharCollection
Adds all elements of the given type-specific collection to this collection.- Specified by:
addAll
in interfaceCharCollection
- Overrides:
addAll
in classAbstractCharCollection
- Parameters:
c
- a type-specific collection.- Returns:
true
if this collection changed as a result of the call.- See Also:
Collection.addAll(Collection)
-
addAll
public boolean addAll(CharList l)
- Specified by:
addAll
in interfaceCharList
- See Also:
List.add(int,Object)
-
add
public void add(int index, Character ok)
Delegates to the corresponding type-specific method.
-
set
public Character set(int index, Character ok)
Delegates to the corresponding type-specific method.
-
get
public Character get(int index)
Delegates to the corresponding type-specific method.
-
indexOf
public int indexOf(Object ok)
Delegates to the corresponding type-specific method.
-
lastIndexOf
public int lastIndexOf(Object ok)
Delegates to the corresponding type-specific method.- Specified by:
lastIndexOf
in interfaceList<Character>
-
remove
public Character remove(int index)
Delegates to the corresponding type-specific method.
-
push
public void push(Character o)
Delegates to the corresponding type-specific method.
-
pop
public Character pop()
Delegates to the corresponding type-specific method.
-
top
public Character top()
Delegates to the corresponding type-specific method.
-
peek
public Character peek(int i)
Delegates to the corresponding type-specific method.
-
toString
public String toString()
- Overrides:
toString
in classAbstractCharCollection
-
-