it.unimi.dsi.fastutil.longs
Class AbstractLongList

java.lang.Object
  extended by it.unimi.dsi.fastutil.longs.AbstractLongCollection
      extended by it.unimi.dsi.fastutil.longs.AbstractLongList
All Implemented Interfaces:
LongCollection, LongIterable, LongList, LongStack, Stack<java.lang.Long>, java.lang.Comparable<java.util.List<? extends java.lang.Long>>, java.lang.Iterable<java.lang.Long>, java.util.Collection<java.lang.Long>, java.util.List<java.lang.Long>
Direct Known Subclasses:
AbstractLongList.LongSubList, LongArrayList, LongLists.Singleton

public abstract class AbstractLongList
extends AbstractLongCollection
implements LongList, LongStack

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 AbstractLongList.LongSubList
           
 
Method Summary
 void add(int index, long k)
           
 void add(int index, java.lang.Long ok)
          Delegates to the corresponding type-specific method.
 boolean add(long k)
           
 boolean addAll(java.util.Collection<? extends java.lang.Long> c)
          Delegates to a more generic method.
 boolean addAll(int index, java.util.Collection<? extends java.lang.Long> c)
           
 boolean addAll(int index, LongCollection c)
          Delegates to a more generic method.
 boolean addAll(int index, LongList l)
          Delegates to a more generic method.
 boolean addAll(LongCollection c)
          Adds all elements of the given type-specific collection to this collection.
 boolean addAll(LongList l)
           
 void addElements(int index, long[] a)
          Add (hopefully quickly) elements to this type-specific list.
 void addElements(int index, long[] a, int offset, int length)
          Adds elements to this type-specific list one-by-one.
 int compareTo(java.util.List<? extends java.lang.Long> l)
          Compares this list to another object.
 boolean contains(long k)
           
 boolean equals(java.lang.Object o)
           
 java.lang.Long get(int index)
          Delegates to the corresponding type-specific method.
 void getElements(int from, long[] 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(long k)
           
 int indexOf(java.lang.Object ok)
          Delegates to the corresponding type-specific method.
 LongIterator iterator()
          Returns a type-specific iterator on the elements of this collection.
 int lastIndexOf(long k)
           
 int lastIndexOf(java.lang.Object ok)
          Delegates to the corresponding type-specific method.
 LongListIterator listIterator()
          Returns a type-specific list iterator on the list.
 LongListIterator listIterator(int index)
          Returns a type-specific list iterator on the list starting at a given index.
 LongListIterator longListIterator()
          Deprecated. 
 LongListIterator longListIterator(int index)
          Deprecated. 
 LongList longSubList(int from, int to)
          Deprecated. 
 java.lang.Long peek(int i)
          Delegates to the corresponding type-specific method.
 long peekLong(int i)
           
 java.lang.Long pop()
          Delegates to the corresponding type-specific method.
 long popLong()
           
 void push(long o)
           
 void push(java.lang.Long o)
          Delegates to the corresponding type-specific method.
 boolean rem(long 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.
 java.lang.Long remove(int index)
          Delegates to the corresponding type-specific method.
 boolean remove(java.lang.Object o)
          Delegates to rem().
 void removeElements(int from, int to)
          Removes elements of this type-specific list one-by-one.
 long removeLong(int i)
           
 long set(int index, long k)
           
 java.lang.Long set(int index, java.lang.Long ok)
          Delegates to the corresponding type-specific method.
 void size(int size)
          Sets the size of this list.
 LongList 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.
 java.lang.Long top()
          Delegates to the corresponding type-specific method.
 long topLong()
           
 java.lang.String toString()
           
 
Methods inherited from class it.unimi.dsi.fastutil.longs.AbstractLongCollection
add, clear, contains, containsAll, containsAll, isEmpty, longIterator, rem, removeAll, removeAll, retainAll, retainAll, toArray, toArray, toArray, toLongArray, toLongArray
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface it.unimi.dsi.fastutil.longs.LongList
getLong
 
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.longs.LongCollection
containsAll, longIterator, removeAll, retainAll, toArray, toArray, toLongArray, toLongArray
 
Methods inherited from interface it.unimi.dsi.fastutil.Stack
isEmpty
 

Method Detail

add

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

add

public boolean add(long k)
Specified by:
add in interface LongCollection
Overrides:
add in class AbstractLongCollection
See Also:
Collection.add(Object)

removeLong

public long removeLong(int i)
Specified by:
removeLong in interface LongList
See Also:
List.remove(int)

set

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

addAll

public boolean addAll(int index,
                      java.util.Collection<? extends java.lang.Long> c)
Specified by:
addAll in interface java.util.List<java.lang.Long>

addAll

public boolean addAll(java.util.Collection<? extends java.lang.Long> c)
Delegates to a more generic method.

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

longListIterator

@Deprecated
public LongListIterator longListIterator()
Deprecated. 

Delegates to the new covariantly stronger generic method.

Specified by:
longListIterator in interface LongList
See Also:
LongList.listIterator()

longListIterator

@Deprecated
public LongListIterator longListIterator(int index)
Deprecated. 

Delegates to the new covariantly stronger generic method.

Specified by:
longListIterator in interface LongList
See Also:
LongList.listIterator(int)

iterator

public LongIterator iterator()
Description copied from interface: LongCollection
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 LongCollection
Specified by:
iterator in interface LongIterable
Specified by:
iterator in interface LongList
Specified by:
iterator in interface java.lang.Iterable<java.lang.Long>
Specified by:
iterator in interface java.util.Collection<java.lang.Long>
Specified by:
iterator in interface java.util.List<java.lang.Long>
Specified by:
iterator in class AbstractLongCollection
Returns:
a type-specific iterator on the elements of this collection.

listIterator

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

Specified by:
listIterator in interface LongList
Specified by:
listIterator in interface java.util.List<java.lang.Long>
See Also:
LongList.listIterator()

listIterator

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

Specified by:
listIterator in interface LongList
Specified by:
listIterator in interface java.util.List<java.lang.Long>
See Also:
LongList.listIterator(int)

contains

public boolean contains(long k)
Specified by:
contains in interface LongCollection
See Also:
Collection.contains(Object)

indexOf

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

lastIndexOf

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

size

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

subList

public LongList subList(int from,
                        int to)
Description copied from interface: LongList
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 LongList
Specified by:
subList in interface java.util.List<java.lang.Long>
See Also:
List.subList(int,int)

longSubList

@Deprecated
public LongList longSubList(int from,
                                       int to)
Deprecated. 

Delegates to the new covariantly stronger generic method.

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

addElements

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

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

getElements

public void getElements(int from,
                        long[] 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 LongList
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(java.lang.Object o)
Specified by:
equals in interface java.util.Collection<java.lang.Long>
Specified by:
equals in interface java.util.List<java.lang.Long>
Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(java.util.List<? extends java.lang.Long> 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 java.lang.Comparable<java.util.List<? extends java.lang.Long>>
Parameters:
l - an 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:
java.lang.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 java.util.Collection<java.lang.Long>
Specified by:
hashCode in interface java.util.List<java.lang.Long>
Overrides:
hashCode in class java.lang.Object
Returns:
the hash code for this list.

push

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

popLong

public long popLong()
Specified by:
popLong in interface LongStack
See Also:
Stack.pop()

topLong

public long topLong()
Specified by:
topLong in interface LongStack
See Also:
Stack.top()

peekLong

public long peekLong(int i)
Specified by:
peekLong in interface LongStack
See Also:
Stack.peek(int)

rem

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

remove

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

Specified by:
remove in interface java.util.Collection<java.lang.Long>
Specified by:
remove in interface java.util.List<java.lang.Long>
Overrides:
remove in class AbstractLongCollection

addAll

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

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

addAll

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

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

addAll

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

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

add

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

Specified by:
add in interface java.util.List<java.lang.Long>

set

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

Specified by:
set in interface java.util.List<java.lang.Long>

get

public java.lang.Long get(int index)
Delegates to the corresponding type-specific method.

Specified by:
get in interface java.util.List<java.lang.Long>

indexOf

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

Specified by:
indexOf in interface java.util.List<java.lang.Long>

lastIndexOf

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

Specified by:
lastIndexOf in interface java.util.List<java.lang.Long>

remove

public java.lang.Long remove(int index)
Delegates to the corresponding type-specific method.

Specified by:
remove in interface java.util.List<java.lang.Long>

push

public void push(java.lang.Long o)
Delegates to the corresponding type-specific method.

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

pop

public java.lang.Long pop()
Delegates to the corresponding type-specific method.

Specified by:
pop in interface Stack<java.lang.Long>
Returns:
the top of the stack.

top

public java.lang.Long top()
Delegates to the corresponding type-specific method.

Specified by:
top in interface Stack<java.lang.Long>
Returns:
the top of the stack.

peek

public java.lang.Long peek(int i)
Delegates to the corresponding type-specific method.

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

toString

public java.lang.String toString()
Overrides:
toString in class AbstractLongCollection