totalngram: use CircularFifoQueue as sliding window base
diff --git a/pom.xml b/pom.xml
index 97ca101..308e1c2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -150,5 +150,11 @@
<artifactId>etaprinter</artifactId>
<version>2.0.0</version>
</dependency>
+ <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-collections4 -->
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-collections4</artifactId>
+ <version>4.1</version>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
diff --git a/src/main/java/org/ids_mannheim/SlidingWindowQueue.java b/src/main/java/org/ids_mannheim/SlidingWindowQueue.java
index 4f07362..cf3db43 100644
--- a/src/main/java/org/ids_mannheim/SlidingWindowQueue.java
+++ b/src/main/java/org/ids_mannheim/SlidingWindowQueue.java
@@ -1,22 +1,22 @@
package org.ids_mannheim;
-import java.util.LinkedList;
import java.util.function.Consumer;
+import org.apache.commons.collections4.queue.CircularFifoQueue;
-public class SlidingWindowQueue extends LinkedList {
+public class SlidingWindowQueue extends CircularFifoQueue {
private final int maxSize;
private final Consumer<String> flush;
public SlidingWindowQueue(int size, Consumer<String> flush) {
+ super(size);
this.maxSize = size;
this.flush = flush;
}
public boolean add(String k) {
boolean r = super.add(k);
- if (size() == maxSize) {
+ if (isAtFullCapacity()) {
this.flush.accept(String.join(" ", this));
- remove(0);
}
return r;
}