org.joda.primitives.list.impl
Class AbstractLongList

java.lang.Object
  extended by org.joda.primitives.collection.impl.AbstractPrimitiveCollectable<Long>
      extended by org.joda.primitives.collection.impl.AbstractLongCollection
          extended by org.joda.primitives.list.impl.AbstractLongList
All Implemented Interfaces:
Iterable<Long>, Collection<Long>, List<Long>, LongCollection, PrimitiveCollection<Long>, LongIterable, LongList, PrimitiveList<Long>, PrimitiveCollectable<Long>
Direct Known Subclasses:
ArrayLongList, ImmutableArrayLongList

public abstract class AbstractLongList
extends AbstractLongCollection
implements LongList

Abstract base class for lists of primitive long 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, long), removeIndex(int) and set(int, long) 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 AbstractLongList.PListIterator
          List iterator.
 
Constructor Summary
protected AbstractLongList()
          Constructor.
 
Method Summary
 boolean add(int index, long value)
          Adds a primitive value to this list at an index (optional operation).
 void add(int index, Long value)
          Adds the Long value to this list at an index (optional operation).
 boolean add(long value)
          Adds a primitive value to this collection (optional operation).
 boolean add(Long value)
          Adds the Long value to this collection (optional operation).
 boolean addAll(int index, Collection<? extends Long> coll)
          Adds an array of Long values to this list at an index (optional operation).
 boolean addAll(int index, long[] values)
          Adds an array of primitive values to this list at an index (optional operation).
 boolean addAll(long[] values)
          Adds an array of primitive values to this list at an index (optional operation).
protected  void arrayCopy(int fromIndex, long[] 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(long 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.
 Long first()
          Gets the first Long value.
 long firstLong()
          Gets the first primitive value.
 Long get(int index)
          Gets the Long value at the specified index.
 int hashCode()
          Gets the hashCode of this list as per the contract of List.
 int indexOf(long value)
          Gets the first index of the specified primitive value.
 int indexOf(long 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 Long value.
 int indexOf(Object value, int fromIndexInclusive)
          Gets the first index of the specified Long value from an index.
 boolean isModifiable()
          Is the collection modifiable in any way.
protected  boolean isSetModifiable()
          Are the set methods supported.
 LongListIterator iterator()
          Gets an iterator over this list.
 Long last()
          Gets the last Long value.
 int lastIndexOf(long value)
          Gets the last index of the specified primitive value.
 int lastIndexOf(long 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 Long value.
 int lastIndexOf(Object value, int fromIndexInclusive)
          Gets the first index of the specified Long value from an index.
 long lastLong()
          Gets the last primitive value.
 LongListIterator listIterator()
          Gets a list iterator over this list.
 LongListIterator listIterator(int index)
          Gets a list iterator over this list from a start index.
 Long remove(int index)
          Deprecated. This method should only be used when working with List and not when working with LongList - use removeLongAt(int)
 boolean removeLong(long value)
          Removes the first occurrence of a primitive value from the list (optional operation).
 long removeLongAt(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).
 long set(int index, long value)
          Sets the primitive value at a specified index.
 Long set(int index, Long value)
          Sets the Long value at a specified index.
 LongList subList(int fromIndexInclusive, int toIndexExclusive)
          Gets a range view of part of this list.
 long[] toLongArray(int fromIndexInclusive, int toIndexExclusive)
          Gets a range of elements as an array.
 
Methods inherited from class org.joda.primitives.collection.impl.AbstractLongCollection
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, toLongArray, toLongArray, 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.LongList
getLong
 
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.LongCollection
addAll, addAll, containsAll, containsAll, containsAll, containsAny, containsAny, containsAny, removeAll, removeAll, removeAll, removeAll, removeFirst, retainAll, retainAll, retainAll, toLongArray, toLongArray
 
Methods inherited from interface org.joda.primitives.collection.PrimitiveCollection
containsAny
 
Methods inherited from interface org.joda.primitives.PrimitiveCollectable
clone, isEmpty, optimize, size
 

Constructor Detail

AbstractLongList

protected AbstractLongList()
Constructor.

Method Detail

iterator

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

Specified by:
iterator in interface Iterable<Long>
Specified by:
iterator in interface Collection<Long>
Specified by:
iterator in interface List<Long>
Specified by:
iterator in interface LongCollection
Specified by:
iterator in interface LongIterable
Specified by:
iterator in interface LongList
Returns:
an iterator over this list, not null

listIterator

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

This implementation uses longListIterator(int).

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

listIterator

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

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

firstLong

public long firstLong()
Gets the first primitive value.

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

lastLong

public long lastLong()
Gets the last primitive value.

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

contains

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

This implementation uses getLong(int).

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

indexOf

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

This implementation uses indexof(long, int).

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

indexOf

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

This implementation uses lastIndexof(long, int).

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

lastIndexOf

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

toLongArray

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

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

add

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

This implementation uses add(int, long).

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

This implementation throws UnsupportedOperationException.

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

This implementation uses addAll(int, long).

Specified by:
addAll in interface LongCollection
Overrides:
addAll in class AbstractLongCollection
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,
                      long[] 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 LongList
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

removeLongAt

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

This implementation throws UnsupportedOperationException.

Specified by:
removeLongAt in interface LongList
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

removeLong

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

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

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

This implementation throws UnsupportedOperationException.

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

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

first

public Long first()
Gets the first Long value.

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

last

public Long last()
Gets the last Long value.

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

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

indexOf

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

lastIndexOf

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

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

lastIndexOf

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

add

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

addAll

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

remove

public Long remove(int index)
Deprecated. This method should only be used when working with List and not when working with LongList - use removeLongAt(int)

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

This implementation uses removeLongAt(int).

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

This implementation uses set(int, long).

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

arrayCopy

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

Overrides:
arrayCopy in class AbstractLongCollection
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<Long>
Overrides:
isModifiable in class AbstractLongCollection
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.