it.unimi.dsi.fastutil.shorts
Class AbstractShortList

java.lang.Object
  extended by java.util.AbstractCollection<Short>
      extended by it.unimi.dsi.fastutil.shorts.AbstractShortCollection
          extended by it.unimi.dsi.fastutil.shorts.AbstractShortList
All Implemented Interfaces:
ShortCollection, ShortIterable, ShortList, ShortStack, Stack<Short>, Comparable<List<? extends Short>>, Iterable<Short>, Collection<Short>, List<Short>
Direct Known Subclasses:
AbstractShortList.ShortSubList, ShortArrayList, ShortLists.Singleton

public abstract class AbstractShortList
extends AbstractShortCollection
implements ShortList, ShortStack

An abstract class providing basic methods for lists implementing a type-specific list interface.

As an additional bonus, this class implements on top of the list operations a type-specific stack.


Nested Class Summary
static class AbstractShortList.ShortSubList
           
 
Constructor Summary
protected AbstractShortList()
           
 
Method Summary
 void add(int index, short k)
           
 void add(int index, Short ok)
          Delegates to the corresponding type-specific method.
 boolean add(short k)
           
 boolean addAll(Collection<? extends Short> c)
          Delegates to a more generic method.
 boolean addAll(int index, Collection<? extends Short> c)
           
 boolean addAll(int index, ShortCollection c)
          Delegates to a more generic method.
 boolean addAll(int index, ShortList l)
          Delegates to a more generic method.
 boolean addAll(ShortCollection c)
          Adds all elements of the given type-specific collection to this collection.
 boolean addAll(ShortList l)
           
 void addElements(int index, short[] a)
          Add (hopefully quickly) elements to this type-specific list.
 void addElements(int index, short[] a, int offset, int length)
          Adds elements to this type-specific list one-by-one.
 int compareTo(List<? extends Short> l)
          Compares this list to another object.
 boolean contains(short k)
           
protected  void ensureIndex(int index)
          Ensures that the given index is nonnegative and not greater than the list size.
protected  void ensureRestrictedIndex(int index)
          Ensures that the given index is nonnegative and smaller than the list size.
 boolean equals(Object o)
           
 Short get(int index)
          Delegates to the corresponding type-specific method.
 void getElements(int from, short[] a, int offset, int length)
          Copies element of this type-specific list into the given array one-by-one.
 int hashCode()
          Returns the hash code for this list, which is identical to List.hashCode().
 int indexOf(Object ok)
          Delegates to the corresponding type-specific method.
 int indexOf(short k)
           
 ShortListIterator iterator()
          Returns a type-specific iterator on the elements of this collection.
 int lastIndexOf(Object ok)
          Delegates to the corresponding type-specific method.
 int lastIndexOf(short k)
           
 ShortListIterator listIterator()
          Returns a type-specific list iterator on the list.
 ShortListIterator listIterator(int index)
          Returns a type-specific list iterator on the list starting at a given index.
 Short peek(int i)
          Delegates to the corresponding type-specific method.
 short peekShort(int i)
           
 Short pop()
          Delegates to the corresponding type-specific method.
 short popShort()
           
 void push(short o)
           
 void push(Short o)
          Delegates to the corresponding type-specific method.
 boolean rem(short k)
          Note that this method should be called remove(), but the clash with the similarly named index-based method in the List interface forces us to use a distinguished name.
 Short remove(int index)
          Delegates to the corresponding type-specific method.
 boolean remove(Object o)
          Delegates to rem().
 void removeElements(int from, int to)
          Removes elements of this type-specific list one-by-one.
 short removeShort(int i)
           
 short set(int index, short k)
           
 Short set(int index, Short ok)
          Delegates to the corresponding type-specific method.
 ShortListIterator shortListIterator()
          Deprecated. 
 ShortListIterator shortListIterator(int index)
          Deprecated. 
 ShortList shortSubList(int from, int to)
          Deprecated. 
 void size(int size)
          Sets the size of this list.
 ShortList subList(int from, int to)
          Returns a type-specific view of the portion of this list from the index from, inclusive, to the index to, exclusive.
 Short top()
          Delegates to the corresponding type-specific method.
 short topShort()
           
 String toString()
           
 
Methods inherited from class it.unimi.dsi.fastutil.shorts.AbstractShortCollection
add, contains, containsAll, containsAll, isEmpty, rem, removeAll, removeAll, retainAll, retainAll, shortIterator, toArray, toArray, toArray, toShortArray, toShortArray
 
Methods inherited from class java.util.AbstractCollection
clear, size
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface it.unimi.dsi.fastutil.shorts.ShortList
getShort
 
Methods inherited from interface java.util.List
add, clear, contains, containsAll, isEmpty, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from interface it.unimi.dsi.fastutil.shorts.ShortCollection
containsAll, removeAll, retainAll, shortIterator, toArray, toArray, toShortArray, toShortArray
 
Methods inherited from interface it.unimi.dsi.fastutil.Stack
isEmpty
 

Constructor Detail

AbstractShortList

protected AbstractShortList()
Method Detail

ensureIndex

protected void ensureIndex(int index)
Ensures that the given index is nonnegative and not greater than the list size.

Parameters:
index - an index.
Throws:
IndexOutOfBoundsException - if the given index is negative or greater than the list size.

ensureRestrictedIndex

protected void ensureRestrictedIndex(int index)
Ensures that the given index is nonnegative and smaller than the list size.

Parameters:
index - an index.
Throws:
IndexOutOfBoundsException - if the given index is negative or not smaller than the list size.

add

public void add(int index,
                short k)
Specified by:
add in interface ShortList
See Also:
List.add(int,Object)

add

public boolean add(short k)
Specified by:
add in interface ShortCollection
Specified by:
add in interface ShortList
Overrides:
add in class AbstractShortCollection
See Also:
Collection.add(Object)

removeShort

public short removeShort(int i)
Specified by:
removeShort in interface ShortList
See Also:
List.remove(int)

set

public short set(int index,
                 short k)
Specified by:
set in interface ShortList
See Also:
List.set(int,Object)

addAll

public boolean addAll(int index,
                      Collection<? extends Short> c)
Specified by:
addAll in interface List<Short>

addAll

public boolean addAll(Collection<? extends Short> c)
Delegates to a more generic method.

Specified by:
addAll in interface Collection<Short>
Specified by:
addAll in interface List<Short>
Overrides:
addAll in class AbstractShortCollection
Parameters:
c - a collection.
Returns:
true if this collection changed as a result of the call.

shortListIterator

@Deprecated
public ShortListIterator shortListIterator()
Deprecated. 

Delegates to the new covariantly stronger generic method.

Specified by:
shortListIterator in interface ShortList
See Also:
ShortList.listIterator()

shortListIterator

@Deprecated
public ShortListIterator shortListIterator(int index)
Deprecated. 

Delegates to the new covariantly stronger generic method.

Specified by:
shortListIterator in interface ShortList
See Also:
ShortList.listIterator(int)

iterator

public ShortListIterator iterator()
Description copied from interface: ShortCollection
Returns a type-specific iterator on the elements of this collection.

Note that this specification strengthens the one given in Iterable.iterator(), which was already strengthened in the corresponding type-specific class, but was weakened by the fact that this interface extends Collection.

Specified by:
iterator in interface ShortCollection
Specified by:
iterator in interface ShortIterable
Specified by:
iterator in interface ShortList
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 class AbstractShortCollection
Returns:
a type-specific iterator on the elements of this collection.

listIterator

public ShortListIterator listIterator()
Description copied from interface: ShortList
Returns a type-specific list iterator on the list.

Specified by:
listIterator in interface ShortList
Specified by:
listIterator in interface List<Short>
See Also:
List.listIterator()

listIterator

public ShortListIterator listIterator(int index)
Description copied from interface: ShortList
Returns a type-specific list iterator on the list starting at a given index.

Specified by:
listIterator in interface ShortList
Specified by:
listIterator in interface List<Short>
See Also:
List.listIterator(int)

contains

public boolean contains(short k)
Specified by:
contains in interface ShortCollection
Overrides:
contains in class AbstractShortCollection
See Also:
Collection.contains(Object)

indexOf

public int indexOf(short k)
Specified by:
indexOf in interface ShortList
See Also:
List.indexOf(Object)

lastIndexOf

public int lastIndexOf(short k)
Specified by:
lastIndexOf in interface ShortList
See Also:
List.lastIndexOf(Object)

size

public void size(int size)
Description copied from interface: ShortList
Sets the size of this list.

If the specified size is smaller than the current size, the last elements are discarded. Otherwise, they are filled with 0/null/false.

Specified by:
size in interface ShortList
Parameters:
size - the new size.

subList

public ShortList subList(int from,
                         int to)
Description copied from interface: ShortList
Returns a type-specific view of the portion of this list from the index from, inclusive, to the index to, exclusive.

Note that this specification strengthens the one given in List.subList(int,int).

Specified by:
subList in interface ShortList
Specified by:
subList in interface List<Short>
See Also:
List.subList(int,int)

shortSubList

@Deprecated
public ShortList shortSubList(int from,
                                         int to)
Deprecated. 

Delegates to the new covariantly stronger generic method.

Specified by:
shortSubList in interface ShortList
See Also:
List.subList(int,int)

removeElements

public void removeElements(int from,
                           int to)
Removes elements of this type-specific list one-by-one.

This is a trivial iterator-based implementation. It is expected that implementations will override this method with a more optimized version.

Specified by:
removeElements in interface ShortList
Parameters:
from - the start index (inclusive).
to - the end index (exclusive).

addElements

public void addElements(int index,
                        short[] a,
                        int offset,
                        int length)
Adds elements to this type-specific list one-by-one.

This is a trivial iterator-based implementation. It is expected that implementations will override this method with a more optimized version.

Specified by:
addElements in interface ShortList
Parameters:
index - the index at which to add elements.
a - the array containing the elements.
offset - the offset of the first element to add.
length - the number of elements to add.

addElements

public void addElements(int index,
                        short[] a)
Description copied from interface: ShortList
Add (hopefully quickly) elements to this type-specific list.

Specified by:
addElements in interface ShortList
Parameters:
index - the index at which to add elements.
a - the array containing the elements.

getElements

public void getElements(int from,
                        short[] a,
                        int offset,
                        int length)
Copies element of this type-specific list into the given array one-by-one.

This is a trivial iterator-based implementation. It is expected that implementations will override this method with a more optimized version.

Specified by:
getElements in interface ShortList
Parameters:
from - the start index (inclusive).
a - the destination array.
offset - the offset into the destination array where to store the first element copied.
length - the number of elements to be copied.

equals

public boolean equals(Object o)
Specified by:
equals in interface Collection<Short>
Specified by:
equals in interface List<Short>
Overrides:
equals in class Object

compareTo

public int compareTo(List<? extends Short> l)
Compares this list to another object. If the argument is a List, this method performs a lexicographical comparison; otherwise, it throws a ClassCastException.

Specified by:
compareTo in interface Comparable<List<? extends Short>>
Parameters:
l - a list.
Returns:
if the argument is a List, a negative integer, zero, or a positive integer as this list is lexicographically less than, equal to, or greater than the argument.
Throws:
ClassCastException - if the argument is not a list.

hashCode

public int hashCode()
Returns the hash code for this list, which is identical to List.hashCode().

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.

push

public void push(short o)
Specified by:
push in interface ShortStack
See Also:
Stack.push(Object)

popShort

public short popShort()
Specified by:
popShort in interface ShortStack
See Also:
Stack.pop()

topShort

public short topShort()
Specified by:
topShort in interface ShortStack
See Also:
Stack.top()

peekShort

public short peekShort(int i)
Specified by:
peekShort in interface ShortStack
See Also:
Stack.peek(int)

rem

public boolean rem(short k)
Description copied from interface: ShortCollection
Note that this method should be called remove(), but the clash with the similarly named index-based method in the List interface forces us to use a distinguished name. For simplicity, the set interfaces reinstates remove().

Specified by:
rem in interface ShortCollection
Overrides:
rem in class AbstractShortCollection
See Also:
Collection.remove(Object)

remove

public boolean remove(Object o)
Delegates to rem().

Specified by:
remove in interface Collection<Short>
Specified by:
remove in interface List<Short>
Overrides:
remove in class AbstractShortCollection

addAll

public boolean addAll(int index,
                      ShortCollection c)
Delegates to a more generic method.

Specified by:
addAll in interface ShortList
See Also:
List.add(int,Object)

addAll

public boolean addAll(int index,
                      ShortList l)
Delegates to a more generic method.

Specified by:
addAll in interface ShortList
See Also:
List.add(int,Object)

addAll

public boolean addAll(ShortCollection c)
Description copied from class: AbstractShortCollection
Adds all elements of the given type-specific collection to this collection.

Specified by:
addAll in interface ShortCollection
Overrides:
addAll in class AbstractShortCollection
Parameters:
c - a type-specific collection.
Returns:
true if this collection changed as a result of the call.
See Also:
Collection.addAll(Collection)

addAll

public boolean addAll(ShortList l)
Specified by:
addAll in interface ShortList
See Also:
List.add(int,Object)

add

public void add(int index,
                Short ok)
Delegates to the corresponding type-specific method.

Specified by:
add in interface List<Short>

set

public Short set(int index,
                 Short ok)
Delegates to the corresponding type-specific method.

Specified by:
set in interface List<Short>

get

public Short get(int index)
Delegates to the corresponding type-specific method.

Specified by:
get in interface List<Short>

indexOf

public int indexOf(Object ok)
Delegates to the corresponding type-specific method.

Specified by:
indexOf in interface List<Short>

lastIndexOf

public int lastIndexOf(Object ok)
Delegates to the corresponding type-specific method.

Specified by:
lastIndexOf in interface List<Short>

remove

public Short remove(int index)
Delegates to the corresponding type-specific method.

Specified by:
remove in interface List<Short>

push

public void push(Short o)
Delegates to the corresponding type-specific method.

Specified by:
push in interface Stack<Short>
Parameters:
o - the object that will become the new top of the stack.

pop

public Short pop()
Delegates to the corresponding type-specific method.

Specified by:
pop in interface Stack<Short>
Returns:
the top of the stack.

top

public Short top()
Delegates to the corresponding type-specific method.

Specified by:
top in interface Stack<Short>
Returns:
the top of the stack.

peek

public Short peek(int i)
Delegates to the corresponding type-specific method.

Specified by:
peek in interface Stack<Short>
Returns:
the i-th element on the stack; 0 represents the top.

toString

public String toString()
Overrides:
toString in class AbstractShortCollection


Copyright © 2011. All Rights Reserved.