org.joda.primitives.list.impl
Class StringBufferCharList

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.StringBufferCharList
All Implemented Interfaces:
Iterable<Character>, Collection<Character>, List<Character>, CharCollection, PrimitiveCollection<Character>, CharIterable, CharList, PrimitiveList<Character>, PrimitiveCollectable<Character>

public class StringBufferCharList
extends AbstractCharList

CharList implementation that uses a StringBuffer internally.

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  StringBuffer stringBuffer
          The String being wrapped
 
Constructor Summary
  StringBufferCharList()
          Constructor that uses an empty string as the datasource.
  StringBufferCharList(CharList list)
          Constructor that copies the specified list.
  StringBufferCharList(String str)
          Constructor that copies the specified string.
protected StringBufferCharList(StringBuffer buf)
          Constructor that decorates the specified string buffer.
 
Method Summary
 boolean add(char value)
          Adds a primitive value to this collection.
 boolean add(int index, char value)
          Adds a primitive value to this list at an index.
 boolean addAll(char[] values)
          Adds an array of primitive values to this list at an index.
 boolean addAll(int index, char[] values)
          Adds an array of primitive values to this list at an index.
protected  void arrayCopy(int fromIndex, char[] dest, int destIndex, int size)
          Copies data from this collection into the specified array.
static StringBufferCharList decorate(StringBuffer buf)
          Decorates the specified string buffer with a StringBufferCharList.
 char getChar(int index)
          Gets the character at the specified index.
protected  boolean isAddModifiable()
          Are the add methods supported.
 boolean isModifiable()
          Is the collection modifiable in any way.
protected  boolean isRemoveModifiable()
          Are the remove methods supported.
protected  boolean isSetModifiable()
          Are the set methods supported.
 char removeIndex(int index)
          Removes a primitive value by index from the list.
 boolean removeRange(int fromIndexInclusive, int toIndexExclusive)
          Removes a range of values from the list.
 char set(int index, char value)
          Sets the primitive value at a specified index.
 int size()
          Gets the size of the list, which is the string length.
 String toStringContents()
          Gets the String underlying the list.
 
Methods inherited from class org.joda.primitives.list.impl.AbstractCharList
add, add, addAll, checkIndex, checkIndexExists, checkRange, checkSetModifiable, clear, contains, equals, first, firstChar, get, hashCode, indexOf, indexOf, indexOf, indexOf, iterator, last, lastChar, lastIndexOf, lastIndexOf, lastIndexOf, lastIndexOf, listIterator, listIterator, remove, removeChar, removeCharAt, set, subList, 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, 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.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, toCharArray
 
Methods inherited from interface org.joda.primitives.collection.PrimitiveCollection
containsAny
 
Methods inherited from interface org.joda.primitives.PrimitiveCollectable
clone, isEmpty, optimize
 

Field Detail

stringBuffer

protected final StringBuffer stringBuffer
The String being wrapped

Constructor Detail

StringBufferCharList

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


StringBufferCharList

public StringBufferCharList(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

StringBufferCharList

public StringBufferCharList(String str)
Constructor that copies the specified string.

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

StringBufferCharList

protected StringBufferCharList(StringBuffer buf)
Constructor that decorates the specified string buffer.

Parameters:
buf - the string buffer to decorate, must not be null
Throws:
IllegalArgumentException - if the string is null
Method Detail

decorate

public static StringBufferCharList decorate(StringBuffer buf)
Decorates the specified string buffer with a StringBufferCharList.

The specified buffer is used as the datasource, so changes to one will affect the other.

Parameters:
buf - the string buffer to decorate, must not be null
Returns:
the new StringBufferCharList
Throws:
IllegalArgumentException - if the string is null

getChar

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

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.

Returns:
the string length

add

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

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

removeIndex

public char removeIndex(int index)
Removes a primitive value by index from the list.

Parameters:
index - the index to remove from
Returns:
the primitive value previously at this index
Throws:
IndexOutOfBoundsException - if the index is invalid

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
Overrides:
set in class AbstractCharList
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

isAddModifiable

protected boolean isAddModifiable()
Are the add methods supported.

Overrides:
isAddModifiable in class AbstractCharCollection
Returns:
true

isRemoveModifiable

protected boolean isRemoveModifiable()
Are the remove methods supported.

Overrides:
isRemoveModifiable in class AbstractCharCollection
Returns:
true

isSetModifiable

protected boolean isSetModifiable()
Are the set methods supported.

Overrides:
isSetModifiable in class AbstractCharList
Returns:
true

isModifiable

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

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

add

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

Specified by:
add in interface CharCollection
Overrides:
add in class AbstractCharList
Parameters:
value - the value to add to this collection
Returns:
true if this collection was modified by this method call

addAll

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

Specified by:
addAll in interface CharCollection
Overrides:
addAll in class AbstractCharList
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

addAll

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

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

removeRange

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

Specified by:
removeRange in interface PrimitiveList<Character>
Overrides:
removeRange in class AbstractCharList
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

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

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 AbstractCharList
Parameters:
fromIndex - the index to start from
dest - the destination array
destIndex - the destination start index
size - the number of items to copy


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