package fi.aalto.trafficsense.regularroutes.backend.pipeline;

import fi.aalto.trafficsense.regularroutes.backend.parser.LocationData;
import timber.log.Timber;

import java.util.ArrayDeque;
import java.util.Deque;

public class DataQueue implements DataCollector.Listener {
    private final Deque<DataPoint> mDeque;

    private long mNextSequence;

    public DataQueue() {
        this.mDeque = new ArrayDeque<DataPoint>();
    }

    @Override
    public void onDataReady(LocationData locationData) {
        DataPoint dataPoint = new DataPoint(System.currentTimeMillis(), mNextSequence++, locationData);
        while (!this.mDeque.offer(dataPoint)) {
            DataPoint discarded = this.mDeque.pop();
            Timber.w("Queue full, discarding data point %s", discarded);
        }
        Timber.d("%s", this.mDeque);
    }

}

@@ -56,16 +56,64 @@
 eline;%0A%0A
+import com.google.common.collect.EvictingQueue;%0A
 import f
@@ -224,40 +224,11 @@
 til.
-ArrayDeque;%0Aimport java.util.Deq
+Que
 ue;%0A
@@ -303,17 +303,62 @@
 ate 
-final Deq
+static final int MAX_SIZE = 256;%0A    private final Que
 ue%3CD
@@ -460,34 +460,37 @@
 e = 
-new ArrayDeque%3CDataPoint%3E(
+EvictingQueue.create(MAX_SIZE
 );%0A 
@@ -682,16 +682,8 @@
     
-while (!
 this
@@ -694,163 +694,23 @@
 que.
-offer(dataPoint)) %7B%0A            DataPoint discarded = this.mDeque.pop();%0A            Timber.w(%22Queue full, discarding 
+add(
 data
- p
+P
 oint
- %25s%22, discarded);%0A        %7D
+);
 %0A   

Use proper eviction for data queue