Class CircularList<T extends CircularList.TimeAccess>

java.lang.Object
com.polytechnik.utils.CircularList<T>

public class CircularList<T extends CircularList.TimeAccess> extends Object
A circular buffer to store data.
  • Field Details

    • buffer

      private T extends CircularList.TimeAccess[] buffer
    • ptr

      private int ptr
    • n_elements

      private int n_elements
    • last_cleared_before

      private long last_cleared_before
  • Constructor Details

    • CircularList

      public CircularList(int initialcapacity)
    • CircularList

      public CircularList()
  • Method Details

    • ensureCapacity

      public void ensureCapacity(int newcapacity)
    • add

      public void add(T t)
    • clearBefore

      public int clearBefore(long t0, Predicate<T> callback)
    • clearBefore

      public int clearBefore(long t0, Predicate<T> callback, int min_elements_to_keep)
      Clear all elements with time <t0. We assume trades are ordered, so we only clean the tail. Also make sure the are at least min_elements_to_store elements left in buffer.
    • removeBrokenElement

      public int removeBrokenElement(Predicate<T> checker)
      Remove element. Slow, because we scan all elements (from end to the beginning). The method removes a sigle element when checker.test() return false.
    • copyData

      public int copyData(T[] items)
    • getLastClearedBefore

      public long getLastClearedBefore()
    • getSize

      public int getSize()
    • getLastAddedElement

      public T getLastAddedElement()
    • backwardForEachEntry

      public boolean backwardForEachEntry(Predicate<T> procedure, int n_skip_from_the_end)
      The method loops backward over the elements of the list, set the n_skip_from_the_end=0 to loop over all elements.
    • forwardForEachEntry

      public boolean forwardForEachEntry(Predicate<T> procedure, int n_elements_to_scan)
      The method loops forward over the elements of the list, set the n_elements_to_scan=getSize(), to loop over all elements.
    • main

      public static void main(String[] args)