We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9bb8dad commit 59bcc2bCopy full SHA for 59bcc2b
1 file changed
src/main/kotlin/utils/CircularList.kt
@@ -8,15 +8,12 @@ import kotlinx.serialization.Serializable
8
* using IntelliJ IDEA
9
*/
10
@Serializable
11
-class CircularList<T>(private val maxCapacity: Int) : ArrayList<T>(maxCapacity) {
+class CircularList<T>(private val maxCapacity: Int, val items: ArrayList<T> = ArrayList(maxCapacity)) {
12
13
/** Adds a new element to the list and removes the oldest element.*/
14
- override fun add(element: T): Boolean {
15
- if (size == maxCapacity) removeFirst()
16
- return super.add(element)
+ fun add(element: T): Boolean {
+ if (items.size == maxCapacity) items.removeFirst()
+ return items.add(element)
17
}
18
19
- /** Returns all elements in this circular list. */
20
- fun elements() = toList()
21
-
22
0 commit comments