Class FastAccess<T>

  • All Implemented Interfaces:
    java.io.Serializable
    Direct Known Subclasses:
    FastArray, FastQueue

    public abstract class FastAccess<T>
    extends java.lang.Object
    implements java.io.Serializable
    Base class for FastArray and FastQueue. Provides access to the data but does not provide methods which add or grow the internal data structure.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      T[] data  
      int size  
      java.lang.Class<T> type  
    • Constructor Summary

      Constructors 
      Constructor Description
      FastAccess​(java.lang.Class<T> type)  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      T get​(int index)  
      int getMaxSize()
      The maximum number of elements before the 'data' array needs to grow
      T getTail()  
      T getTail​(int index)
      Returns an element in the list relative to the tail
      abstract T remove​(int index)
      Removes an element from the queue and preserves the order of all elements.
      abstract T removeSwap​(int index)
      Removes the specified index from the array by swapping it with last element.
      void reverse()
      Reverse the item order in this queue.
      int size()
      Number of elements in the array
      abstract java.util.List<T> toList()
      Returns a wrapper around FastQueue that allows it to act as a read only list.
      • Methods inherited from class java.lang.Object

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

      • data

        public T[] data
      • size

        public int size
      • type

        public final java.lang.Class<T> type
    • Constructor Detail

      • FastAccess

        public FastAccess​(java.lang.Class<T> type)
    • Method Detail

      • get

        public T get​(int index)
      • getMaxSize

        public int getMaxSize()
        The maximum number of elements before the 'data' array needs to grow
        Returns:
        length of 'data'
      • remove

        public abstract T remove​(int index)
        Removes an element from the queue and preserves the order of all elements. This is done by shifting elements in the array down one and placing the removed element at the old end of the list. O(N) runtime.
        Parameters:
        index - Index of the element being removed
        Returns:
        The object removed.
      • removeSwap

        public abstract T removeSwap​(int index)
        Removes the specified index from the array by swapping it with last element. Does not preserve order but has a runtime of O(1).
        Parameters:
        index - The index to be removed.
        Returns:
        The removed object
      • size

        public int size()
        Number of elements in the array
      • toList

        public abstract java.util.List<T> toList()
        Returns a wrapper around FastQueue that allows it to act as a read only list. There is little overhead in using this interface. NOTE: The same instead of a list is returned each time. Be careful when writing concurrent code and create a copy.
        Returns:
        List wrapper.
      • getTail

        public T getTail()
      • getTail

        public T getTail​(int index)
        Returns an element in the list relative to the tail
        Parameters:
        index - index relative to tail. 0 == the tail. size-1 = first element
        Returns:
        element
      • reverse

        public void reverse()
        Reverse the item order in this queue.