Class SizedRegistry

java.lang.Object
overit.geocall.util.SizedRegistry

public class SizedRegistry extends Object
This class implements a registry that can contain a customizable maximum number of object elements. The elements are recorded in a LinkedList; if an insertion causes the maximum number of elements to be exceeded, the first element will be removed from the list. The class exposes the methods to record the objects, to retrieve the current and the max size, and the current elements, in the form of ArrayList.
  • Field Details

    • _maxsize

      protected int _maxsize
    • _ll

      protected LinkedList _ll
  • Constructor Details

    • SizedRegistry

      public SizedRegistry(int maxsize)
      Creates a new SizedRegistry, with the desired maximum size
      Parameters:
      maxsize - The maximum number of element that the registry can contain
  • Method Details

    • getMaxSize

      public int getMaxSize()
      Returns the maximum size of the SizedRegistry
      Returns:
      The maximum number of element that the registry can contain
    • getCurrentSize

      public int getCurrentSize()
      Returns the current size of the SizedRegistry
      Returns:
      The number of elements currently recorded in the registry
    • record

      public Object record(Object o)
      Inserts the object in the last position of the SizedRegistry. If, after the insertion, the number of objects inserted in the registry is greater than the maximum number allowed, then the first element of the list is removed from the registry and returned by the function. Otherwise is returned null.
      Parameters:
      o - The object to record in the registry
      Returns:
      null or the first element of the registry if the entry causes the maximum number of elements to be exceeded
    • getCurrentContent

      public ArrayList getCurrentContent()
      Returns an ArrayList containing the elements of the SizedRegistry
      Returns:
      The ArrayList that contains the elements recorded in the registry