/*
 * Copyright (C) 2015 Pedro Vicente Gomez Sanchez.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.github.pedrovgs.lynx.presenter;

import com.github.pedrovgs.lynx.model.Trace;
import java.util.LinkedList;
import java.util.List;

/**
 * Buffer created to keep a max number of traces and be able to configure the size of the buffer.
 *
 * @author Pedro Vicente Gómez Sánchez.
 */
class TraceBuffer {

  private final int bufferSize;
  private final List<Trace> traces;

  TraceBuffer(int bufferSize) {
    this.bufferSize = bufferSize;
    traces = new LinkedList<Trace>();
  }

  /**
   * Add a list of traces to the buffer, if the buffer is full your new traces will be added and
   * the previous one will be removed.
   */
  public void add(List<Trace> traces) {
    this.traces.addAll(traces);
    int tracesToDiscard = getNumberOfTracesToDiscard();
    if (tracesToDiscard > 0) {
      discardTraces(tracesToDiscard);
    }
  }

  public List<Trace> getTraces() {
    return traces;
  }

  private int getNumberOfTracesToDiscard() {
    int currentTracesSize = this.traces.size();
    return currentTracesSize - bufferSize;
  }

  private void discardTraces(int tracesToDiscard) {
    for (int i = 0; i < tracesToDiscard; i++) {
      traces.remove(0);
    }
  }
}

@@ -929,22 +929,16 @@
 private 
-final 
 int buff
@@ -1091,16 +1091,208 @@
 );%0A  %7D%0A%0A
+  /**%0A   * Configure the max number of traces to keep inside the buffer%0A   */%0A  void setBufferSize(int bufferSize) %7B%0A    this.bufferSize = bufferSize;%0A    removeExceededTracesIfNeeded();%0A  %7D%0A%0A
   /**%0A  
@@ -1433,23 +1433,16 @@
    */%0A  
-public 
 void add
@@ -1496,16 +1496,157 @@
 races);%0A
+    removeExceededTracesIfNeeded();%0A  %7D%0A%0A  List%3CTrace%3E getTraces() %7B%0A    return traces;%0A  %7D%0A%0A  private void removeExceededTracesIfNeeded() %7B%0A
     int 
@@ -1777,67 +1777,8 @@
  %7D%0A%0A
-  public List%3CTrace%3E getTraces() %7B%0A    return traces;%0A  %7D%0A%0A
   pr

Add setBufferSize method implementation