Class CircularList<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
jmt.framework.data.CircularList<E>
- All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess, SequencedCollection<E>
public class CircularList<E>
extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable, Serializable
Name: CircularList
Description:
A random access circular list based on an array, optimized for speed in append and remove
operations in the head or tail of the list.
The array is able to grow when internal capacity is finished, with an O(n) complexity.
CircularQueue is optimized to have O(1) complexity on each get operation and in add and remove operations
at the beginning and at the end of the list. Other operations are O(n). This implementation is good for
unordered, unbounded LIFO/FIFO queues.
Date: 10/giu/2009 Time: 19:22:03
- Version:
- 1.0
- Author:
- Bertoli Marco
- See Also:
-
Field Summary
Fields inherited from class AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionBuilds a new Circual list, using the default sizeCircularList(int initialSize) Builds a new CircularList with the given initial size -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanbooleanaddAll(int index, Collection<? extends E> c) voidAdds an object at the beginning of the listvoidAdds an object to the end of the list.voidclear()clone()get(int index) getFirst()Returns the first.getLast()Returns the last.intintremove(int index) Removes the first element of the list and returns it.Removes the last element of the list and returns itprotected voidremoveRange(int fromIndex, int toIndex) intsize()Methods inherited from class AbstractList
equals, hashCode, iterator, listIterator, listIterator, subListMethods inherited from class AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface List
addAll, contains, containsAll, equals, hashCode, isEmpty, iterator, listIterator, listIterator, remove, removeAll, replaceAll, retainAll, reversed, sort, spliterator, subList, toArray, toArray
-
Constructor Details
-
CircularList
public CircularList()Builds a new Circual list, using the default size -
CircularList
public CircularList(int initialSize) Builds a new CircularList with the given initial size- Parameters:
initialSize- the initial size
-
-
Method Details
-
size
public int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceList<E>- Specified by:
sizein classAbstractCollection<E>
-
add
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceList<E>- Overrides:
addin classAbstractList<E>
-
addFirst
-
addLast
-
addAll
-
clear
public void clear()- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceList<E>- Overrides:
clearin classAbstractList<E>
-
clone
-
get
-
getFirst
Returns the first.- Specified by:
getFirstin interfaceList<E>- Specified by:
getFirstin interfaceSequencedCollection<E>- Returns:
- the first element of the list
- Throws:
IllegalArgumentException- if the list is empty
-
getLast
Returns the last.- Specified by:
getLastin interfaceList<E>- Specified by:
getLastin interfaceSequencedCollection<E>- Returns:
- the last element of the list
- Throws:
IllegalArgumentException- if the list is empty
-
add
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOfin interfaceList<E>- Overrides:
lastIndexOfin classAbstractList<E>
-
remove
-
removeFirst
Removes the first element of the list and returns it.- Specified by:
removeFirstin interfaceList<E>- Specified by:
removeFirstin interfaceSequencedCollection<E>- Returns:
- the first element of the list
- Throws:
IndexOutOfBoundsException- if size is zero
-
removeLast
Removes the last element of the list and returns it- Specified by:
removeLastin interfaceList<E>- Specified by:
removeLastin interfaceSequencedCollection<E>- Returns:
- the last element of the list
- Throws:
IndexOutOfBoundsException- if size is zero
-
removeRange
protected void removeRange(int fromIndex, int toIndex) - Overrides:
removeRangein classAbstractList<E>
-
set
-