public abstract class AbstractCharList extends AbstractCharCollection implements CharList
char
elements.
This class implements Collection
allowing
seamless integration with other APIs.
The get(int)
and size()
methods must be
implemented by subclases.
To make the subclass modifiable, the add(int, char)
,
removeIndex(int)
and set(int, char) must also be implemented.
Subclasses may override other methods to increase efficiency.
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractCharList.PListIterator
List iterator.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractCharList()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(char value)
Adds a primitive value to this collection (optional operation).
|
boolean |
add(Character value)
Adds the
Character value to this collection (optional operation). |
boolean |
add(int index,
char value)
Adds a primitive value to this list at an index (optional operation).
|
void |
add(int index,
Character value)
Adds the
Character value to this list at an index (optional operation). |
boolean |
addAll(char[] values)
Adds an array of primitive values to this list at an index (optional operation).
|
boolean |
addAll(int index,
char[] values)
Adds an array of primitive values to this list at an index (optional operation).
|
boolean |
addAll(int index,
Collection<? extends Character> coll)
Adds an array of
Character values to this list at an index (optional operation). |
protected void |
arrayCopy(int fromIndex,
char[] dest,
int destIndex,
int size)
Copies data from this collection into the specified array.
|
protected void |
checkIndex(int index)
Checks whether an index is valid or not.
|
protected void |
checkIndexExists(int index)
Checks whether an index is valid or not.
|
protected void |
checkRange(int fromIndexInclusive,
int toIndexExclusive)
Checks whether a range is valid or not.
|
protected void |
checkSetModifiable()
Check whether add is suported and throw an exception.
|
void |
clear()
Clears the listof all elements (optional operation).
|
boolean |
contains(char value)
Checks whether this collection contains a specified primitive value.
|
boolean |
equals(Object obj)
Compares this list to another as per the contract of
List . |
Character |
first()
Gets the first
Character value. |
char |
firstChar()
Gets the first primitive value.
|
Character |
get(int index)
Gets the
Character value at the specified index. |
int |
hashCode()
Gets the hashCode of this list as per the contract of
List . |
int |
indexOf(char value)
Gets the first index of the specified primitive value.
|
int |
indexOf(char value,
int fromIndexInclusive)
Gets the first index of the specified primitive value from an index.
|
int |
indexOf(Object value)
Gets the first index of the specified
Character value. |
int |
indexOf(Object value,
int fromIndexInclusive)
Gets the first index of the specified
Character value from an index. |
boolean |
isModifiable()
Is the collection modifiable in any way.
|
protected boolean |
isSetModifiable()
Are the set methods supported.
|
CharListIterator |
iterator()
Gets an iterator over this list.
|
Character |
last()
Gets the last
Character value. |
char |
lastChar()
Gets the last primitive value.
|
int |
lastIndexOf(char value)
Gets the last index of the specified primitive value.
|
int |
lastIndexOf(char value,
int fromIndexInclusive)
Gets the first index of the specified primitive value from an index.
|
int |
lastIndexOf(Object value)
Gets the last index of the specified
Character value. |
int |
lastIndexOf(Object value,
int fromIndexInclusive)
Gets the first index of the specified
Character value from an index. |
CharListIterator |
listIterator()
Gets a list iterator over this list.
|
CharListIterator |
listIterator(int index)
Gets a list iterator over this list from a start index.
|
Character |
remove(int index)
Deprecated.
This method should only be used when working with List and
not when working with CharList - use
removeCharAt(int) |
boolean |
removeChar(char value)
Removes the first occurrence of a primitive value from the list (optional operation).
|
char |
removeCharAt(int index)
Removes a primitive value by index from the list (optional operation).
|
boolean |
removeRange(int fromIndexInclusive,
int toIndexExclusive)
Removes a range of values from the list (optional operation).
|
char |
set(int index,
char value)
Sets the primitive value at a specified index.
|
Character |
set(int index,
Character value)
Sets the
Character value at a specified index. |
CharList |
subList(int fromIndexInclusive,
int toIndexExclusive)
Gets a range view of part of this list.
|
char[] |
toCharArray(int fromIndexInclusive,
int toIndexExclusive)
Gets a range of elements as an array.
|
String |
toStringContents()
Gets the contents of the list as a String.
|
addAll, addAll, addAll, checkAddModifiable, checkRemoveModifiable, contains, containsAll, containsAll, containsAll, containsAll, containsAny, containsAny, containsAny, containsAny, isAddModifiable, isRemoveModifiable, isToPrimitivePossible, remove, removeAll, removeAll, removeAll, removeAll, removeAll, removeFirst, retainAll, retainAll, retainAll, retainAll, toArray, toArray, toCharArray, toCharArray, toObject, toPrimitive, toPrimitiveArray, toString
clone, isEmpty, optimize
finalize, getClass, notify, notifyAll, wait, wait, wait
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, size, toArray, toArray
addAll, addAll, containsAll, containsAll, containsAll, containsAny, containsAny, containsAny, removeAll, removeAll, removeAll, removeAll, removeFirst, retainAll, retainAll, retainAll, toCharArray, toCharArray
containsAny
clone, isEmpty, optimize, size
protected AbstractCharList()
public CharListIterator iterator()
iterator
in interface Iterable<Character>
iterator
in interface Collection<Character>
iterator
in interface List<Character>
iterator
in interface CharCollection
iterator
in interface CharIterable
iterator
in interface CharList
public CharListIterator listIterator()
This implementation uses charListIterator(int)
.
listIterator
in interface List<Character>
listIterator
in interface CharList
public CharListIterator listIterator(int index)
listIterator
in interface List<Character>
listIterator
in interface CharList
index
- the index to start fromIndexOutOfBoundsException
- if the index is invalidpublic char firstChar()
firstChar
in interface CharList
IndexOutOfBoundsException
- if the size is zeropublic char lastChar()
lastChar
in interface CharList
size() - 1
IndexOutOfBoundsException
- if the size is zeropublic boolean contains(char value)
This implementation uses getChar(int)
.
contains
in interface CharCollection
contains
in class AbstractCharCollection
value
- the value to search fortrue
if the value is foundpublic int indexOf(char value)
This implementation uses indexof(char, int)
.
public int indexOf(char value, int fromIndexInclusive)
This method follows the conventions of String
in that a
negative index is treated as zero, and an index greater than the list
size will simply return -1
.
This implementation uses get(int)
.
public int lastIndexOf(char value)
This implementation uses lastIndexof(char, int)
.
lastIndexOf
in interface CharList
value
- the value to search for-1
if not foundpublic int lastIndexOf(char value, int fromIndexInclusive)
This method follows the conventions of String
in that an
index greater than the list size will start searching at the list size,
and a negative index simply returns -1
.
This implementation uses get(int)
.
lastIndexOf
in interface CharList
value
- the value to search forfromIndexInclusive
- the index to start searching from, inclusive-1
if not foundpublic String toStringContents()
toStringContents
in interface CharList
public char[] toCharArray(int fromIndexInclusive, int toIndexExclusive)
toCharArray
in interface CharList
fromIndexInclusive
- the index to start from, inclusivetoIndexExclusive
- the index to end at, exclusiveIndexOutOfBoundsException
- if either index is invalidpublic CharList subList(int fromIndexInclusive, int toIndexExclusive)
This method allows operations to work on a range within the greater list. Changes made to the either object will affect the other.
subList
in interface List<Character>
subList
in interface CharList
fromIndexInclusive
- the index to start from, inclusivetoIndexExclusive
- the index to end at, exclusiveIndexOutOfBoundsException
- if either index is invalidpublic void clear()
This implementation uses removeRange(int, int)
.
clear
in interface Collection<Character>
clear
in interface List<Character>
clear
in interface PrimitiveCollectable<Character>
clear
in class AbstractCharCollection
UnsupportedOperationException
- if method not supported by this collectionpublic boolean add(char value)
This implementation uses add(int, char)
.
add
in interface CharCollection
add
in class AbstractCharCollection
value
- the value to add to this collectiontrue
if this collection was modified by this method callIllegalArgumentException
- if value is rejected by this collectionUnsupportedOperationException
- if not supported by this collectionpublic boolean add(int index, char value)
This implementation throws UnsupportedOperationException.
add
in interface CharList
index
- the index to add atvalue
- the value to add to this collectiontrue
if this list was modified by this method callIndexOutOfBoundsException
- if the index is invalidIllegalArgumentException
- if value is rejected by this collectionUnsupportedOperationException
- if not supported by this collectionpublic boolean addAll(char[] values)
This implementation uses addAll(int, char)
.
addAll
in interface CharCollection
addAll
in class AbstractCharCollection
values
- the values to add to this collection, null treated as empty arraytrue
if this list was modified by this method callIndexOutOfBoundsException
- if the index is invalidIllegalArgumentException
- if value is rejected by this collectionUnsupportedOperationException
- if not supported by this collectionpublic boolean addAll(int index, char[] values)
This method is optional, throwing an UnsupportedOperationException if the collection cannot be added to.
addAll
in interface CharList
index
- the index to add atvalues
- the values to add to this collection, null treated as empty arraytrue
if this list was modified by this method callIndexOutOfBoundsException
- if the index is invalidIllegalArgumentException
- if value is rejected by this collectionUnsupportedOperationException
- if not supported by this collectionpublic char removeCharAt(int index)
This implementation throws UnsupportedOperationException.
removeCharAt
in interface CharList
index
- the index to remove fromIndexOutOfBoundsException
- if the index is invalidUnsupportedOperationException
- if not supported by this collectionpublic boolean removeChar(char value)
This implementation uses get(int)
and removeCharAt(int)
.
value
- the value to removeUnsupportedOperationException
- if not supported by this collectionpublic boolean removeRange(int fromIndexInclusive, int toIndexExclusive)
This implementation uses removeCharAt(int)
.
removeRange
in interface PrimitiveList<Character>
fromIndexInclusive
- the start of the range to remove, inclusivetoIndexExclusive
- the end of the range to remove, exclusivetrue
if the collection was modifiedIndexOutOfBoundsException
- if the index is invalidUnsupportedOperationException
- if remove is not supportedpublic char set(int index, char value)
This implementation throws UnsupportedOperationException.
set
in interface CharList
index
- the index to setvalue
- the value to storeIndexOutOfBoundsException
- if the index is invalidIllegalArgumentException
- if value is rejected by this collectionUnsupportedOperationException
- if not supported by this collectionpublic Character get(int index)
Character
value at the specified index.get
in interface List<Character>
index
- the index to get fromIndexOutOfBoundsException
- if the index is invalidpublic Character first()
Character
value.first
in interface PrimitiveList<Character>
public Character last()
Character
value.last
in interface PrimitiveList<Character>
size() - 1
or null if the size is zeropublic int indexOf(Object value)
Character
value.indexOf
in interface List<Character>
value
- the value to search for-1
if not foundNullPointerException
- if the value if nullClassCastException
- if the object is not Character
public int indexOf(Object value, int fromIndexInclusive)
Character
value from an index.
This method follows the conventions of String
in that a
negative index is treated as zero, and an index greater than the list
size will simply return -1
.
value
- the value to search forfromIndexInclusive
- the index to start searching from, inclusive-1
if not foundNullPointerException
- if the value if nullClassCastException
- if the object is not Character
public int lastIndexOf(Object value)
Character
value.lastIndexOf
in interface List<Character>
value
- the value to search for-1
if not foundNullPointerException
- if the value if nullClassCastException
- if the object is not Character
public int lastIndexOf(Object value, int fromIndexInclusive)
Character
value from an index.
This method follows the conventions of String
in that an
index greater than the list size will start searching at the list size,
and a negative index simply returns -1
.
value
- the value to search forfromIndexInclusive
- the index to start searching from, inclusive-1
if not foundNullPointerException
- if the value if nullClassCastException
- if the object is not Character
public boolean add(Character value)
Character
value to this collection (optional operation).
This method is optional, throwing an UnsupportedOperationException if the collection cannot be added to.
add
in interface Collection<Character>
add
in interface List<Character>
add
in class AbstractCharCollection
value
- the value to add to this collectiontrue
if this collection was modified by this method callIllegalArgumentException
- if value is rejected by this collectionUnsupportedOperationException
- if not supported by this collectionpublic void add(int index, Character value)
Character
value to this list at an index (optional operation).
This method is optional, throwing an UnsupportedOperationException if the collection cannot be added to.
add
in interface List<Character>
index
- the index to add atvalue
- the value to add to this collectionIndexOutOfBoundsException
- if the index is invalidClassCastException
- if the object is not Character
IllegalArgumentException
- if value is rejected by this collectionUnsupportedOperationException
- if not supported by this collectionpublic boolean addAll(int index, Collection<? extends Character> coll)
Character
values to this list at an index (optional operation).
This method is optional, throwing an UnsupportedOperationException if the collection cannot be added to.
addAll
in interface List<Character>
index
- the index to add atcoll
- the values to add to this collectiontrue
if this list was modified by this method callIndexOutOfBoundsException
- if the index is invalidClassCastException
- if any object is not Character
IllegalArgumentException
- if value is rejected by this collectionUnsupportedOperationException
- if not supported by this collectionpublic Character remove(int index)
removeCharAt(int)
This implementation uses removeCharAt(int)
.
remove
in interface List<Character>
remove
in interface CharList
index
- the index to remove fromIndexOutOfBoundsException
- if the index is invalidUnsupportedOperationException
- if not supported by this collectionpublic Character set(int index, Character value)
Character
value at a specified index.
This implementation uses set(int, char)
.
set
in interface List<Character>
index
- the index to setvalue
- the value to storeIndexOutOfBoundsException
- if the index is invalidIllegalArgumentException
- if value is rejected by this collectionUnsupportedOperationException
- if not supported by this collectionpublic int hashCode()
List
.protected void arrayCopy(int fromIndex, char[] dest, int destIndex, int size)
arrayCopy
in class AbstractCharCollection
fromIndex
- the index to start fromdest
- the destination arraydestIndex
- the destination start indexsize
- the number of items to copyprotected boolean isSetModifiable()
This implementation returns false.
public boolean isModifiable()
isModifiable
in interface PrimitiveCollectable<Character>
isModifiable
in class AbstractCharCollection
protected void checkSetModifiable()
protected void checkIndexExists(int index)
index
- the index to checkIndexOutOfBoundsException
- if either index is invalidprotected void checkIndex(int index)
index
- the index to checkIndexOutOfBoundsException
- if either index is invalidprotected void checkRange(int fromIndexInclusive, int toIndexExclusive)
fromIndexInclusive
- the index to start from, inclusivetoIndexExclusive
- the index to end at, exclusiveIndexOutOfBoundsException
- if either index is invalidCopyright © 2005-2012 Joda.org. All Rights Reserved.