Class SizedList

java.lang.Object
overit.geocall.util.SizedList

public class SizedList extends Object
The class implements a list with a specific size. The add method, adds the object always as the first element of the list, shifting the others and the elements that are in excess are eliminated. The class also exposes the classic get, remove and clear methods, in addition to the contains, used to search for a specific object in the SizedList
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
     
    protected ArrayList
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    SizedList(int maxSize)
    Creates a SizedList, with the desired size
  • Method Summary

    Modifier and Type
    Method
    Description
    Adds the object always as the first element of the list, shifting the others.
    void
    Empties the SizedList
    boolean
    Checks if the SizedList contains a specific object
    get(int pos)
    Returns the object element in the specific position
    remove(int pos)
    Removes the object element in the specific position
    int
    Returns the list size, that is fixed by the value used to create the SizedList (SizedList(maxSize))

    Methods inherited from class java.lang.Object

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

    • _maxSize

      protected int _maxSize
    • _values

      protected ArrayList _values
  • Constructor Details

    • SizedList

      public SizedList(int maxSize)
      Creates a SizedList, with the desired size
      Parameters:
      maxSize - The size of the list
  • Method Details

    • size

      public int size()
      Returns the list size, that is fixed by the value used to create the SizedList (SizedList(maxSize))
      Returns:
      The list size
    • add

      public Object add(Object o)
      Adds the object always as the first element of the list, shifting the others. If, after addition, the number of items in the list exceeds the maximum allowed size defined by the constructor method, the elements that are in excess are eliminated
      Parameters:
      o - The object to add
      Returns:
      The SizedList with the added object
    • get

      public Object get(int pos)
      Returns the object element in the specific position
      Parameters:
      pos - The position of the element
      Returns:
      The object in the desired position, or null if the position passed as parameter is greater than the list size
    • remove

      public Object remove(int pos)
      Removes the object element in the specific position
      Parameters:
      pos - The position of the element that must be removed
      Returns:
      The SizedList without the element removed, or null if the position passed as parameter is greater than the list size
    • contains

      public boolean contains(Object o)
      Checks if the SizedList contains a specific object
      Parameters:
      o - The object searched
      Returns:
      true if the object is in the SizedList, false otherwise
    • clear

      public void clear()
      Empties the SizedList