Skip to content

Commit 59bcc2b

Browse files
committed
Added serialisation to circular lists
1 parent 9bb8dad commit 59bcc2b

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

src/main/kotlin/utils/CircularList.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@ import kotlinx.serialization.Serializable
88
* using IntelliJ IDEA
99
*/
1010
@Serializable
11-
class CircularList<T>(private val maxCapacity: Int) : ArrayList<T>(maxCapacity) {
11+
class CircularList<T>(private val maxCapacity: Int, val items: ArrayList<T> = ArrayList(maxCapacity)) {
1212

1313
/** 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)
14+
fun add(element: T): Boolean {
15+
if (items.size == maxCapacity) items.removeFirst()
16+
return items.add(element)
1717
}
1818

19-
/** Returns all elements in this circular list. */
20-
fun elements() = toList()
21-
2219
}

0 commit comments

Comments
 (0)