org.joda.primitives.list.impl
Class AbstractShortList

java.lang.Object
  extended by org.joda.primitives.collection.impl.AbstractPrimitiveCollectable<Short>
      extended by org.joda.primitives.collection.impl.AbstractShortCollection
          extended by org.joda.primitives.list.impl.AbstractShortList
All Implemented Interfaces:
Iterable<Short>, Collection<Short>, List<Short>, PrimitiveCollection<Short>, ShortCollection, ShortIterable, PrimitiveList<Short>, ShortList, PrimitiveCollectable<Short>
Direct Known Subclasses:
ArrayShortList, ImmutableArrayShortList

public abstract class AbstractShortList
extends AbstractShortCollection
implements ShortList

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

Constructor Detail

AbstractShortList

protected AbstractShortList()
Constructor.

Method Detail

iterator

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

Specified by:
iterator in interface Iterable<Short>
Specified by:
iterator in interface Collection<Short>
Specified by:
iterator in interface List<Short>
Specified by:
iterator in interface ShortCollection
Specified by:
iterator in interface ShortIterable
Specified by:
iterator in interface ShortList
Returns:
an iterator over this list, not null

listIterator

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

This implementation uses shortListIterator(int).

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

listIterator

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

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

firstShort

public short firstShort()
Gets the first primitive value.

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

lastShort

public short lastShort()
Gets the last primitive value.

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

contains

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

This implementation uses getShort(int).

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

indexOf

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

This implementation uses indexof(short, int).

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

indexOf

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

This implementation uses lastIndexof(short, int).

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

lastIndexOf

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

toShortArray

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

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

add

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

This implementation uses add(int, short).

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

This implementation throws UnsupportedOperationException.

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

This implementation uses addAll(int, short).

Specified by:
addAll in interface ShortCollection
Overrides:
addAll in class AbstractShortCollection
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,
                      short[] 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 ShortList
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

removeShortAt

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

This implementation throws UnsupportedOperationException.

Specified by:
removeShortAt in interface ShortList
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

removeShort

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

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

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

This implementation throws UnsupportedOperationException.

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

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

first

public Short first()
Gets the first Short value.

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

last

public Short last()
Gets the last Short value.

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

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

indexOf

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

lastIndexOf

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

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

lastIndexOf

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

add

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

addAll

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

remove

public Short remove(int index)
Deprecated. This method should only be used when working with List and not when working with ShortList - use removeShortAt(int)

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

This implementation uses removeShortAt(int).

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

This implementation uses set(int, short).

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

arrayCopy

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

Overrides:
arrayCopy in class AbstractShortCollection
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<Short>
Overrides:
isModifiable in class AbstractShortCollection
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.