public class ArrayByteCollection extends AbstractByteCollection implements Cloneable
ByteCollection
for
primitive byte
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.
Modifier and Type | Class and Description |
---|---|
protected static class |
ArrayByteCollection.PIterator
Iterator.
|
Constructor and Description |
---|
ArrayByteCollection()
Constructor.
|
ArrayByteCollection(byte[] values)
Constructor that copies the specified values.
|
ArrayByteCollection(Collection<?> coll)
Constructs a new collection by copying values from another collection.
|
ArrayByteCollection(int initialSize)
Constructor that defines an initial size for the internal storage array.
|
ArrayByteCollection(Iterator<Byte> it)
Constructs a new collection by copying values from an iterator.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(byte value)
Adds a primitive value to this collection.
|
boolean |
addAll(byte[] values)
Adds an array of primitive values to this collection.
|
boolean |
addAll(byte startInclusive,
byte endInclusive)
Adds a range of primitive values to this collection.
|
boolean |
addAll(ByteCollection values)
Adds a collection of primitive values to this collection.
|
protected void |
arrayCopy(int fromIndex,
byte[] 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(byte value)
Checks whether this collection contains a specified primitive value.
|
protected boolean |
doAdd(int index,
byte[] 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.
|
ByteIterator |
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.
|
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, toByteArray, toByteArray, toObject, toPrimitive, toPrimitiveArray, toString
isEmpty
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
isEmpty
equals, hashCode, isEmpty
public ArrayByteCollection()
public ArrayByteCollection(int initialSize)
initialSize
- the initial size of the internal array, negative treated as zeropublic ArrayByteCollection(byte[] values)
values
- an array of values to copy, null treated as zero size arraypublic ArrayByteCollection(Collection<?> coll)
coll
- a collection of values to copy, null treated as zero size collectionpublic ArrayByteCollection(Iterator<Byte> it)
it
- an iterator of values to extract, null treated as zero size collectionpublic int size()
size
in interface Collection<Byte>
size
in interface PrimitiveCollectable<Byte>
public ByteIterator iterator()
iterator
in interface Iterable<Byte>
iterator
in interface Collection<Byte>
iterator
in interface ByteCollection
iterator
in interface ByteIterable
public boolean add(byte value)
add
in interface ByteCollection
add
in class AbstractByteCollection
value
- the value to add to this collectiontrue
if this collection was modified by this method callIllegalArgumentException
- if value is rejected by this collectionpublic void optimize()
This implementation changes the internal array to be the same size as the size of the collection.
optimize
in interface PrimitiveCollectable<Byte>
optimize
in class AbstractPrimitiveCollectable<Byte>
protected boolean isAddModifiable()
isAddModifiable
in class AbstractByteCollection
true
protected boolean isRemoveModifiable()
isRemoveModifiable
in class AbstractByteCollection
true
public boolean isModifiable()
isModifiable
in interface PrimitiveCollectable<Byte>
isModifiable
in class AbstractByteCollection
true
public boolean contains(byte value)
This implementation uses the internal array directly.
contains
in interface ByteCollection
contains
in class AbstractByteCollection
value
- the value to search fortrue
if the value is foundpublic void clear()
This implementation resets the size, but does not reduce the internal storage array.
clear
in interface Collection<Byte>
clear
in interface PrimitiveCollectable<Byte>
clear
in class AbstractByteCollection
public boolean addAll(byte[] values)
addAll
in interface ByteCollection
addAll
in class AbstractByteCollection
values
- the values to add to this collectiontrue
if this collection was modified by this method callpublic boolean addAll(ByteCollection values)
addAll
in interface ByteCollection
addAll
in class AbstractByteCollection
values
- the values to add to this collection, null treated as empty collectiontrue
if this collection was modified by this method callpublic boolean addAll(byte startInclusive, byte endInclusive)
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.
addAll
in interface ByteCollection
addAll
in class AbstractByteCollection
startInclusive
- the inclusive range start valueendInclusive
- the inclusive range end valuetrue
if this collection was modified by this method callIllegalArgumentException
- if a value is rejected by this setUnsupportedOperationException
- if not supported by this setpublic Object clone()
clone
in interface PrimitiveCollectable<Byte>
clone
in class AbstractPrimitiveCollectable<Byte>
protected void arrayCopy(int fromIndex, byte[] dest, int destIndex, int size)
arrayCopy
in class AbstractByteCollection
fromIndex
- the index to start fromdest
- the destination arraydestIndex
- the destination start indexsize
- the number of items to copyprotected boolean doAdd(int index, byte[] values)
index
- the index to add at, validvalues
- the array to add, not nullprotected void doRemoveIndex(int index)
index
- the index, validprotected void ensureCapacity(int reqCapacity)
reqCapacity
- the amount to expand toCopyright © 2005-2012 Joda.org. All Rights Reserved.