E
- the element to record in this listclass EventLogManagerModel.MostRecentElementList<E> extends LinkedList<E>
LinkedList
class, implements a specific
linked list that has a limited size, avoids duplicates and has a LIFO behaviour.
The maximum size of the list is specified during the object creation, using the
constructor parameter. Then, the new method addNewElement(Object)
added to the standard ones can be used to ensure the limit size of the list, avoid duplicates
and implements a LIFO behaviour.
This method does tree basic steps: first of all, if the E
element that
we try to add is already inside the list, it deletes it (this avoids duplicates). Then it
adds the element on top of the list (this implements the LIFO behaviour, because iterating
the list will give as first element the last item inserted, and so on). At the end, if this
add has made the list exceed the maximum defined size, the method deletes the oldest element of
the list (this ensure that the limit size capacity is respected and that only the n most recent
elements are kept in the list).
Modifier and Type | Field and Description |
---|---|
(package private) int |
maxSize
The maximum size of the list.
|
private static long |
serialVersionUID
Auto-Generated Serial Version UID for this class.
|
modCount
Constructor and Description |
---|
MostRecentElementList(int maxSize)
Creates a new
MostRecentElementList with the specified
maximum capacity. |
Modifier and Type | Method and Description |
---|---|
void |
addNewElement(E element)
Adds a new
E element on top of this list, deleting any duplicates and
ensuring the respect of the list maximum size (defined by the maxSize variable). |
int |
getMaxSize()
Returns the maximum size defined for this list.
|
add, add, addAll, addAll, addFirst, addLast, clear, clone, contains, descendingIterator, element, get, getFirst, getLast, indexOf, lastIndexOf, listIterator, offer, offerFirst, offerLast, peek, peekFirst, peekLast, poll, pollFirst, pollLast, pop, push, remove, remove, remove, removeFirst, removeFirstOccurrence, removeLast, removeLastOccurrence, set, size, spliterator, toArray, toArray
iterator
equals, hashCode, listIterator, removeRange, subList
containsAll, isEmpty, removeAll, retainAll, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
containsAll, equals, hashCode, isEmpty, iterator, listIterator, removeAll, replaceAll, retainAll, sort, subList
parallelStream, removeIf, stream
private static final long serialVersionUID
int maxSize
public MostRecentElementList(int maxSize)
MostRecentElementList
with the specified
maximum capacity.maxSize
- the maximum size of the list. 0 for unlimited size.public int getMaxSize()
public void addNewElement(E element)
E
element on top of this list, deleting any duplicates and
ensuring the respect of the list maximum size (defined by the maxSize
variable).
This method does tree basic steps: first of all, if the E
element that
we try to add is already inside the list, it deletes it (this avoids duplicates). Then it
adds the element on top of the list (this implements the LIFO behaviour, because iterating
the list will give as first element the last item inserted, and so on). At the end, if this
add has made the list exceed the maximum defined size, the method deletes the oldest element of
the list added by this method (this ensure that the limit size capacity is respected and that
only the n most recent elements are kept in the list).
element
- the E
element to add to this list