org.joda.primitives.list.impl
Class AbstractIntList

java.lang.Object
  extended by org.joda.primitives.collection.impl.AbstractPrimitiveCollectable<Integer>
      extended by org.joda.primitives.collection.impl.AbstractIntCollection
          extended by org.joda.primitives.list.impl.AbstractIntList
All Implemented Interfaces:
Iterable<Integer>, Collection<Integer>, List<Integer>, IntCollection, PrimitiveCollection<Integer>, IntIterable, IntList, PrimitiveList<Integer>, PrimitiveCollectable<Integer>
Direct Known Subclasses:
ArrayIntList, ImmutableArrayIntList

public abstract class AbstractIntList
extends AbstractIntCollection
implements IntList

Abstract base class for lists of primitive int 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, int), removeIndex(int) and set(int, int) 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 AbstractIntList.PListIterator
          List iterator.
 
Constructor Summary
protected AbstractIntList()
          Constructor.
 
Method Summary
 boolean add(int value)
          Adds a primitive value to this collection (optional operation).
 boolean add(Integer value)
          Adds the Integer value to this collection (optional operation).
 boolean add(int index, int value)
          Adds a primitive value to this list at an index (optional operation).
 void add(int index, Integer value)
          Adds the Integer value to this list at an index (optional operation).
 boolean addAll(int[] values)
          Adds an array of primitive values to this list at an index (optional operation).
 boolean addAll(int index, Collection<? extends Integer> coll)
          Adds an array of Integer values to this list at an index (optional operation).
 boolean addAll(int index, int[] values)
          Adds an array of primitive values to this list at an index (optional operation).
protected  void arrayCopy(int fromIndex, int[] 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(int 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.
 Integer first()
          Gets the first Integer value.
 int firstInt()
          Gets the first primitive value.
 Integer get(int index)
          Gets the Integer value at the specified index.
 int hashCode()
          Gets the hashCode of this list as per the contract of List.
 int indexOf(int value)
          Gets the first index of the specified primitive value.
 int indexOf(int 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 Integer value.
 int indexOf(Object value, int fromIndexInclusive)
          Gets the first index of the specified Integer value from an index.
 boolean isModifiable()
          Is the collection modifiable in any way.
protected  boolean isSetModifiable()
          Are the set methods supported.
 IntListIterator iterator()
          Gets an iterator over this list.
 Integer last()
          Gets the last Integer value.
 int lastIndexOf(int value)
          Gets the last index of the specified primitive value.
 int lastIndexOf(int 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 Integer value.
 int lastIndexOf(Object value, int fromIndexInclusive)
          Gets the first index of the specified Integer value from an index.
 int lastInt()
          Gets the last primitive value.
 IntListIterator listIterator()
          Gets a list iterator over this list.
 IntListIterator listIterator(int index)
          Gets a list iterator over this list from a start index.
 Integer remove(int index)
          Deprecated. This method should only be used when working with List and not when working with IntList - use removeIntAt(int)
 boolean removeInt(int value)
          Removes the first occurrence of a primitive value from the list (optional operation).
 int removeIntAt(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).
 int set(int index, int value)
          Sets the primitive value at a specified index.
 Integer set(int index, Integer value)
          Sets the Integer value at a specified index.
 IntList subList(int fromIndexInclusive, int toIndexExclusive)
          Gets a range view of part of this list.
 int[] toIntArray(int fromIndexInclusive, int toIndexExclusive)
          Gets a range of elements as an array.
 
Methods inherited from class org.joda.primitives.collection.impl.AbstractIntCollection
addAll, addAll, addAll, checkAddModifiable, checkRemoveModifiable, contains, containsAll, containsAll, containsAll, containsAll, containsAny, containsAny, containsAny, containsAny, isAddModifiable, isRemoveModifiable, isToPrimitivePossible, remove, removeAll, removeAll, removeAll, removeAll, removeAll, removeFirst, retainAll, retainAll, retainAll, retainAll, toArray, toArray, toIntArray, toIntArray, 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.IntList
getInt
 
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.IntCollection
addAll, addAll, containsAll, containsAll, containsAll, containsAny, containsAny, containsAny, removeAll, removeAll, removeAll, removeAll, removeFirst, retainAll, retainAll, retainAll, toIntArray, toIntArray
 
Methods inherited from interface org.joda.primitives.collection.PrimitiveCollection
containsAny
 
Methods inherited from interface org.joda.primitives.PrimitiveCollectable
clone, isEmpty, optimize, size
 

Constructor Detail

AbstractIntList

protected AbstractIntList()
Constructor.

Method Detail

iterator

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

Specified by:
iterator in interface Iterable<Integer>
Specified by:
iterator in interface Collection<Integer>
Specified by:
iterator in interface List<Integer>
Specified by:
iterator in interface IntCollection
Specified by:
iterator in interface IntIterable
Specified by:
iterator in interface IntList
Returns:
an iterator over this list, not null

listIterator

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

This implementation uses intListIterator(int).

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

listIterator

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

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

firstInt

public int firstInt()
Gets the first primitive value.

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

lastInt

public int lastInt()
Gets the last primitive value.

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

contains

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

This implementation uses getInt(int).

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

indexOf

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

This implementation uses indexof(int, int).

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

indexOf

public int indexOf(int 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 IntList
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(int value)
Gets the last index of the specified primitive value.

This implementation uses lastIndexof(int, int).

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

lastIndexOf

public int lastIndexOf(int 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 IntList
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

toIntArray

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

Specified by:
toIntArray in interface IntList
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 IntList 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<Integer>
Specified by:
subList in interface IntList
Parameters:
fromIndexInclusive - the index to start from, inclusive
toIndexExclusive - the index to end at, exclusive
Returns:
a new IntList 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<Integer>
Specified by:
clear in interface List<Integer>
Specified by:
clear in interface PrimitiveCollectable<Integer>
Overrides:
clear in class AbstractIntCollection
Throws:
UnsupportedOperationException - if method not supported by this collection

add

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

This implementation uses add(int, int).

Specified by:
add in interface IntCollection
Overrides:
add in class AbstractIntCollection
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,
                   int value)
Adds a primitive value to this list at an index (optional operation).

This implementation throws UnsupportedOperationException.

Specified by:
add in interface IntList
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(int[] values)
Adds an array of primitive values to this list at an index (optional operation).

This implementation uses addAll(int, int).

Specified by:
addAll in interface IntCollection
Overrides:
addAll in class AbstractIntCollection
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,
                      int[] 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 IntList
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

removeIntAt

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

This implementation throws UnsupportedOperationException.

Specified by:
removeIntAt in interface IntList
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

removeInt

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

This implementation uses get(int) and removeIntAt(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 removeIntAt(int).

Specified by:
removeRange in interface PrimitiveList<Integer>
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 int set(int index,
               int value)
Sets the primitive value at a specified index.

This implementation throws UnsupportedOperationException.

Specified by:
set in interface IntList
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 Integer get(int index)
Gets the Integer value at the specified index.

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

first

public Integer first()
Gets the first Integer value.

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

last

public Integer last()
Gets the last Integer value.

Specified by:
last in interface PrimitiveList<Integer>
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 Integer value.

Specified by:
indexOf in interface List<Integer>
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 Integer

indexOf

public int indexOf(Object value,
                   int fromIndexInclusive)
Gets the first index of the specified Integer 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 Integer

lastIndexOf

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

Specified by:
lastIndexOf in interface List<Integer>
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 Integer

lastIndexOf

public int lastIndexOf(Object value,
                       int fromIndexInclusive)
Gets the first index of the specified Integer 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 Integer

add

public boolean add(Integer value)
Adds the Integer 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<Integer>
Specified by:
add in interface List<Integer>
Overrides:
add in class AbstractIntCollection
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,
                Integer value)
Adds the Integer 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<Integer>
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 Integer
IllegalArgumentException - if value is rejected by this collection
UnsupportedOperationException - if not supported by this collection

addAll

public boolean addAll(int index,
                      Collection<? extends Integer> coll)
Adds an array of Integer 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<Integer>
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 Integer
IllegalArgumentException - if value is rejected by this collection
UnsupportedOperationException - if not supported by this collection

remove

public Integer remove(int index)
Deprecated. This method should only be used when working with List and not when working with IntList - use removeIntAt(int)

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

This implementation uses removeIntAt(int).

Specified by:
remove in interface List<Integer>
Specified by:
remove in interface IntList
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 Integer set(int index,
                   Integer value)
Sets the Integer value at a specified index.

This implementation uses set(int, int).

Specified by:
set in interface List<Integer>
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<Integer>
Specified by:
equals in interface List<Integer>
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<Integer>
Specified by:
hashCode in interface List<Integer>
Overrides:
hashCode in class Object
Returns:
the hash code for this list

arrayCopy

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

Overrides:
arrayCopy in class AbstractIntCollection
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<Integer>
Overrides:
isModifiable in class AbstractIntCollection
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.