public class CircularList<T> extends AbstractList<T>
modCount
Constructor and Description |
---|
CircularList(int capacity)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(T newElement)
Add an element to the list, overwriting last added element when
list's capacity is reached
|
boolean |
addAll(Collection<? extends T> newElements)
Inserts a collection of elements, looping on them.
|
void |
clear()
Removes all elements from the list.
|
T |
first()
Returns the first (inserted) element.
|
T |
get(int index)
Get element by index
|
int |
getCapacity()
Get capacity (buffer size).
|
boolean |
isEmpty()
Tells whether the list is empty
|
Iterator<T> |
iterator()
Creates a new iterator to browse elements.
|
T |
last()
Returns the last (inserted) element.
|
T |
removeFirst()
Removes the first (inserted) element of the collection.
|
int |
size()
Return the number of elements in the list
|
Object[] |
toArray() |
<T> T[] |
toArray(T[] elementsCopy) |
add, addAll, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
contains, containsAll, remove, removeAll, retainAll, toString
public CircularList(int capacity)
capacity
- Size of the ring bufferpublic int getCapacity()
public int size()
size
in interface Collection<T>
size
in interface List<T>
size
in class AbstractCollection<T>
public boolean isEmpty()
isEmpty
in interface Collection<T>
isEmpty
in interface List<T>
isEmpty
in class AbstractCollection<T>
public boolean add(T newElement)
add
in interface Collection<T>
add
in interface List<T>
add
in class AbstractList<T>
newElement
- Element to addpublic boolean addAll(Collection<? extends T> newElements)
addAll
in interface Collection<T>
addAll
in interface List<T>
addAll
in class AbstractCollection<T>
newElements
- Collection of elements to addpublic T removeFirst()
public void clear()
clear
in interface Collection<T>
clear
in interface List<T>
clear
in class AbstractList<T>
public Object[] toArray()
toArray
in interface Collection<T>
toArray
in interface List<T>
toArray
in class AbstractCollection<T>
public <T> T[] toArray(T[] elementsCopy)
toArray
in interface Collection<T>
toArray
in interface List<T>
toArray
in class AbstractCollection<T>
Copyright © 2019. All rights reserved.