Class CyclicBuffer


  • public class CyclicBuffer
    extends java.lang.Object
    Holds LoggingEvents for immediate or differed display.

    This buffer gives read access to any element in the buffer not just the first or last element.

    Since:
    0.9.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) LoggingEvent[] ea  
      (package private) int first  
      (package private) int last  
      (package private) int maxSize  
      (package private) int numElems  
    • Constructor Summary

      Constructors 
      Constructor Description
      CyclicBuffer​(int maxSize)
      Constructs a new instance of at most maxSize events.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(LoggingEvent event)
      Adds an event as the last event in the buffer.
      LoggingEvent get()
      Gets the oldest (first) element in the buffer.
      LoggingEvent get​(int i)
      Gets the ith oldest event currently in the buffer.
      int getMaxSize()  
      int length()
      Gets the number of elements in the buffer.
      void resize​(int newSize)
      Resizes the cyclic buffer to newSize.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • first

        int first
      • last

        int last
      • numElems

        int numElems
      • maxSize

        int maxSize
    • Constructor Detail

      • CyclicBuffer

        public CyclicBuffer​(int maxSize)
                     throws java.lang.IllegalArgumentException
        Constructs a new instance of at most maxSize events. The maxSize argument must a positive integer.
        Parameters:
        maxSize - The maximum number of elements in the buffer.
        Throws:
        java.lang.IllegalArgumentException
    • Method Detail

      • add

        public void add​(LoggingEvent event)
        Adds an event as the last event in the buffer.
      • get

        public LoggingEvent get()
        Gets the oldest (first) element in the buffer. The oldest element is removed from the buffer.
      • get

        public LoggingEvent get​(int i)
        Gets the ith oldest event currently in the buffer. If i is outside the range 0 to the number of elements currently in the buffer, then null is returned.
      • getMaxSize

        public int getMaxSize()
      • length

        public int length()
        Gets the number of elements in the buffer. This number is guaranteed to be in the range 0 to maxSize (inclusive).
      • resize

        public void resize​(int newSize)
        Resizes the cyclic buffer to newSize.
        Throws:
        java.lang.IllegalArgumentException - if newSize is negative.