Class AbstractReferenceList<K>
- All Implemented Interfaces:
ObjectIterable<K>,ReferenceCollection<K>,ReferenceList<K>,Stack<K>,Iterable<K>,Collection<K>,List<K>
- Direct Known Subclasses:
AbstractReferenceList.ReferenceSubList,ReferenceArrayList,ReferenceLists.Singleton
public abstract class AbstractReferenceList<K> extends AbstractReferenceCollection<K> implements ReferenceList<K>, Stack<K>
As an additional bonus, this class implements on top of the list operations a type-specific stack.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractReferenceList.ReferenceSubList<K>A class implementing a sublist view. -
Method Summary
Modifier and Type Method Description voidadd(int index, K k)booleanadd(K k)booleanaddAll(int index, Collection<? extends K> c)Adds all of the elements in the specified collection to this list (optional operation).booleanaddAll(Collection<? extends K> c)voidaddElements(int index, K[] a)Add (hopefully quickly) elements to this type-specific list.voidaddElements(int index, K[] a, int offset, int length)Add (hopefully quickly) elements to this type-specific list.voidclear()booleancontains(Object k)Returns true if this list contains the specified element.booleanequals(Object o)voidgetElements(int from, Object[] a, int offset, int length)Copies (hopefully quickly) elements of this type-specific list into the given array.inthashCode()Returns the hash code for this list, which is identical toList.hashCode().intindexOf(Object k)ObjectListIterator<K>iterator()Returns a type-specific iterator on the elements of this collection.intlastIndexOf(Object k)ObjectListIterator<K>listIterator()Returns a type-specific list iterator on the list.ObjectListIterator<K>listIterator(int index)Returns a type-specific list iterator on the list starting at a given index.Kpeek(int i)Peeks at an element on the stack (optional operation).Kpop()Pops the top off the stack.voidpush(K o)Pushes the given object on the stack.Kremove(int i)voidremoveElements(int from, int to)Removes (hopefully quickly) elements of this type-specific list.Kset(int index, K k)voidsize(int size)Sets the size of this list.ReferenceList<K>subList(int from, int to)Returns a type-specific view of the portion of this list from the indexfrom, inclusive, to the indexto, exclusive.Ktop()Peeks at the top of the stack (optional operation).StringtoString()Methods inherited from class java.util.AbstractCollection
containsAll, isEmpty, remove, removeAll, retainAll, size, toArray, toArrayMethods inherited from interface java.util.List
containsAll, get, isEmpty, remove, removeAll, replaceAll, retainAll, size, sort, spliterator, toArray, toArrayMethods inherited from interface it.unimi.dsi.fastutil.objects.ReferenceList
setElements, setElements, setElements, unstableSort
-
Method Details
-
add
This implementation always throws an
UnsupportedOperationException. -
add
This implementation delegates to the type-specific version of
List.add(int, Object).- Specified by:
addin interfaceCollection<K>- Specified by:
addin interfaceList<K>- Overrides:
addin classAbstractCollection<K>
-
remove
This implementation always throws an
UnsupportedOperationException. -
set
This implementation always throws an
UnsupportedOperationException. -
addAll
Adds all of the elements in the specified collection to this list (optional operation). -
addAll
This implementation delegates to the type-specific version of
List.addAll(int, Collection).- Specified by:
addAllin interfaceCollection<K>- Specified by:
addAllin interfaceList<K>- Overrides:
addAllin classAbstractCollection<K>
-
iterator
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 extendsCollection.This implementation delegates to
listIterator().- Specified by:
iteratorin interfaceCollection<K>- Specified by:
iteratorin interfaceIterable<K>- Specified by:
iteratorin interfaceList<K>- Specified by:
iteratorin interfaceObjectIterable<K>- Specified by:
iteratorin interfaceReferenceCollection<K>- Specified by:
iteratorin interfaceReferenceList<K>- Specified by:
iteratorin classAbstractReferenceCollection<K>- Returns:
- a type-specific iterator on the elements of this collection.
- See Also:
Iterable.iterator()
-
listIterator
Returns a type-specific list iterator on the list.This implementation delegates to
listIterator(0).- Specified by:
listIteratorin interfaceList<K>- Specified by:
listIteratorin interfaceReferenceList<K>- See Also:
List.listIterator()
-
listIterator
Returns a type-specific list iterator on the list starting at a given index.This implementation is based on the random-access methods.
- Specified by:
listIteratorin interfaceList<K>- Specified by:
listIteratorin interfaceReferenceList<K>- See Also:
List.listIterator(int)
-
contains
Returns true if this list contains the specified element.This implementation delegates to
indexOf().- Specified by:
containsin interfaceCollection<K>- Specified by:
containsin interfaceList<K>- Overrides:
containsin classAbstractCollection<K>- See Also:
List.contains(Object)
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOfin interfaceList<K>
-
size
public void size(int size)Description copied from interface:ReferenceListSets 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:
sizein interfaceReferenceList<K>- Parameters:
size- the new size.
-
subList
Description copied from interface:ReferenceListReturns a type-specific view of the portion of this list from the indexfrom, inclusive, to the indexto, exclusive.Note that this specification strengthens the one given in
List.subList(int,int).- Specified by:
subListin interfaceList<K>- Specified by:
subListin interfaceReferenceList<K>- See Also:
List.subList(int,int)
-
removeElements
public void removeElements(int from, int to)Removes (hopefully quickly) elements of this type-specific list.This is a trivial iterator-based implementation. It is expected that implementations will override this method with a more optimized version.
- Specified by:
removeElementsin interfaceReferenceList<K>- Parameters:
from- the start index (inclusive).to- the end index (exclusive).
-
addElements
Add (hopefully quickly) elements to this type-specific list.This is a trivial iterator-based implementation. It is expected that implementations will override this method with a more optimized version.
- Specified by:
addElementsin interfaceReferenceList<K>- 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
Add (hopefully quickly) elements to this type-specific list.This implementation delegates to the analogous method for array fragments.
- Specified by:
addElementsin interfaceReferenceList<K>- Parameters:
index- the index at which to add elements.a- the array containing the elements.
-
getElements
Copies (hopefully quickly) elements of this type-specific list into the given array.This is a trivial iterator-based implementation. It is expected that implementations will override this method with a more optimized version.
- Specified by:
getElementsin interfaceReferenceList<K>- 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.
-
clear
public void clear()This implementation delegates to
removeElements(int, int).- Specified by:
clearin interfaceCollection<K>- Specified by:
clearin interfaceList<K>- Overrides:
clearin classAbstractCollection<K>
-
hashCode
public int hashCode()Returns the hash code for this list, which is identical toList.hashCode(). -
equals
-
push
Description copied from interface:StackPushes the given object on the stack. -
pop
Description copied from interface:StackPops the top off the stack. -
top
Description copied from interface:StackPeeks at the top of the stack (optional operation).This default implementation returns
peek(0). -
peek
Description copied from interface:StackPeeks at an element on the stack (optional operation).This default implementation just throws an
UnsupportedOperationException. -
toString
- Overrides:
toStringin classAbstractReferenceCollection<K>
-