Class BoundedList<T>
java.lang.Object
org.openjdk.jmc.common.collection.BoundedList<T>
- Type Parameters:
T
- type of the stored elements
- All Implemented Interfaces:
Iterable<T>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
The list elements are stored in nodes that takes care of the actual linking. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a value to this list.getFirst()
Get the first element in the list.getLast()
Get the last element in the list.int
Get the maximum number of elements to retain in this list.int
getSize()
Get the number of elements in this list.iterator()
Get an iterator from the first available to the last available element at the time the iterator was created.void
setMaxSize
(int maxSize) Set the maximum number of elements to retain in this list.toString()
Use only for debugging purposes!Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
BoundedList
public BoundedList(int maxSize) Create a new bounded list.- Parameters:
maxSize
- maximum number of elements to keep
-
-
Method Details
-
add
Adds a value to this list. If the list is at max capacity then the oldest element will be dropped.- Parameters:
t
- the value to add
-
iterator
Get an iterator from the first available to the last available element at the time the iterator was created. Keeping a reference to an iterator for longer than necessary may keep memory from properly being reclaimed. -
getFirst
Get the first element in the list.- Returns:
- the first element
-
getLast
Get the last element in the list.- Returns:
- the last element
-
getSize
public int getSize()Get the number of elements in this list.- Returns:
- the size of the list
-
getMaxSize
public int getMaxSize()Get the maximum number of elements to retain in this list.- Returns:
- the maximum size of the list
-
setMaxSize
public void setMaxSize(int maxSize) Set the maximum number of elements to retain in this list.- Parameters:
maxSize
- the maximum size of the list
-
toString
Use only for debugging purposes!
-