org.joda.primitives.collection.impl
Class ArrayDoubleCollection

java.lang.Object
  extended by org.joda.primitives.collection.impl.AbstractPrimitiveCollectable<Double>
      extended by org.joda.primitives.collection.impl.AbstractDoubleCollection
          extended by org.joda.primitives.collection.impl.ArrayDoubleCollection
All Implemented Interfaces:
Cloneable, Iterable<Double>, Collection<Double>, DoubleCollection, PrimitiveCollection<Double>, DoubleIterable, PrimitiveCollectable<Double>

public class ArrayDoubleCollection
extends AbstractDoubleCollection
implements Cloneable

Array based implementation of DoubleCollection for primitive double 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 ArrayDoubleCollection.PIterator
          Iterator.
 
Constructor Summary
ArrayDoubleCollection()
          Constructor.
ArrayDoubleCollection(Collection<?> coll)
          Constructs a new collection by copying values from another collection.
ArrayDoubleCollection(double[] values)
          Constructor that copies the specified values.
ArrayDoubleCollection(int initialSize)
          Constructor that defines an initial size for the internal storage array.
ArrayDoubleCollection(Iterator<Double> it)
          Constructs a new collection by copying values from an iterator.
 
Method Summary
 boolean add(double value)
          Adds a primitive value to this collection.
 boolean addAll(double[] values)
          Adds an array of primitive values to this collection.
 boolean addAll(DoubleCollection values)
          Adds a collection of primitive values to this collection.
protected  void arrayCopy(int fromIndex, double[] 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(double value)
          Checks whether this collection contains a specified primitive value.
protected  boolean doAdd(int index, double[] 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.
 DoubleIterator 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.AbstractDoubleCollection
add, addAll, checkAddModifiable, checkRemoveModifiable, contains, containsAll, containsAll, containsAll, containsAny, containsAny, containsAny, isToPrimitivePossible, remove, removeAll, removeAll, removeAll, removeAll, removeFirst, retainAll, retainAll, retainAll, toArray, toArray, toDoubleArray, toDoubleArray, 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

ArrayDoubleCollection

public ArrayDoubleCollection()
Constructor.


ArrayDoubleCollection

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

ArrayDoubleCollection

public ArrayDoubleCollection(double[] values)
Constructor that copies the specified values.

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

ArrayDoubleCollection

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

ArrayDoubleCollection

public ArrayDoubleCollection(Iterator<Double> 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<Double>
Specified by:
size in interface PrimitiveCollectable<Double>
Returns:
the current size

iterator

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

Specified by:
iterator in interface Iterable<Double>
Specified by:
iterator in interface Collection<Double>
Specified by:
iterator in interface DoubleCollection
Specified by:
iterator in interface DoubleIterable
Returns:
an iterator over this collection

add

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

Specified by:
add in interface DoubleCollection
Overrides:
add in class AbstractDoubleCollection
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<Double>
Overrides:
optimize in class AbstractPrimitiveCollectable<Double>

isAddModifiable

protected boolean isAddModifiable()
Are the add methods supported.

Overrides:
isAddModifiable in class AbstractDoubleCollection
Returns:
true

isRemoveModifiable

protected boolean isRemoveModifiable()
Are the remove methods supported.

Overrides:
isRemoveModifiable in class AbstractDoubleCollection
Returns:
true

isModifiable

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

Specified by:
isModifiable in interface PrimitiveCollectable<Double>
Overrides:
isModifiable in class AbstractDoubleCollection
Returns:
true

contains

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

This implementation uses the internal array directly.

Specified by:
contains in interface DoubleCollection
Overrides:
contains in class AbstractDoubleCollection
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<Double>
Specified by:
clear in interface PrimitiveCollectable<Double>
Overrides:
clear in class AbstractDoubleCollection

addAll

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

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

addAll

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

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

clone

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

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

arrayCopy

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

Overrides:
arrayCopy in class AbstractDoubleCollection
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,
                        double[] 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.