org.joda.primitives.list.impl
Class AbstractBooleanList

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

public abstract class AbstractBooleanList
extends AbstractBooleanCollection
implements BooleanList

Abstract base class for lists of primitive boolean elements.

This class implements Collection allowing seamless integration with other APIs.

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

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

Nested Class Summary
protected static class AbstractBooleanList.PListIterator
          List iterator.
 
Constructor Summary
protected AbstractBooleanList()
          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 add(int index, boolean value)
          Adds a primitive value to this list at an index (optional operation).
 void add(int index, Boolean value)
          Adds the Boolean value to this list at an index (optional operation).
 boolean addAll(boolean[] values)
          Adds an array of primitive values to this list at an index (optional operation).
 boolean addAll(int index, boolean[] values)
          Adds an array of primitive values to this list at an index (optional operation).
 boolean addAll(int index, Collection<? extends Boolean> coll)
          Adds an array of Boolean values to this list at an index (optional operation).
protected  void arrayCopy(int fromIndex, boolean[] dest, int destIndex, int size)
          Copies data from this collection into the specified array.
protected  void checkIndex(int index)
          Checks whether an index is valid or not.
protected  void checkIndexExists(int index)
          Checks whether an index is valid or not.
protected  void checkRange(int fromIndexInclusive, int toIndexExclusive)
          Checks whether a range is valid or not.
protected  void checkSetModifiable()
          Check whether add is suported and throw an exception.
 void clear()
          Clears the listof all elements (optional operation).
 boolean contains(boolean value)
          Checks whether this collection contains a specified primitive value.
 boolean equals(Object obj)
          Compares this list to another as per the contract of List.
 Boolean first()
          Gets the first Boolean value.
 boolean firstBoolean()
          Gets the first primitive value.
 Boolean get(int index)
          Gets the Boolean value at the specified index.
 int hashCode()
          Gets the hashCode of this list as per the contract of List.
 int indexOf(boolean value)
          Gets the first index of the specified primitive value.
 int indexOf(boolean value, int fromIndexInclusive)
          Gets the first index of the specified primitive value from an index.
 int indexOf(Object value)
          Gets the first index of the specified Boolean value.
 int indexOf(Object value, int fromIndexInclusive)
          Gets the first index of the specified Boolean value from an index.
 boolean isModifiable()
          Is the collection modifiable in any way.
protected  boolean isSetModifiable()
          Are the set methods supported.
 BooleanListIterator iterator()
          Gets an iterator over this list.
 Boolean last()
          Gets the last Boolean value.
 boolean lastBoolean()
          Gets the last primitive value.
 int lastIndexOf(boolean value)
          Gets the last index of the specified primitive value.
 int lastIndexOf(boolean value, int fromIndexInclusive)
          Gets the first index of the specified primitive value from an index.
 int lastIndexOf(Object value)
          Gets the last index of the specified Boolean value.
 int lastIndexOf(Object value, int fromIndexInclusive)
          Gets the first index of the specified Boolean value from an index.
 BooleanListIterator listIterator()
          Gets a list iterator over this list.
 BooleanListIterator listIterator(int index)
          Gets a list iterator over this list from a start index.
 Boolean remove(int index)
          Deprecated. This method should only be used when working with List and not when working with BooleanList - use removeBooleanAt(int)
 boolean removeBoolean(boolean value)
          Removes the first occurrence of a primitive value from the list (optional operation).
 boolean removeBooleanAt(int index)
          Removes a primitive value by index from the list (optional operation).
 boolean removeRange(int fromIndexInclusive, int toIndexExclusive)
          Removes a range of values from the list (optional operation).
 boolean set(int index, boolean value)
          Sets the primitive value at a specified index.
 Boolean set(int index, Boolean value)
          Sets the Boolean value at a specified index.
 BooleanList subList(int fromIndexInclusive, int toIndexExclusive)
          Gets a range view of part of this list.
 boolean[] toBooleanArray(int fromIndexInclusive, int toIndexExclusive)
          Gets a range of elements as an array.
 
Methods inherited from class org.joda.primitives.collection.impl.AbstractBooleanCollection
addAll, addAll, checkAddModifiable, checkRemoveModifiable, contains, containsAll, containsAll, containsAll, containsAny, containsAny, containsAny, isAddModifiable, isRemoveModifiable, isToPrimitivePossible, remove, removeAll, removeAll, removeAll, removeAll, removeFirst, retainAll, retainAll, retainAll, toArray, toArray, toBooleanArray, toBooleanArray, 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.list.BooleanList
getBoolean
 
Methods inherited from interface org.joda.primitives.collection.PrimitiveCollection
containsAny
 
Methods inherited from interface org.joda.primitives.PrimitiveCollectable
clone, isEmpty, optimize, size
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from interface org.joda.primitives.collection.BooleanCollection
addAll, containsAll, containsAll, containsAny, containsAny, removeAll, removeAll, removeAll, removeFirst, retainAll, retainAll, toBooleanArray, toBooleanArray
 
Methods inherited from interface org.joda.primitives.collection.PrimitiveCollection
containsAny
 
Methods inherited from interface org.joda.primitives.PrimitiveCollectable
clone, isEmpty, optimize, size
 

Constructor Detail

AbstractBooleanList

protected AbstractBooleanList()
Constructor.

Method Detail

iterator

public BooleanListIterator iterator()
Gets an iterator over this list.

Specified by:
iterator in interface Iterable<Boolean>
Specified by:
iterator in interface Collection<Boolean>
Specified by:
iterator in interface List<Boolean>
Specified by:
iterator in interface BooleanCollection
Specified by:
iterator in interface BooleanIterable
Specified by:
iterator in interface BooleanList
Returns:
an iterator over this list, not null

listIterator

public BooleanListIterator listIterator()
Gets a list iterator over this list.

This implementation uses booleanListIterator(int).

Specified by:
listIterator in interface List<Boolean>
Specified by:
listIterator in interface BooleanList
Returns:
an iterator over this list, not null

listIterator

public BooleanListIterator listIterator(int index)
Gets a list iterator over this list from a start index.

Specified by:
listIterator in interface List<Boolean>
Specified by:
listIterator in interface BooleanList
Parameters:
index - the index to start from
Returns:
an iterator over this list, not null
Throws:
IndexOutOfBoundsException - if the index is invalid

firstBoolean

public boolean firstBoolean()
Gets the first primitive value.

Specified by:
firstBoolean in interface BooleanList
Returns:
value at index zero
Throws:
IndexOutOfBoundsException - if the size is zero

lastBoolean

public boolean lastBoolean()
Gets the last primitive value.

Specified by:
lastBoolean in interface BooleanList
Returns:
value at index size() - 1
Throws:
IndexOutOfBoundsException - if the size is zero

contains

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

This implementation uses getBoolean(int).

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

indexOf

public int indexOf(boolean value)
Gets the first index of the specified primitive value.

This implementation uses indexof(boolean, int).

Specified by:
indexOf in interface BooleanList
Parameters:
value - the value to search for
Returns:
the zero-based index, or -1 if not found

indexOf

public int indexOf(boolean value,
                   int fromIndexInclusive)
Gets the first index of the specified primitive value from an index.

This method follows the conventions of String in that a negative index is treated as zero, and an index greater than the list size will simply return -1.

This implementation uses get(int).

Specified by:
indexOf in interface BooleanList
Parameters:
value - the value to search for
fromIndexInclusive - the index to start searching from, inclusive
Returns:
the zero-based index, or -1 if not found

lastIndexOf

public int lastIndexOf(boolean value)
Gets the last index of the specified primitive value.

This implementation uses lastIndexof(boolean, int).

Specified by:
lastIndexOf in interface BooleanList
Parameters:
value - the value to search for
Returns:
the zero-based index, or -1 if not found

lastIndexOf

public int lastIndexOf(boolean value,
                       int fromIndexInclusive)
Gets the first index of the specified primitive value from an index.

This method follows the conventions of String in that an index greater than the list size will start searching at the list size, and a negative index simply returns -1.

This implementation uses get(int).

Specified by:
lastIndexOf in interface BooleanList
Parameters:
value - the value to search for
fromIndexInclusive - the index to start searching from, inclusive
Returns:
the zero-based index, or -1 if not found

toBooleanArray

public boolean[] toBooleanArray(int fromIndexInclusive,
                                int toIndexExclusive)
Gets a range of elements as an array.

Specified by:
toBooleanArray in interface BooleanList
Parameters:
fromIndexInclusive - the index to start from, inclusive
toIndexExclusive - the index to end at, exclusive
Returns:
a new array containing a copy of the range of elements, not null
Throws:
IndexOutOfBoundsException - if either index is invalid

subList

public BooleanList subList(int fromIndexInclusive,
                           int toIndexExclusive)
Gets a range view of part of this list.

This method allows operations to work on a range within the greater list. Changes made to the either object will affect the other.

Specified by:
subList in interface List<Boolean>
Specified by:
subList in interface BooleanList
Parameters:
fromIndexInclusive - the index to start from, inclusive
toIndexExclusive - the index to end at, exclusive
Returns:
a new BooleanList for the subList, not null
Throws:
IndexOutOfBoundsException - if either index is invalid

clear

public void clear()
Clears the listof all elements (optional operation).

This implementation uses removeRange(int, int).

Specified by:
clear in interface Collection<Boolean>
Specified by:
clear in interface List<Boolean>
Specified by:
clear in interface PrimitiveCollectable<Boolean>
Overrides:
clear in class AbstractBooleanCollection
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 uses add(int, boolean).

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

add

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

This implementation throws UnsupportedOperationException.

Specified by:
add in interface BooleanList
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
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 list at an index (optional operation).

This implementation uses addAll(int, boolean).

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

addAll

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

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

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

removeBooleanAt

public boolean removeBooleanAt(int index)
Removes a primitive value by index from the list (optional operation).

This implementation throws UnsupportedOperationException.

Specified by:
removeBooleanAt in interface BooleanList
Parameters:
index - the index to remove from
Returns:
the primitive value previously at this index
Throws:
IndexOutOfBoundsException - if the index is invalid
UnsupportedOperationException - if not supported by this collection

removeBoolean

public boolean removeBoolean(boolean value)
Removes the first occurrence of a primitive value from the list (optional operation).

This implementation uses get(int) and removeBooleanAt(int).

Parameters:
value - the value to remove
Returns:
the primitive value previously at this index
Throws:
UnsupportedOperationException - if not supported by this collection

removeRange

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

This implementation uses removeBooleanAt(int).

Specified by:
removeRange in interface PrimitiveList<Boolean>
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
Throws:
IndexOutOfBoundsException - if the index is invalid
UnsupportedOperationException - if remove is not supported

set

public boolean set(int index,
                   boolean value)
Sets the primitive value at a specified index.

This implementation throws UnsupportedOperationException.

Specified by:
set in interface BooleanList
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
IllegalArgumentException - if value is rejected by this collection
UnsupportedOperationException - if not supported by this collection

get

public Boolean get(int index)
Gets the Boolean value at the specified index.

Specified by:
get in interface List<Boolean>
Parameters:
index - the index to get from
Returns:
value at the index
Throws:
IndexOutOfBoundsException - if the index is invalid

first

public Boolean first()
Gets the first Boolean value.

Specified by:
first in interface PrimitiveList<Boolean>
Returns:
value at index zero or null if the size is zero

last

public Boolean last()
Gets the last Boolean value.

Specified by:
last in interface PrimitiveList<Boolean>
Returns:
value at index size() - 1 or null if the size is zero

indexOf

public int indexOf(Object value)
Gets the first index of the specified Boolean value.

Specified by:
indexOf in interface List<Boolean>
Parameters:
value - the value to search for
Returns:
the zero-based index, or -1 if not found
Throws:
NullPointerException - if the value if null
ClassCastException - if the object is not Boolean

indexOf

public int indexOf(Object value,
                   int fromIndexInclusive)
Gets the first index of the specified Boolean value from an index.

This method follows the conventions of String in that a negative index is treated as zero, and an index greater than the list size will simply return -1.

Parameters:
value - the value to search for
fromIndexInclusive - the index to start searching from, inclusive
Returns:
the zero-based index, or -1 if not found
Throws:
NullPointerException - if the value if null
ClassCastException - if the object is not Boolean

lastIndexOf

public int lastIndexOf(Object value)
Gets the last index of the specified Boolean value.

Specified by:
lastIndexOf in interface List<Boolean>
Parameters:
value - the value to search for
Returns:
the zero-based index, or -1 if not found
Throws:
NullPointerException - if the value if null
ClassCastException - if the object is not Boolean

lastIndexOf

public int lastIndexOf(Object value,
                       int fromIndexInclusive)
Gets the first index of the specified Boolean value from an index.

This method follows the conventions of String in that an index greater than the list size will start searching at the list size, and a negative index simply returns -1.

Parameters:
value - the value to search for
fromIndexInclusive - the index to start searching from, inclusive
Returns:
the zero-based index, or -1 if not found
Throws:
NullPointerException - if the value if null
ClassCastException - if the object is not 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.

Specified by:
add in interface Collection<Boolean>
Specified by:
add in interface List<Boolean>
Overrides:
add in class AbstractBooleanCollection
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

add

public void add(int index,
                Boolean value)
Adds the Boolean value to this list at an index (optional operation).

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

Specified by:
add in interface List<Boolean>
Parameters:
index - the index to add at
value - the value to add to this collection
Throws:
IndexOutOfBoundsException - if the index is invalid
ClassCastException - if the object is not Boolean
IllegalArgumentException - if value is rejected by this collection
UnsupportedOperationException - if not supported by this collection

addAll

public boolean addAll(int index,
                      Collection<? extends Boolean> coll)
Adds an array of Boolean values to this list at an index (optional operation).

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

Specified by:
addAll in interface List<Boolean>
Parameters:
index - the index to add at
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(int index)
Deprecated. This method should only be used when working with List and not when working with BooleanList - use removeBooleanAt(int)

Removes a primitive value by index from the list (optional operation).

This implementation uses removeBooleanAt(int).

Specified by:
remove in interface List<Boolean>
Specified by:
remove in interface BooleanList
Parameters:
index - the index to remove from
Returns:
the primitive value previously at this index
Throws:
IndexOutOfBoundsException - if the index is invalid
UnsupportedOperationException - if not supported by this collection

set

public Boolean set(int index,
                   Boolean value)
Sets the Boolean value at a specified index.

This implementation uses set(int, boolean).

Specified by:
set in interface List<Boolean>
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
IllegalArgumentException - if value is rejected by this collection
UnsupportedOperationException - if not supported by this collection

equals

public boolean equals(Object obj)
Compares this list to another as per the contract of List.

Specified by:
equals in interface Collection<Boolean>
Specified by:
equals in interface List<Boolean>
Overrides:
equals in class Object
Parameters:
obj - the object to compare to
Returns:
true if the lists are equal

hashCode

public int hashCode()
Gets the hashCode of this list as per the contract of List.

Specified by:
hashCode in interface Collection<Boolean>
Specified by:
hashCode in interface List<Boolean>
Overrides:
hashCode in class Object
Returns:
the hash code for this list

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.

Overrides:
arrayCopy in class AbstractBooleanCollection
Parameters:
fromIndex - the index to start from
dest - the destination array
destIndex - the destination start index
size - the number of items to copy

isSetModifiable

protected boolean isSetModifiable()
Are the set 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 AbstractBooleanCollection
Returns:
true if supported

checkSetModifiable

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


checkIndexExists

protected void checkIndexExists(int index)
Checks whether an index is valid or not.

Parameters:
index - the index to check
Throws:
IndexOutOfBoundsException - if either index is invalid

checkIndex

protected void checkIndex(int index)
Checks whether an index is valid or not.

Parameters:
index - the index to check
Throws:
IndexOutOfBoundsException - if either index is invalid

checkRange

protected void checkRange(int fromIndexInclusive,
                          int toIndexExclusive)
Checks whether a range is valid or not.

Parameters:
fromIndexInclusive - the index to start from, inclusive
toIndexExclusive - the index to end at, exclusive
Throws:
IndexOutOfBoundsException - if either index is invalid


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