org.joda.primitives.list.impl
Class AbstractCharList

java.lang.Object
  extended by org.joda.primitives.collection.impl.AbstractPrimitiveCollectable<Character>
      extended by org.joda.primitives.collection.impl.AbstractCharCollection
          extended by org.joda.primitives.list.impl.AbstractCharList
All Implemented Interfaces:
Iterable<Character>, Collection<Character>, List<Character>, CharCollection, PrimitiveCollection<Character>, CharIterable, CharList, PrimitiveList<Character>, PrimitiveCollectable<Character>
Direct Known Subclasses:
ArrayCharList, ImmutableArrayCharList, StringBufferCharList, StringCharList

public abstract class AbstractCharList
extends AbstractCharCollection
implements CharList

Abstract base class for lists of primitive 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.

Since:
1.0
Version:
CODE GENERATED
Author:
Stephen Colebourne, Rodney Waldhoff, Jason Tiscione

Nested Class Summary
protected static class AbstractCharList.PListIterator
          List iterator.
 
Constructor Summary
protected AbstractCharList()
          Constructor.
 
Method Summary
 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.
 
Methods inherited from class org.joda.primitives.collection.impl.AbstractCharCollection
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
 
Methods inherited from class org.joda.primitives.collection.impl.AbstractPrimitiveCollectable
clone, isEmpty, optimize
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.joda.primitives.list.CharList
getChar
 
Methods inherited from interface org.joda.primitives.collection.PrimitiveCollection
containsAny
 
Methods inherited from interface org.joda.primitives.PrimitiveCollectable
clone, isEmpty, optimize, size
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from interface org.joda.primitives.collection.CharCollection
addAll, addAll, containsAll, containsAll, containsAll, containsAny, containsAny, containsAny, removeAll, removeAll, removeAll, removeAll, removeFirst, retainAll, retainAll, retainAll, toCharArray, toCharArray
 
Methods inherited from interface org.joda.primitives.collection.PrimitiveCollection
containsAny
 
Methods inherited from interface org.joda.primitives.PrimitiveCollectable
clone, isEmpty, optimize, size
 

Constructor Detail

AbstractCharList

protected AbstractCharList()
Constructor.

Method Detail

iterator

public CharListIterator iterator()
Gets an iterator over this list.

Specified by:
iterator in interface Iterable<Character>
Specified by:
iterator in interface Collection<Character>
Specified by:
iterator in interface List<Character>
Specified by:
iterator in interface CharCollection
Specified by:
iterator in interface CharIterable
Specified by:
iterator in interface CharList
Returns:
an iterator over this list, not null

listIterator

public CharListIterator listIterator()
Gets a list iterator over this list.

This implementation uses charListIterator(int).

Specified by:
listIterator in interface List<Character>
Specified by:
listIterator in interface CharList
Returns:
an iterator over this list, not null

listIterator

public CharListIterator listIterator(int index)
Gets a list iterator over this list from a start index.

Specified by:
listIterator in interface List<Character>
Specified by:
listIterator in interface CharList
Parameters:
index - the index to start from
Returns:
an iterator over this list, not null
Throws:
IndexOutOfBoundsException - if the index is invalid

firstChar

public char firstChar()
Gets the first primitive value.

Specified by:
firstChar in interface CharList
Returns:
value at index zero
Throws:
IndexOutOfBoundsException - if the size is zero

lastChar

public char lastChar()
Gets the last primitive value.

Specified by:
lastChar in interface CharList
Returns:
value at index size() - 1
Throws:
IndexOutOfBoundsException - if the size is zero

contains

public boolean contains(char value)
Checks whether this collection contains a specified primitive value.

This implementation uses getChar(int).

Specified by:
contains in interface CharCollection
Overrides:
contains in class AbstractCharCollection
Parameters:
value - the value to search for
Returns:
true if the value is found

indexOf

public int indexOf(char value)
Gets the first index of the specified primitive value.

This implementation uses indexof(char, int).

Specified by:
indexOf in interface CharList
Parameters:
value - the value to search for
Returns:
the zero-based index, or -1 if not found

indexOf

public int indexOf(char value,
                   int fromIndexInclusive)
Gets the first index of the specified primitive 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.

This implementation uses get(int).

Specified by:
indexOf in interface CharList
Parameters:
value - the value to search for
fromIndexInclusive - the index to start searching from, inclusive
Returns:
the zero-based index, or -1 if not found

lastIndexOf

public int lastIndexOf(char value)
Gets the last index of the specified primitive value.

This implementation uses lastIndexof(char, int).

Specified by:
lastIndexOf in interface CharList
Parameters:
value - the value to search for
Returns:
the zero-based index, or -1 if not found

lastIndexOf

public int lastIndexOf(char value,
                       int fromIndexInclusive)
Gets the first index of the specified primitive 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.

This implementation uses get(int).

Specified by:
lastIndexOf in interface CharList
Parameters:
value - the value to search for
fromIndexInclusive - the index to start searching from, inclusive
Returns:
the zero-based index, or -1 if not found

toStringContents

public String toStringContents()
Gets the contents of the list as a String.

Specified by:
toStringContents in interface CharList
Returns:
the list contents

toCharArray

public char[] toCharArray(int fromIndexInclusive,
                          int toIndexExclusive)
Gets a range of elements as an array.

Specified by:
toCharArray in interface CharList
Parameters:
fromIndexInclusive - the index to start from, inclusive
toIndexExclusive - the index to end at, exclusive
Returns:
a new array containing a copy of the range of elements, not null
Throws:
IndexOutOfBoundsException - if either index is invalid

subList

public CharList subList(int fromIndexInclusive,
                        int toIndexExclusive)
Gets a range view of part of this list.

This method allows operations to work on a range within the greater list. Changes made to the either object will affect the other.

Specified by:
subList in interface List<Character>
Specified by:
subList in interface CharList
Parameters:
fromIndexInclusive - the index to start from, inclusive
toIndexExclusive - the index to end at, exclusive
Returns:
a new CharList for the subList, not null
Throws:
IndexOutOfBoundsException - if either index is invalid

clear

public void clear()
Clears the listof all elements (optional operation).

This implementation uses removeRange(int, int).

Specified by:
clear in interface Collection<Character>
Specified by:
clear in interface List<Character>
Specified by:
clear in interface PrimitiveCollectable<Character>
Overrides:
clear in class AbstractCharCollection
Throws:
UnsupportedOperationException - if method not supported by this collection

add

public boolean add(char value)
Adds a primitive value to this collection (optional operation).

This implementation uses add(int, char).

Specified by:
add in interface CharCollection
Overrides:
add in class AbstractCharCollection
Parameters:
value - the value to add to this collection
Returns:
true if this collection was modified by this method call
Throws:
IllegalArgumentException - if value is rejected by this collection
UnsupportedOperationException - if not supported by this collection

add

public boolean add(int index,
                   char value)
Adds a primitive value to this list at an index (optional operation).

This implementation throws UnsupportedOperationException.

Specified by:
add in interface CharList
Parameters:
index - the index to add at
value - the value to add to this collection
Returns:
true if this list was modified by this method call
Throws:
IndexOutOfBoundsException - if the index is invalid
IllegalArgumentException - if value is rejected by this collection
UnsupportedOperationException - if not supported by this collection

addAll

public boolean addAll(char[] values)
Adds an array of primitive values to this list at an index (optional operation).

This implementation uses addAll(int, char).

Specified by:
addAll in interface CharCollection
Overrides:
addAll in class AbstractCharCollection
Parameters:
values - the values to add to this collection, null treated as empty array
Returns:
true if this list was modified by this method call
Throws:
IndexOutOfBoundsException - if the index is invalid
IllegalArgumentException - if value is rejected by this collection
UnsupportedOperationException - if not supported by this collection

addAll

public boolean addAll(int index,
                      char[] values)
Adds an array of primitive values to this list at an index (optional operation).

This method is optional, throwing an UnsupportedOperationException if the collection cannot be added to.

Specified by:
addAll in interface CharList
Parameters:
index - the index to add at
values - the values to add to this collection, null treated as empty array
Returns:
true if this list was modified by this method call
Throws:
IndexOutOfBoundsException - if the index is invalid
IllegalArgumentException - if value is rejected by this collection
UnsupportedOperationException - if not supported by this collection

removeCharAt

public char removeCharAt(int index)
Removes a primitive value by index from the list (optional operation).

This implementation throws UnsupportedOperationException.

Specified by:
removeCharAt in interface CharList
Parameters:
index - the index to remove from
Returns:
the primitive value previously at this index
Throws:
IndexOutOfBoundsException - if the index is invalid
UnsupportedOperationException - if not supported by this collection

removeChar

public boolean removeChar(char value)
Removes the first occurrence of a primitive value from the list (optional operation).

This implementation uses get(int) and removeCharAt(int).

Parameters:
value - the value to remove
Returns:
the primitive value previously at this index
Throws:
UnsupportedOperationException - if not supported by this collection

removeRange

public boolean removeRange(int fromIndexInclusive,
                           int toIndexExclusive)
Removes a range of values from the list (optional operation).

This implementation uses removeCharAt(int).

Specified by:
removeRange in interface PrimitiveList<Character>
Parameters:
fromIndexInclusive - the start of the range to remove, inclusive
toIndexExclusive - the end of the range to remove, exclusive
Returns:
true if the collection was modified
Throws:
IndexOutOfBoundsException - if the index is invalid
UnsupportedOperationException - if remove is not supported

set

public char set(int index,
                char value)
Sets the primitive value at a specified index.

This implementation throws UnsupportedOperationException.

Specified by:
set in interface CharList
Parameters:
index - the index to set
value - the value to store
Returns:
the previous value at the index
Throws:
IndexOutOfBoundsException - if the index is invalid
IllegalArgumentException - if value is rejected by this collection
UnsupportedOperationException - if not supported by this collection

get

public Character get(int index)
Gets the Character value at the specified index.

Specified by:
get in interface List<Character>
Parameters:
index - the index to get from
Returns:
value at the index
Throws:
IndexOutOfBoundsException - if the index is invalid

first

public Character first()
Gets the first Character value.

Specified by:
first in interface PrimitiveList<Character>
Returns:
value at index zero or null if the size is zero

last

public Character last()
Gets the last Character value.

Specified by:
last in interface PrimitiveList<Character>
Returns:
value at index size() - 1 or null if the size is zero

indexOf

public int indexOf(Object value)
Gets the first index of the specified Character value.

Specified by:
indexOf in interface List<Character>
Parameters:
value - the value to search for
Returns:
the zero-based index, or -1 if not found
Throws:
NullPointerException - if the value if null
ClassCastException - if the object is not Character

indexOf

public int indexOf(Object value,
                   int fromIndexInclusive)
Gets the first index of the specified 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.

Parameters:
value - the value to search for
fromIndexInclusive - the index to start searching from, inclusive
Returns:
the zero-based index, or -1 if not found
Throws:
NullPointerException - if the value if null
ClassCastException - if the object is not Character

lastIndexOf

public int lastIndexOf(Object value)
Gets the last index of the specified Character value.

Specified by:
lastIndexOf in interface List<Character>
Parameters:
value - the value to search for
Returns:
the zero-based index, or -1 if not found
Throws:
NullPointerException - if the value if null
ClassCastException - if the object is not Character

lastIndexOf

public int lastIndexOf(Object value,
                       int fromIndexInclusive)
Gets the first index of the specified 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.

Parameters:
value - the value to search for
fromIndexInclusive - the index to start searching from, inclusive
Returns:
the zero-based index, or -1 if not found
Throws:
NullPointerException - if the value if null
ClassCastException - if the object is not Character

add

public boolean add(Character value)
Adds the Character value to this collection (optional operation).

This method is optional, throwing an UnsupportedOperationException if the collection cannot be added to.

Specified by:
add in interface Collection<Character>
Specified by:
add in interface List<Character>
Overrides:
add in class AbstractCharCollection
Parameters:
value - the value to add to this collection
Returns:
true if this collection was modified by this method call
Throws:
IllegalArgumentException - if value is rejected by this collection
UnsupportedOperationException - if not supported by this collection

add

public void add(int index,
                Character value)
Adds the Character value to this list at an index (optional operation).

This method is optional, throwing an UnsupportedOperationException if the collection cannot be added to.

Specified by:
add in interface List<Character>
Parameters:
index - the index to add at
value - the value to add to this collection
Throws:
IndexOutOfBoundsException - if the index is invalid
ClassCastException - if the object is not Character
IllegalArgumentException - if value is rejected by this collection
UnsupportedOperationException - if not supported by this collection

addAll

public boolean addAll(int index,
                      Collection<? extends Character> coll)
Adds an array of Character values to this list at an index (optional operation).

This method is optional, throwing an UnsupportedOperationException if the collection cannot be added to.

Specified by:
addAll in interface List<Character>
Parameters:
index - the index to add at
coll - the values to add to this collection
Returns:
true if this list was modified by this method call
Throws:
IndexOutOfBoundsException - if the index is invalid
ClassCastException - if any object is not Character
IllegalArgumentException - if value is rejected by this collection
UnsupportedOperationException - if not supported by this collection

remove

public Character remove(int index)
Deprecated. This method should only be used when working with List and not when working with CharList - use removeCharAt(int)

Removes a primitive value by index from the list (optional operation).

This implementation uses removeCharAt(int).

Specified by:
remove in interface List<Character>
Specified by:
remove in interface CharList
Parameters:
index - the index to remove from
Returns:
the primitive value previously at this index
Throws:
IndexOutOfBoundsException - if the index is invalid
UnsupportedOperationException - if not supported by this collection

set

public Character set(int index,
                     Character value)
Sets the Character value at a specified index.

This implementation uses set(int, char).

Specified by:
set in interface List<Character>
Parameters:
index - the index to set
value - the value to store
Returns:
the previous value at the index
Throws:
IndexOutOfBoundsException - if the index is invalid
IllegalArgumentException - if value is rejected by this collection
UnsupportedOperationException - if not supported by this collection

equals

public boolean equals(Object obj)
Compares this list to another as per the contract of List.

Specified by:
equals in interface Collection<Character>
Specified by:
equals in interface List<Character>
Overrides:
equals in class Object
Parameters:
obj - the object to compare to
Returns:
true if the lists are equal

hashCode

public int hashCode()
Gets the hashCode of this list as per the contract of List.

Specified by:
hashCode in interface Collection<Character>
Specified by:
hashCode in interface List<Character>
Overrides:
hashCode in class Object
Returns:
the hash code for this list

arrayCopy

protected void arrayCopy(int fromIndex,
                         char[] dest,
                         int destIndex,
                         int size)
Copies data from this collection into the specified array. This method is pre-validated.

Overrides:
arrayCopy in class AbstractCharCollection
Parameters:
fromIndex - the index to start from
dest - the destination array
destIndex - the destination start index
size - the number of items to copy

isSetModifiable

protected boolean isSetModifiable()
Are the set methods supported.

This implementation returns false.

Returns:
true if supported

isModifiable

public boolean isModifiable()
Is the collection modifiable in any way.

Specified by:
isModifiable in interface PrimitiveCollectable<Character>
Overrides:
isModifiable in class AbstractCharCollection
Returns:
true if supported

checkSetModifiable

protected void checkSetModifiable()
Check whether add is suported and throw an exception.


checkIndexExists

protected void checkIndexExists(int index)
Checks whether an index is valid or not.

Parameters:
index - the index to check
Throws:
IndexOutOfBoundsException - if either index is invalid

checkIndex

protected void checkIndex(int index)
Checks whether an index is valid or not.

Parameters:
index - the index to check
Throws:
IndexOutOfBoundsException - if either index is invalid

checkRange

protected void checkRange(int fromIndexInclusive,
                          int toIndexExclusive)
Checks whether a range is valid or not.

Parameters:
fromIndexInclusive - the index to start from, inclusive
toIndexExclusive - the index to end at, exclusive
Throws:
IndexOutOfBoundsException - if either index is invalid


Copyright © 2005-2010 Joda.org. All Rights Reserved.