org.apache.commons.collections.primitives.adapters
Class ListShortList

java.lang.Object
  extended by org.apache.commons.collections.primitives.adapters.ListShortList
All Implemented Interfaces:
Serializable, ShortCollection, ShortList

public class ListShortList
extends Object
implements Serializable

Adapts a Number-valued List to the ShortList interface.

This implementation delegates most methods to the provided List implementation in the "obvious" way.

Since:
Commons Primitives 1.0
Version:
$Revision: 480462 $ $Date: 2006-11-29 09:15:00 +0100(mer, 29 nov 2006) $
Author:
Rodney Waldhoff
See Also:
Serialized Form

Constructor Summary
ListShortList(List list)
          Creates an ShortList wrapping the specified List.
 
Method Summary
 void add(int index, short element)
          Inserts the specified element at the specified position (optional operation).
 boolean add(short element)
          Ensures that I contain the specified element (optional operation).
 boolean addAll(int index, ShortCollection collection)
          Inserts all of the elements in the specified collection into me, at the specified position (optional operation).
 boolean addAll(ShortCollection c)
          Adds all of the elements in the specified collection to me (optional operation).
 void clear()
          Removes all my elements (optional operation).
 boolean contains(short element)
          Returns true iff I contain the specified element.
 boolean containsAll(ShortCollection c)
          Returns true iff I contain all of the elements in the given collection.
 boolean equals(Object obj)
          Returns true iff that is an ShortList that contains the same elements in the same order as me.
 short get(int index)
          Returns the value of the element at the specified position within me.
protected  Collection getCollection()
           
protected  List getList()
           
 int hashCode()
          Returns my hash code.
 int indexOf(short element)
          Returns the index of the first occurrence of the specified element within me, or -1 if I do not contain the element.
 boolean isEmpty()
          Returns true iff I contain no elements.
 ShortIterator iterator()
          wraps the Iterator returned by my underlying Collection, if any.
 int lastIndexOf(short element)
          Returns the index of the last occurrence of the specified element within me, or -1 if I do not contain the element.
 ShortListIterator listIterator()
          wraps the ShortList returned by my underlying ShortListIterator, if any.
 ShortListIterator listIterator(int index)
          wraps the ShortList returned by my underlying ShortListIterator, if any.
 boolean removeAll(ShortCollection c)
          Removes all of my elements that are contained in the specified collection (optional operation).
 boolean removeElement(short element)
          Removes a single occurrence of the specified element (optional operation).
 short removeElementAt(int index)
          Removes the element at the specified position in (optional operation).
 boolean retainAll(ShortCollection c)
          Removes all of my elements that are not contained in the specified collection (optional operation).
 short set(int index, short element)
          Replaces the element at the specified position in me with the specified element (optional operation).
 int size()
          Returns the number of elements I contain.
 ShortList subList(int fromIndex, int toIndex)
          Returns a view of the elements within me between the specified fromIndex, inclusive, and toIndex, exclusive.
 short[] toArray()
          Returns an array containing all of my elements.
 short[] toArray(short[] dest)
          Returns an array containing all of my elements, using the given array if it is large enough.
 String toString()
           
static ShortList wrap(List list)
          Create an ShortList wrapping the specified List.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.commons.collections.primitives.ShortList
add, iterator
 
Methods inherited from interface org.apache.commons.collections.primitives.ShortCollection
addAll, clear, contains, containsAll, isEmpty, removeAll, removeElement, retainAll, size, toArray, toArray
 

Constructor Detail

ListShortList

public ListShortList(List list)
Creates an ShortList wrapping the specified List.

See Also:
wrap(java.util.List)
Method Detail

wrap

public static ShortList wrap(List list)
Create an ShortList wrapping the specified List. When the given list is null, returns null.

Parameters:
list - the (possibly null) List to wrap
Returns:
a ShortList wrapping the given list, or null when list is null.

getList

protected List getList()

add

public void add(int index,
                short element)
Description copied from interface: ShortList
Inserts the specified element at the specified position (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right, increasing their indices.

Specified by:
add in interface ShortList
Parameters:
index - the index at which to insert the element
element - the value to insert

addAll

public boolean addAll(int index,
                      ShortCollection collection)
Description copied from interface: ShortList
Inserts all of the elements in the specified collection into me, at the specified position (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right, increasing their indices. The new elements will appear in the order that they are returned by the given collection's iterator.

Specified by:
addAll in interface ShortList
Parameters:
index - the index at which to insert the first element from the specified collection
collection - the ShortCollection of elements to add
Returns:
true iff I changed as a result of this call

get

public short get(int index)
Description copied from interface: ShortList
Returns the value of the element at the specified position within me.

Specified by:
get in interface ShortList
Parameters:
index - the index of the element to return
Returns:
the value of the element at the specified position

indexOf

public int indexOf(short element)
Description copied from interface: ShortList
Returns the index of the first occurrence of the specified element within me, or -1 if I do not contain the element.

Specified by:
indexOf in interface ShortList
Parameters:
element - the element to search for
Returns:
the smallest index of an element matching the specified value, or -1 if no such matching element can be found

lastIndexOf

public int lastIndexOf(short element)
Description copied from interface: ShortList
Returns the index of the last occurrence of the specified element within me, or -1 if I do not contain the element.

Specified by:
lastIndexOf in interface ShortList
Parameters:
element - the element to search for
Returns:
the largest index of an element matching the specified value, or -1 if no such matching element can be found

listIterator

public ShortListIterator listIterator()
wraps the ShortList returned by my underlying ShortListIterator, if any.

Specified by:
listIterator in interface ShortList

listIterator

public ShortListIterator listIterator(int index)
wraps the ShortList returned by my underlying ShortListIterator, if any.

Specified by:
listIterator in interface ShortList

removeElementAt

public short removeElementAt(int index)
Description copied from interface: ShortList
Removes the element at the specified position in (optional operation). Any subsequent elements are shifted to the left, subtracting one from their indices. Returns the element that was removed.

Specified by:
removeElementAt in interface ShortList
Parameters:
index - the index of the element to remove
Returns:
the value of the element that was removed

set

public short set(int index,
                 short element)
Description copied from interface: ShortList
Replaces the element at the specified position in me with the specified element (optional operation).

Specified by:
set in interface ShortList
Parameters:
index - the index of the element to change
element - the value to be stored at the specified position
Returns:
the value previously stored at the specified position

subList

public ShortList subList(int fromIndex,
                         int toIndex)
Description copied from interface: ShortList
Returns a view of the elements within me between the specified fromIndex, inclusive, and toIndex, exclusive. The returned ShortList is backed by me, so that any changes in the returned list are reflected in me, and vice-versa. The returned list supports all of the optional operations that I support.

Note that when fromIndex == toIndex, the returned list is initially empty, and when fromIndex == 0 && toIndex == size() the returned list is my "improper" sublist, containing all my elements.

The semantics of the returned list become undefined if I am structurally modified in any way other than via the returned list.

Specified by:
subList in interface ShortList
Parameters:
fromIndex - the smallest index (inclusive) in me that appears in the returned list
toIndex - the largest index (exclusive) in me that appears in the returned list
Returns:
a view of this list from fromIndex (inclusive) to toIndex (exclusive)

equals

public boolean equals(Object obj)
Description copied from interface: ShortList
Returns true iff that is an ShortList that contains the same elements in the same order as me. In other words, returns true iff that is a ShortList that has the same size as me, and for which the elements returned by its iterator are equal (==) to the corresponding elements within me. (This contract ensures that this method works properly across different implementations of the ShortList interface.)

Specified by:
equals in interface ShortList
Overrides:
equals in class Object
Parameters:
obj - the object to compare to me
Returns:
true iff that is an ShortList that contains the same elements in the same order as me

hashCode

public int hashCode()
Description copied from interface: ShortList
Returns my hash code.

The hash code of an ShortList is defined to be the result of the following calculation:

 int hash = 1;
 for(ShortIterator iter = iterator(); iter.hasNext(); ) {
   short value = iter.next();
   hash = 31*hash + (int)(value ^ (value >>> 32));
 }

This contract ensures that this method is consistent with equals and with the hashCode method of a List of Shorts.

Specified by:
hashCode in interface ShortList
Overrides:
hashCode in class Object
Returns:
my hash code

getCollection

protected final Collection getCollection()

add

public boolean add(short element)
Description copied from interface: ShortCollection
Ensures that I contain the specified element (optional operation). Returns true iff I changed as a result of this call.

If a collection refuses to add the specified element for any reason other than that it already contains the element, it must throw an exception (rather than simply returning false). This preserves the invariant that a collection always contains the specified element after this call returns.

Specified by:
add in interface ShortCollection
Parameters:
element - the value whose presence within me is to be ensured
Returns:
true iff I changed as a result of this call

addAll

public boolean addAll(ShortCollection c)
Description copied from interface: ShortCollection
Adds all of the elements in the specified collection to me (optional operation).

Specified by:
addAll in interface ShortCollection
Parameters:
c - the collection of elements whose presence within me is to be ensured
Returns:
true iff I changed as a result of this call

clear

public void clear()
Description copied from interface: ShortCollection
Removes all my elements (optional operation). I will be empty after this method successfully returns.

Specified by:
clear in interface ShortCollection

contains

public boolean contains(short element)
Description copied from interface: ShortCollection
Returns true iff I contain the specified element.

Specified by:
contains in interface ShortCollection
Parameters:
element - the value whose presence within me is to be tested
Returns:
true iff I contain the specified element

containsAll

public boolean containsAll(ShortCollection c)
Description copied from interface: ShortCollection
Returns true iff I contain all of the elements in the given collection.

Specified by:
containsAll in interface ShortCollection
Parameters:
c - the collection of elements whose presence within me is to be tested
Returns:
true iff I contain the all the specified elements

toString

public String toString()
Overrides:
toString in class Object

isEmpty

public boolean isEmpty()
Description copied from interface: ShortCollection
Returns true iff I contain no elements.

Specified by:
isEmpty in interface ShortCollection
Returns:
true iff I contain no elements.

iterator

public ShortIterator iterator()
wraps the Iterator returned by my underlying Collection, if any.

Specified by:
iterator in interface ShortCollection
Returns:
an iterator over all my elements.

removeElement

public boolean removeElement(short element)
Description copied from interface: ShortCollection
Removes a single occurrence of the specified element (optional operation).

Specified by:
removeElement in interface ShortCollection
Parameters:
element - the element to remove, if present
Returns:
true iff I contained the specified element, in other words, iff I changed as a result of this call

removeAll

public boolean removeAll(ShortCollection c)
Description copied from interface: ShortCollection
Removes all of my elements that are contained in the specified collection (optional operation). The behavior of this method is unspecified if the given collection is modified while this method is executing. Note that this includes the case in which the given collection is this collection, and it is not empty.

Specified by:
removeAll in interface ShortCollection
Parameters:
c - the collection of elements to remove
Returns:
true iff I contained the at least one of the specified elements, in other words, returns true iff I changed as a result of this call

retainAll

public boolean retainAll(ShortCollection c)
Description copied from interface: ShortCollection
Removes all of my elements that are not contained in the specified collection (optional operation). (In other words, retains only my elements that are contained in the specified collection.) The behavior of this method is unspecified if the given collection is modified while this method is executing.

Specified by:
retainAll in interface ShortCollection
Parameters:
c - the collection of elements to retain
Returns:
true iff I changed as a result of this call

size

public int size()
Description copied from interface: ShortCollection
Returns the number of elements I contain.

Specified by:
size in interface ShortCollection
Returns:
the number of elements I contain

toArray

public short[] toArray()
Description copied from interface: ShortCollection
Returns an array containing all of my elements. The length of the returned array will be equal to my size.

The returned array will be independent of me, so that callers may modify that returned array without modifying this collection.

When I guarantee the order in which elements are returned by an iterator, the returned array will contain elements in the same order.

Specified by:
toArray in interface ShortCollection
Returns:
an array containing all my elements

toArray

public short[] toArray(short[] dest)
Description copied from interface: ShortCollection
Returns an array containing all of my elements, using the given array if it is large enough. When the length of the given array is larger than the number of elements I contain, values outside of my range will be unchanged.

The returned array will be independent of me, so that callers may modify that returned array without modifying this collection.

When I guarantee the order in which elements are returned by an iterator, the returned array will contain elements in the same order.

Specified by:
toArray in interface ShortCollection
Parameters:
dest - an array that may be used to contain the elements
Returns:
an array containing all my elements


Copyright © 2002-2011 Apache Software Foundation. All Rights Reserved.