it.unimi.dsi.fastutil.bytes
Class AbstractByteList

java.lang.Object
  extended by java.util.AbstractCollection<Byte>
      extended by it.unimi.dsi.fastutil.bytes.AbstractByteCollection
          extended by it.unimi.dsi.fastutil.bytes.AbstractByteList
All Implemented Interfaces:
ByteCollection, ByteIterable, ByteList, ByteStack, Stack<Byte>, Comparable<List<? extends Byte>>, Iterable<Byte>, Collection<Byte>, List<Byte>
Direct Known Subclasses:
AbstractByteList.ByteSubList, ByteArrayList, ByteLists.Singleton

public abstract class AbstractByteList
extends AbstractByteCollection
implements ByteList, ByteStack

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 AbstractByteList.ByteSubList
           
 
Constructor Summary
protected AbstractByteList()
           
 
Method Summary
 boolean add(byte k)
           
 void add(int index, byte k)
           
 void add(int index, Byte ok)
          Delegates to the corresponding type-specific method.
 boolean addAll(ByteCollection c)
          Adds all elements of the given type-specific collection to this collection.
 boolean addAll(ByteList l)
           
 boolean addAll(Collection<? extends Byte> c)
          Delegates to a more generic method.
 boolean addAll(int index, ByteCollection c)
          Delegates to a more generic method.
 boolean addAll(int index, ByteList l)
          Delegates to a more generic method.
 boolean addAll(int index, Collection<? extends Byte> c)
           
 void addElements(int index, byte[] a)
          Add (hopefully quickly) elements to this type-specific list.
 void addElements(int index, byte[] a, int offset, int length)
          Adds elements to this type-specific list one-by-one.
 ByteListIterator byteListIterator()
          Deprecated. 
 ByteListIterator byteListIterator(int index)
          Deprecated. 
 ByteList byteSubList(int from, int to)
          Deprecated. 
 int compareTo(List<? extends Byte> l)
          Compares this list to another object.
 boolean contains(byte 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)
           
 Byte get(int index)
          Delegates to the corresponding type-specific method.
 void getElements(int from, byte[] 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(byte k)
           
 int indexOf(Object ok)
          Delegates to the corresponding type-specific method.
 ByteListIterator iterator()
          Returns a type-specific iterator on the elements of this collection.
 int lastIndexOf(byte k)
           
 int lastIndexOf(Object ok)
          Delegates to the corresponding type-specific method.
 ByteListIterator listIterator()
          Returns a type-specific list iterator on the list.
 ByteListIterator listIterator(int index)
          Returns a type-specific list iterator on the list starting at a given index.
 Byte peek(int i)
          Delegates to the corresponding type-specific method.
 byte peekByte(int i)
           
 Byte pop()
          Delegates to the corresponding type-specific method.
 byte popByte()
           
 void push(byte o)
           
 void push(Byte o)
          Delegates to the corresponding type-specific method.
 boolean rem(byte 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.
 Byte remove(int index)
          Delegates to the corresponding type-specific method.
 boolean remove(Object o)
          Delegates to rem().
 byte removeByte(int i)
           
 void removeElements(int from, int to)
          Removes elements of this type-specific list one-by-one.
 byte set(int index, byte k)
           
 Byte set(int index, Byte ok)
          Delegates to the corresponding type-specific method.
 void size(int size)
          Sets the size of this list.
 ByteList 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.
 Byte top()
          Delegates to the corresponding type-specific method.
 byte topByte()
           
 String toString()
           
 
Methods inherited from class it.unimi.dsi.fastutil.bytes.AbstractByteCollection
add, byteIterator, contains, containsAll, containsAll, isEmpty, rem, removeAll, removeAll, retainAll, retainAll, toArray, toArray, toArray, toByteArray, toByteArray
 
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.bytes.ByteList
getByte
 
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.bytes.ByteCollection
byteIterator, containsAll, removeAll, retainAll, toArray, toArray, toByteArray, toByteArray
 
Methods inherited from interface it.unimi.dsi.fastutil.Stack
isEmpty
 

Constructor Detail

AbstractByteList

protected AbstractByteList()
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,
                byte k)
Specified by:
add in interface ByteList
See Also:
List.add(int,Object)

add

public boolean add(byte k)
Specified by:
add in interface ByteCollection
Specified by:
add in interface ByteList
Overrides:
add in class AbstractByteCollection
See Also:
Collection.add(Object)

removeByte

public byte removeByte(int i)
Specified by:
removeByte in interface ByteList
See Also:
List.remove(int)

set

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

addAll

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

addAll

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

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

byteListIterator

@Deprecated
public ByteListIterator byteListIterator()
Deprecated. 

Delegates to the new covariantly stronger generic method.

Specified by:
byteListIterator in interface ByteList
See Also:
ByteList.listIterator()

byteListIterator

@Deprecated
public ByteListIterator byteListIterator(int index)
Deprecated. 

Delegates to the new covariantly stronger generic method.

Specified by:
byteListIterator in interface ByteList
See Also:
ByteList.listIterator(int)

iterator

public ByteListIterator iterator()
Description copied from interface: ByteCollection
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 ByteCollection
Specified by:
iterator in interface ByteIterable
Specified by:
iterator in interface ByteList
Specified by:
iterator in interface Iterable<Byte>
Specified by:
iterator in interface Collection<Byte>
Specified by:
iterator in interface List<Byte>
Specified by:
iterator in class AbstractByteCollection
Returns:
a type-specific iterator on the elements of this collection.

listIterator

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

Specified by:
listIterator in interface ByteList
Specified by:
listIterator in interface List<Byte>
See Also:
List.listIterator()

listIterator

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

Specified by:
listIterator in interface ByteList
Specified by:
listIterator in interface List<Byte>
See Also:
List.listIterator(int)

contains

public boolean contains(byte k)
Specified by:
contains in interface ByteCollection
Overrides:
contains in class AbstractByteCollection
See Also:
Collection.contains(Object)

indexOf

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

lastIndexOf

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

size

public void size(int size)
Description copied from interface: ByteList
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 ByteList
Parameters:
size - the new size.

subList

public ByteList subList(int from,
                        int to)
Description copied from interface: ByteList
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 ByteList
Specified by:
subList in interface List<Byte>
See Also:
List.subList(int,int)

byteSubList

@Deprecated
public ByteList byteSubList(int from,
                                       int to)
Deprecated. 

Delegates to the new covariantly stronger generic method.

Specified by:
byteSubList in interface ByteList
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 ByteList
Parameters:
from - the start index (inclusive).
to - the end index (exclusive).

addElements

public void addElements(int index,
                        byte[] 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 ByteList
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,
                        byte[] a)
Description copied from interface: ByteList
Add (hopefully quickly) elements to this type-specific list.

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

getElements

public void getElements(int from,
                        byte[] 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 ByteList
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<Byte>
Specified by:
equals in interface List<Byte>
Overrides:
equals in class Object

compareTo

public int compareTo(List<? extends Byte> 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 Byte>>
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<Byte>
Specified by:
hashCode in interface List<Byte>
Overrides:
hashCode in class Object
Returns:
the hash code for this list.

push

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

popByte

public byte popByte()
Specified by:
popByte in interface ByteStack
See Also:
Stack.pop()

topByte

public byte topByte()
Specified by:
topByte in interface ByteStack
See Also:
Stack.top()

peekByte

public byte peekByte(int i)
Specified by:
peekByte in interface ByteStack
See Also:
Stack.peek(int)

rem

public boolean rem(byte k)
Description copied from interface: ByteCollection
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 ByteCollection
Overrides:
rem in class AbstractByteCollection
See Also:
Collection.remove(Object)

remove

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

Specified by:
remove in interface Collection<Byte>
Specified by:
remove in interface List<Byte>
Overrides:
remove in class AbstractByteCollection

addAll

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

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

addAll

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

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

addAll

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

Specified by:
addAll in interface ByteCollection
Overrides:
addAll in class AbstractByteCollection
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(ByteList l)
Specified by:
addAll in interface ByteList
See Also:
List.add(int,Object)

add

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

Specified by:
add in interface List<Byte>

set

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

Specified by:
set in interface List<Byte>

get

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

Specified by:
get in interface List<Byte>

indexOf

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

Specified by:
indexOf in interface List<Byte>

lastIndexOf

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

Specified by:
lastIndexOf in interface List<Byte>

remove

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

Specified by:
remove in interface List<Byte>

push

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

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

pop

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

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

top

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

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

peek

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

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

toString

public String toString()
Overrides:
toString in class AbstractByteCollection


Copyright © 2011. All Rights Reserved.