org.joda.primitives.collection.impl
Class ArrayCharCollection

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.collection.impl.ArrayCharCollection
All Implemented Interfaces:
Cloneable, Iterable<Character>, Collection<Character>, CharCollection, PrimitiveCollection<Character>, CharIterable, PrimitiveCollectable<Character>

public class ArrayCharCollection
extends AbstractCharCollection
implements Cloneable

Array based implementation of CharCollection for primitive char elements.

This collection implementation allows multiple copies of the same value to be added. Internally, it uses an array, and behaves much like a list.

This class implements Collection allowing seamless integration with other APIs.

Add, Remove and Clear are supported.

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

Nested Class Summary
protected static class ArrayCharCollection.PIterator
          Iterator.
 
Constructor Summary
ArrayCharCollection()
          Constructor.
ArrayCharCollection(char[] values)
          Constructor that copies the specified values.
ArrayCharCollection(Collection<?> coll)
          Constructs a new collection by copying values from another collection.
ArrayCharCollection(int initialSize)
          Constructor that defines an initial size for the internal storage array.
ArrayCharCollection(Iterator<Character> it)
          Constructs a new collection by copying values from an iterator.
 
Method Summary
 boolean add(char value)
          Adds a primitive value to this collection.
 boolean addAll(char[] values)
          Adds an array of primitive values to this collection.
 boolean addAll(char startInclusive, char endInclusive)
          Adds a range of primitive values to this collection.
 boolean addAll(CharCollection values)
          Adds a collection of primitive values to this collection.
protected  void arrayCopy(int fromIndex, char[] dest, int destIndex, int size)
          Copies data from this collection into the specified array.
 void clear()
          Clears the collection of all elements.
 Object clone()
          Clone implementation that calls Object clone().
 boolean contains(char value)
          Checks whether this collection contains a specified primitive value.
protected  boolean doAdd(int index, char[] values)
          Internal implementation to add to this collection at the specified index.
protected  void doRemoveIndex(int index)
          Internal implementation to remove the element at the specified index.
protected  void ensureCapacity(int reqCapacity)
          Internal implementation to ensure that the internal storage array has at least the specified size.
protected  boolean isAddModifiable()
          Are the add methods supported.
 boolean isModifiable()
          Checks whether the object can currently be modified.
protected  boolean isRemoveModifiable()
          Are the remove methods supported.
 CharIterator iterator()
          Gets an iterator over this collection capable of accessing the primitive values.
 void optimize()
          Optimizes the implementation.
 int size()
          Gets the current size of the collection.
 
Methods inherited from class org.joda.primitives.collection.impl.AbstractCharCollection
add, 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
isEmpty
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.joda.primitives.PrimitiveCollectable
isEmpty
 
Methods inherited from interface java.util.Collection
equals, hashCode, isEmpty
 

Constructor Detail

ArrayCharCollection

public ArrayCharCollection()
Constructor.


ArrayCharCollection

public ArrayCharCollection(int initialSize)
Constructor that defines an initial size for the internal storage array.

Parameters:
initialSize - the initial size of the internal array, negative treated as zero

ArrayCharCollection

public ArrayCharCollection(char[] values)
Constructor that copies the specified values.

Parameters:
values - an array of values to copy, null treated as zero size array

ArrayCharCollection

public ArrayCharCollection(Collection<?> coll)
Constructs a new collection by copying values from another collection.

Parameters:
coll - a collection of values to copy, null treated as zero size collection

ArrayCharCollection

public ArrayCharCollection(Iterator<Character> it)
Constructs a new collection by copying values from an iterator.

Parameters:
it - an iterator of values to extract, null treated as zero size collection
Method Detail

size

public int size()
Gets the current size of the collection.

Specified by:
size in interface Collection<Character>
Specified by:
size in interface PrimitiveCollectable<Character>
Returns:
the current size

iterator

public CharIterator iterator()
Gets an iterator over this collection capable of accessing the primitive values.

Specified by:
iterator in interface Iterable<Character>
Specified by:
iterator in interface Collection<Character>
Specified by:
iterator in interface CharCollection
Specified by:
iterator in interface CharIterable
Returns:
an iterator over this collection

add

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

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

optimize

public void optimize()
Optimizes the implementation.

This implementation changes the internal array to be the same size as the size of the collection.

Specified by:
optimize in interface PrimitiveCollectable<Character>
Overrides:
optimize in class AbstractPrimitiveCollectable<Character>

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

isModifiable

public boolean isModifiable()
Checks whether the object can currently be modified.

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

contains

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

This implementation uses the internal array directly.

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

clear

public void clear()
Clears the collection of all elements. The collection will have a zero size after this method completes.

This implementation resets the size, but does not reduce the internal storage array.

Specified by:
clear in interface Collection<Character>
Specified by:
clear in interface PrimitiveCollectable<Character>
Overrides:
clear in class AbstractCharCollection

addAll

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

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

addAll

public boolean addAll(CharCollection values)
Adds a collection of primitive values to this collection.

Specified by:
addAll in interface CharCollection
Overrides:
addAll in class AbstractCharCollection
Parameters:
values - the values to add to this collection, null treated as empty collection
Returns:
true if this collection was modified by this method call

addAll

public boolean addAll(char startInclusive,
                      char endInclusive)
Adds a range of primitive values to this collection.

The range is defined to be inclusive of the start and end. If the start is greater than the end then the range is equivalent to an empty collection.

Specified by:
addAll in interface CharCollection
Overrides:
addAll in class AbstractCharCollection
Parameters:
startInclusive - the inclusive range start value
endInclusive - the inclusive range end value
Returns:
true if this collection was modified by this method call
Throws:
IllegalArgumentException - if a value is rejected by this set
UnsupportedOperationException - if not supported by this set

clone

public Object clone()
Clone implementation that calls Object clone().

Specified by:
clone in interface PrimitiveCollectable<Character>
Overrides:
clone in class AbstractPrimitiveCollectable<Character>
Returns:
the clone

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

doAdd

protected boolean doAdd(int index,
                        char[] values)
Internal implementation to add to this collection at the specified index. This method adjusts the capacity and size.

Parameters:
index - the index to add at, valid
values - the array to add, not null
Returns:
true if the array was updated

doRemoveIndex

protected void doRemoveIndex(int index)
Internal implementation to remove the element at the specified index.

Parameters:
index - the index, valid

ensureCapacity

protected void ensureCapacity(int reqCapacity)
Internal implementation to ensure that the internal storage array has at least the specified size.

Parameters:
reqCapacity - the amount to expand to


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