File tree Expand file tree Collapse file tree 2 files changed +7
-5
lines changed
main/kotlin/com/lambda/util/collections Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -106,11 +106,17 @@ class LimitedDecayQueue<E>(
106106 * Updates the maximum allowed size for the queue and triggers a cleanup operation
107107 * to remove elements exceeding the new size or falling outside the allowed time interval.
108108 *
109+ * Elements starting from the head will be removed.
110+ *
109111 * @param newSize The new maximum size for the queue. Must be a non-negative integer.
110112 */
111113 fun setMaxSize (newSize : Int ) {
112114 sizeLimit = newSize
113115 cleanUp()
116+
117+ while (queue.size > newSize) {
118+ queue.poll()
119+ }
114120 }
115121
116122 /* *
@@ -131,4 +137,4 @@ class LimitedDecayQueue<E>(
131137 onDecay(queue.poll().first)
132138 }
133139 }
134- }
140+ }
Original file line number Diff line number Diff line change @@ -137,11 +137,7 @@ class LimitedDecayQueueTest {
137137
138138 queue.setMaxSize(2 ) // Reduce size limit to 2
139139
140- queue.add(" Element4" )
141-
142- // Verify that the queue is limited to 2 elements, and oldest element is removed
143140 assertEquals(2 , queue.size)
144- assertTrue(onDecayCalled.contains(" Element1" )) // "Element1" should be decayed
145141 }
146142
147143 @Test
You can’t perform that action at this time.
0 commit comments