org.joda.primitives.list.impl
Class StringCharList

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
              extended by org.joda.primitives.list.impl.StringCharList
All Implemented Interfaces:
Cloneable, Iterable<Character>, Collection<Character>, List<Character>, CharCollection, PrimitiveCollection<Character>, CharIterable, CharList, PrimitiveList<Character>, PrimitiveCollectable<Character>

public class StringCharList
extends AbstractCharList
implements Cloneable

Unmodifiable CharList wrapped around a String.

This class implements List allowing seamless integration with other APIs.

Since:
1.0
Author:
Stephen Colebourne

Nested Class Summary
 
Nested classes/interfaces inherited from class org.joda.primitives.list.impl.AbstractCharList
AbstractCharList.PListIterator
 
Field Summary
protected  String string
          The String being wrapped
 
Constructor Summary
StringCharList()
          Constructor that uses an empty string as the datasource.
StringCharList(CharList list)
          Constructor that copies the specified list.
StringCharList(String str)
          Constructor that uses the specified string as the datasource.
 
Method Summary
 boolean contains(char value)
          Checks whether this collection contains a specified primitive value.
 char getChar(int index)
          Gets the character at the specified index.
 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 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 size()
          Gets the size of the list, which is the string length.
 CharList subList(int fromIndexInclusive, int toIndexExclusive)
          Gets a range view of part of this list.
 char[] toCharArray()
          Gets the elements of this collection as an array.
 String toStringContents()
          Gets the String underlying the list.
 
Methods inherited from class org.joda.primitives.list.impl.AbstractCharList
add, add, add, add, addAll, addAll, addAll, arrayCopy, checkIndex, checkIndexExists, checkRange, checkSetModifiable, clear, equals, first, firstChar, get, hashCode, indexOf, indexOf, isModifiable, isSetModifiable, iterator, last, lastChar, lastIndexOf, lastIndexOf, listIterator, listIterator, remove, removeChar, removeCharAt, removeRange, set, set, toCharArray
 
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, 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.collection.PrimitiveCollection
containsAny
 
Methods inherited from interface org.joda.primitives.PrimitiveCollectable
clone, isEmpty, optimize
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, 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
 
Methods inherited from interface org.joda.primitives.collection.PrimitiveCollection
containsAny
 
Methods inherited from interface org.joda.primitives.PrimitiveCollectable
clone, isEmpty, optimize
 

Field Detail

string

protected final String string
The String being wrapped

Constructor Detail

StringCharList

public StringCharList()
Constructor that uses an empty string as the datasource.


StringCharList

public StringCharList(CharList list)
Constructor that copies the specified list.

Parameters:
list - the list to copy, must not be null
Throws:
IllegalArgumentException - if the list is null

StringCharList

public StringCharList(String str)
Constructor that uses the specified string as the datasource.

Parameters:
str - the string to wrap in a list, must not be null
Throws:
IllegalArgumentException - if the string is null
Method Detail

getChar

public char getChar(int index)
Gets the character at the specified index.

Specified by:
getChar in interface CharList
Parameters:
index - the index to retrieve
Returns:
the character at the specified index

size

public int size()
Gets the size of the list, which is the string length.

Specified by:
size in interface Collection<Character>
Specified by:
size in interface List<Character>
Specified by:
size in interface PrimitiveCollectable<Character>
Returns:
the string length

contains

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

This implementation uses String.indexOf(char).

Specified by:
contains in interface CharCollection
Overrides:
contains in class AbstractCharList
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 String.indexOf(char).

Specified by:
indexOf in interface CharList
Overrides:
indexOf in class AbstractCharList
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 String.indexOf(char, int).

Specified by:
indexOf in interface CharList
Overrides:
indexOf in class AbstractCharList
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 String.lastIndexOf(char).

Specified by:
lastIndexOf in interface CharList
Overrides:
lastIndexOf in class AbstractCharList
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 String.lastIndexOf(char, int).

Specified by:
lastIndexOf in interface CharList
Overrides:
lastIndexOf in class AbstractCharList
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 String underlying the list.

Specified by:
toStringContents in interface CharList
Overrides:
toStringContents in class AbstractCharList
Returns:
the underlying string, not null

toCharArray

public char[] toCharArray()
Gets the elements of this collection as an array.

This implementation uses String.toCharArray().

Specified by:
toCharArray in interface CharCollection
Overrides:
toCharArray in class AbstractCharCollection
Returns:
a new array containing a copy of the elements of this collection, not null

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. StringCharList is unmodifiable, thus so is the view.

Specified by:
subList in interface List<Character>
Specified by:
subList in interface CharList
Overrides:
subList in class AbstractCharList
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


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