org.joda.primitives.collection.impl
Class AbstractBooleanCollection

java.lang.Object
  extended by org.joda.primitives.collection.impl.AbstractPrimitiveCollectable<Boolean>
      extended by org.joda.primitives.collection.impl.AbstractBooleanCollection
All Implemented Interfaces:
Iterable<Boolean>, Collection<Boolean>, BooleanCollection, PrimitiveCollection<Boolean>, BooleanIterable, PrimitiveCollectable<Boolean>
Direct Known Subclasses:
AbstractBooleanList, ArrayBooleanCollection

public abstract class AbstractBooleanCollection
extends AbstractPrimitiveCollectable<Boolean>
implements BooleanCollection

Abstract base class for collections of primitive boolean elements.

This class implements Collection allowing seamless integration with other APIs.

The iterator and size must be implemented by subclases. To make the subclass modifiable, the add(boolean) and iterator remove() methods must also be implemented. Subclasses may override other methods to increase efficiency.

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

Constructor Summary
protected AbstractBooleanCollection()
          Constructor.
 
Method Summary
 boolean add(boolean value)
          Adds a primitive value to this collection (optional operation).
 boolean add(Boolean value)
          Adds the Boolean value to this collection (optional operation).
 boolean addAll(boolean[] values)
          Adds an array of primitive values to this collection (optional operation).
 boolean addAll(BooleanCollection values)
          Adds a collection of primitive values to this collection (optional operation).
 boolean addAll(Collection<? extends Boolean> coll)
          Adds a collection of Boolean values to this collection (optional operation).
protected  void arrayCopy(int fromIndex, boolean[] dest, int destIndex, int size)
          Copies data from this collection into the specified array.
protected  void checkAddModifiable()
          Check whether add is suported and throw an exception.
protected  void checkRemoveModifiable()
          Check whether remove is suported and throw an exception.
 void clear()
          Clears the collection/map of all elements (optional operation).
 boolean contains(boolean value)
          Checks whether this collection contains a specified primitive value.
 boolean contains(Object value)
          Checks whether this collection contains a specified Boolean value.
 boolean containsAll(boolean[] values)
          Checks if this collection contains all of the values in the specified array.
 boolean containsAll(BooleanCollection values)
          Checks if this collection contains all of the values in the specified collection.
 boolean containsAll(Collection<?> coll)
          Checks if the collection contains all of the primitive values.
 boolean containsAny(boolean[] values)
          Checks if this collection contains any of the values in the specified array.
 boolean containsAny(BooleanCollection values)
          Checks if this collection contains any of the values in the specified collection.
 boolean containsAny(Collection<?> coll)
          Checks if the collection contains any of the primitive values in the array.
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 isToPrimitivePossible(Object value)
          Checks if the object can be converted to a primitive successfully.
 boolean remove(Object value)
          Removes the first occurrance of the specified Boolean value from this collection (optional operation).
 boolean removeAll(boolean value)
          Removes all occurrences of the specified primitive value from this collection.
 boolean removeAll(boolean[] values)
          Removes all occurrences from this collection of each primitive in the specified array.
 boolean removeAll(BooleanCollection values)
          Removes all occurrences from this collection of each primitive in the specified collection.
 boolean removeAll(Collection<?> coll)
          Removes each of a collection of Boolean values from this collection (optional operation).
 boolean removeFirst(boolean value)
          Removes the first occurrence of the specified primitive value from this collection
 boolean retainAll(boolean[] values)
          Retains each element of this collection that is present in the specified array removing all other values.
 boolean retainAll(BooleanCollection values)
          Retains each element of this collection that is present in the specified collection removing all other values.
 boolean retainAll(Collection<?> coll)
          Retains each of a collection of Boolean values, removing other values (optional operation).
 Object[] toArray()
          Gets the collection as an array of Boolean.
<T> T[]
toArray(T[] array)
          Gets the collection as an array, using the array provided.
 boolean[] toBooleanArray()
          Gets the elements of this collection as an array.
 boolean[] toBooleanArray(boolean[] array, int startIndex)
          Copies the elements of this collection into an array at a specified position.
protected  Boolean toObject(boolean value)
          Wraps an boolean with an Object wrapper.
protected  boolean toPrimitive(Object value)
          Unwraps the Boolean to retrieve the primitive boolean.
protected  boolean[] toPrimitiveArray(Collection<?> coll)
          Unwraps a Collection to retrieve the primitive boolean.
 String toString()
          Gets a string representing this collection.
 
Methods inherited from class org.joda.primitives.collection.impl.AbstractPrimitiveCollectable
clone, isEmpty, optimize
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.joda.primitives.collection.BooleanCollection
iterator
 
Methods inherited from interface org.joda.primitives.PrimitiveCollectable
clone, isEmpty, optimize, size
 
Methods inherited from interface java.util.Collection
equals, hashCode, isEmpty, size
 

Constructor Detail

AbstractBooleanCollection

protected AbstractBooleanCollection()
Constructor.

Method Detail

contains

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

This implementation uses booleanIterator().

Specified by:
contains in interface BooleanCollection
Parameters:
value - the value to search for
Returns:
true if the value is found

containsAll

public boolean containsAll(boolean[] values)
Checks if this collection contains all of the values in the specified array. If the specified array is empty, true is returned.

This implementation uses contains(boolean).

Specified by:
containsAll in interface BooleanCollection
Parameters:
values - the values to search for, null treated as empty array
Returns:
true if all of the values are found

containsAll

public boolean containsAll(BooleanCollection values)
Checks if this collection contains all of the values in the specified collection. If the specified collection is empty, true is returned.

This implementation uses contains(boolean).

Specified by:
containsAll in interface BooleanCollection
Parameters:
values - the values to search for, null treated as empty collection
Returns:
true if all of the values are found

containsAny

public boolean containsAny(boolean[] values)
Checks if this collection contains any of the values in the specified array. If the specified array is empty, false is returned.

This implementation uses contains(boolean).

Specified by:
containsAny in interface BooleanCollection
Parameters:
values - the values to search for, null treated as empty array
Returns:
true if at least one of the values is found

containsAny

public boolean containsAny(BooleanCollection values)
Checks if this collection contains any of the values in the specified collection. If the specified collection is empty, false is returned.

This implementation uses contains(boolean).

Specified by:
containsAny in interface BooleanCollection
Parameters:
values - the values to search for, null treated as empty collection
Returns:
true if at least one of the values is found

toBooleanArray

public boolean[] toBooleanArray()
Gets the elements of this collection as an array.

This implementation uses arrayCopy.

Specified by:
toBooleanArray in interface BooleanCollection
Returns:
a new array containing a copy of the elements of this collection

toBooleanArray

public boolean[] toBooleanArray(boolean[] array,
                                int startIndex)
Copies the elements of this collection into an array at a specified position. Previous values in the array are overwritten.

If the array specified is null a new array is created. If the array specified is large enough, it will be modified. If the array is not large enough, a new array will be created containing the values from the specified array before the startIndex plus those from this collection.

This implementation uses arrayCopy.

Specified by:
toBooleanArray in interface BooleanCollection
Parameters:
array - the array to add the elements to, null treated as empty array
startIndex - the position in the array to start setting elements
Returns:
the array with the populated collection
Throws:
IndexOutOfBoundsException - if the index is negative

clear

public void clear()
Clears the collection/map of all elements (optional operation).

The collection/map will have a zero size after this method completes. This method is optional, throwing an UnsupportedOperationException if the collection/map cannot be cleared.

This implementation uses iterator().

Specified by:
clear in interface Collection<Boolean>
Specified by:
clear in interface PrimitiveCollectable<Boolean>
Throws:
UnsupportedOperationException - if method not supported by this collection

add

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

This implementation throws UnsupportedOperationException.

Specified by:
add in interface BooleanCollection
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
UnsupportedOperationException - if not supported by this collection

addAll

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

This implementation uses add(boolean).

Specified by:
addAll in interface BooleanCollection
Parameters:
values - the values to add to this collection, null treated as empty array
Returns:
true if this collection was modified by this method call
Throws:
IllegalArgumentException - if a value is rejected by this collection
UnsupportedOperationException - if not supported by this collection

addAll

public boolean addAll(BooleanCollection values)
Adds a collection of primitive values to this collection (optional operation).

This implementation uses add(boolean).

Specified by:
addAll in interface BooleanCollection
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
Throws:
IllegalArgumentException - if a value is rejected by this collection
UnsupportedOperationException - if not supported by this collection

removeFirst

public boolean removeFirst(boolean value)
Removes the first occurrence of the specified primitive value from this collection

This implementation uses iterator().remove().

Specified by:
removeFirst in interface BooleanCollection
Parameters:
value - the value to remove
Returns:
true if this collection was modified by this method call
Throws:
UnsupportedOperationException - if not supported by this collection

removeAll

public boolean removeAll(boolean value)
Removes all occurrences of the specified primitive value from this collection.

This implementation uses iterator().remove().

Specified by:
removeAll in interface BooleanCollection
Parameters:
value - the value to remove
Returns:
true if this collection was modified by this method call
Throws:
UnsupportedOperationException - if not supported by this collection

removeAll

public boolean removeAll(boolean[] values)
Removes all occurrences from this collection of each primitive in the specified array.

This implementation uses iterator().remove().

Specified by:
removeAll in interface BooleanCollection
Parameters:
values - the values to remove from this collection, null treated as empty array
Returns:
true if this list was modified by this method call
Throws:
UnsupportedOperationException - if not supported by this collection

removeAll

public boolean removeAll(BooleanCollection values)
Removes all occurrences from this collection of each primitive in the specified collection.

This implementation uses iterator().remove().

Specified by:
removeAll in interface BooleanCollection
Parameters:
values - the values to remove from this collection, null treated as empty collection
Returns:
true if this list was modified by this method call
Throws:
UnsupportedOperationException - if not supported by this collection

retainAll

public boolean retainAll(boolean[] values)
Retains each element of this collection that is present in the specified array removing all other values.

This implementation uses iterator().remove().

Specified by:
retainAll in interface BooleanCollection
Parameters:
values - the values to remove from this collection, null treated as empty array
Returns:
true if this list was modified by this method call
Throws:
UnsupportedOperationException - if not supported by this collection

retainAll

public boolean retainAll(BooleanCollection values)
Retains each element of this collection that is present in the specified collection removing all other values.

This implementation uses iterator().remove().

Specified by:
retainAll in interface BooleanCollection
Parameters:
values - the values to retain in this collection, null treated as empty collection
Returns:
true if this collection was modified by this method call
Throws:
UnsupportedOperationException - if not supported by this collection

contains

public boolean contains(Object value)
Checks whether this collection contains a specified Boolean value.

This implementation uses contains(boolean).

Specified by:
contains in interface Collection<Boolean>
Parameters:
value - the value to search for
Returns:
true if the value is found

containsAll

public boolean containsAll(Collection<?> coll)
Checks if the collection contains all of the primitive values.

This implementation uses containsAll(boolean[]).

Specified by:
containsAll in interface Collection<Boolean>
Parameters:
coll - the collection of values to search for
Returns:
true if all the values are found

containsAny

public boolean containsAny(Collection<?> coll)
Checks if the collection contains any of the primitive values in the array. If the specified collection is empty, false is returned.

This implementation uses containsAny(boolean[]).

Specified by:
containsAny in interface PrimitiveCollection<Boolean>
Parameters:
coll - the collection of values to search for
Returns:
true if at least one of the values is found

toArray

public Object[] toArray()
Gets the collection as an array of Boolean.

Specified by:
toArray in interface Collection<Boolean>
Returns:
an array of Boolean

toArray

public <T> T[] toArray(T[] array)
Gets the collection as an array, using the array provided.

Specified by:
toArray in interface Collection<Boolean>
Parameters:
array - the array to populate
Returns:
an array of Boolean

add

public boolean add(Boolean value)
Adds the Boolean value to this collection (optional operation).

This method is optional, throwing an UnsupportedOperationException if the collection cannot be added to.

This implementation uses add(boolean).

Specified by:
add in interface Collection<Boolean>
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
UnsupportedOperationException - if not supported by this collection

addAll

public boolean addAll(Collection<? extends Boolean> coll)
Adds a collection of Boolean values to this collection (optional operation).

This method is optional, throwing an UnsupportedOperationException if the collection cannot be added to.

This implementation uses addAll(boolean[]).

Specified by:
addAll in interface Collection<Boolean>
Parameters:
coll - the values to add to this collection
Returns:
true if this list was modified by this method call
Throws:
IndexOutOfBoundsException - if the index is invalid
ClassCastException - if any object is not Boolean
IllegalArgumentException - if value is rejected by this collection
UnsupportedOperationException - if not supported by this collection

remove

public boolean remove(Object value)
Removes the first occurrance of the specified Boolean value from this collection (optional operation).

This method is optional, throwing an UnsupportedOperationException if the collection cannot be removed from.

This implementation uses removeFirst(boolean).

Specified by:
remove in interface Collection<Boolean>
Parameters:
value - the value to remove
Returns:
true if this collection was modified by this method call
Throws:
UnsupportedOperationException - if not supported by this collection

removeAll

public boolean removeAll(Collection<?> coll)
Removes each of a collection of Boolean values from this collection (optional operation).

This method is optional, throwing an UnsupportedOperationException if the collection cannot be added to.

This implementation uses removeAll(boolean[]).

Specified by:
removeAll in interface Collection<Boolean>
Parameters:
coll - the values to remove from this collection
Returns:
true if this list was modified by this method call
Throws:
UnsupportedOperationException - if not supported by this collection

retainAll

public boolean retainAll(Collection<?> coll)
Retains each of a collection of Boolean values, removing other values (optional operation).

This method is optional, throwing an UnsupportedOperationException if the collection cannot be added to.

This implementation uses retainAll(boolean[]).

Specified by:
retainAll in interface Collection<Boolean>
Parameters:
coll - the values to retain in this collection
Returns:
true if this list was modified by this method call
Throws:
UnsupportedOperationException - if not supported by this collection

toString

public String toString()
Gets a string representing this collection.

The format used is as per Collection.

Overrides:
toString in class Object
Returns:
collection as a String

arrayCopy

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

Parameters:
fromIndex - the index to start from
dest - the destination array
destIndex - the destination start index
size - the number of items to copy

isAddModifiable

protected boolean isAddModifiable()
Are the add methods supported.

This implementation returns false.

Returns:
true if supported

isRemoveModifiable

protected boolean isRemoveModifiable()
Are the remove methods supported.

This implementation returns false.

Returns:
true if supported

isModifiable

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

Specified by:
isModifiable in interface PrimitiveCollectable<Boolean>
Overrides:
isModifiable in class AbstractPrimitiveCollectable<Boolean>
Returns:
true if supported

checkAddModifiable

protected void checkAddModifiable()
Check whether add is suported and throw an exception.


checkRemoveModifiable

protected void checkRemoveModifiable()
Check whether remove is suported and throw an exception.


toObject

protected Boolean toObject(boolean value)
Wraps an boolean with an Object wrapper.

Parameters:
value - the primitive value
Returns:
the Object wrapper

isToPrimitivePossible

protected boolean isToPrimitivePossible(Object value)
Checks if the object can be converted to a primitive successfully.

This implementation only allows non-null Boolean objects.

Parameters:
value - the Object wrapper
Returns:
true if a primitive value can be successfully extracted

toPrimitive

protected boolean toPrimitive(Object value)
Unwraps the Boolean to retrieve the primitive boolean.

This implementation only allows non-null Boolean objects.

Parameters:
value - the Object to convert to a primitive
Returns:
the primitive value
Throws:
NullPointerException - if the value is null and this is unacceptable
ClassCastException - if the object is of an unsuitable type

toPrimitiveArray

protected boolean[] toPrimitiveArray(Collection<?> coll)
Unwraps a Collection to retrieve the primitive boolean.

This implementation only allows non-null Boolean objects.

Parameters:
coll - the Collection to convert to primitives
Returns:
the primitive value
Throws:
NullPointerException - if the value is null and this is unacceptable
ClassCastException - if any object is of an unsuitable type


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