Class FastAccess<T>

java.lang.Object
org.ddogleg.struct.FastAccess<T>
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
DogArray, FastArray

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

    • data

      public T[] data
    • size

      public int size
    • type

      public final Class<T> type
  • Constructor Details

    • FastAccess

      protected FastAccess(Class<T> type)
  • Method Details

    • get

      public T get(int index)
    • isIndexOutOfBounds

      public boolean isIndexOutOfBounds(int index)
      Returns true if the specified array index is outside the allowed value range
    • 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
    • isEmpty

      public boolean isEmpty()
      True if the container has no elements
    • toList

      public abstract 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
    • contains

      public boolean contains(Object o)
      Returns true if an object 'a' in the array returns true for 'a.equals(o)'
    • indexOf

      public int indexOf(T obj)
      Returns the first index which equals() obj. -1 is there is no match
      Parameters:
      obj - The object being searched for
      Returns:
      index or -1 if not found
    • reverse

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

      public void swap(int i, int j)
      Swaps the two elements in the array
      Parameters:
      i - index
      j - index
    • findIdx

      public int findIdx(FastAccess.FunctionMatches<T> function)
      Returns the first instance's index which matches the function. -1 if no match is found
    • find

      @Nullable public T find(FastAccess.FunctionMatches<T> function)
      Returns the first instance which matches the function. Null if no matches are found
    • findAllIdx

      public boolean findAllIdx(DogArray_I32 matches, FastAccess.FunctionMatches<T> function)
      Finds the indexes of all elements which match. Returns true if at least one match was found
    • findAll

      public boolean findAll(List<T> matches, FastAccess.FunctionMatches<T> function)
      Finds the indexes of all elements which match. Returns true if at least one match was found
    • filter

      public List<T> filter(FastAccess.FunctionMatches<T> function)
    • forIdx

      public void forIdx(FastAccess.FunctionEachIdx<T> function)
      The passed in function is called once for each element in the list
    • forIdx

      public void forIdx(int idx0, int idx1, FastAccess.FunctionEachIdx<T> function)
      For each with a range of values specified
      Parameters:
      idx0 - lower extent, inclusive
      idx1 - upper extent, exclusive
    • forEach

      public void forEach(FastAccess.FunctionEach<T> function)
      The passed in function is called once for each element in the list
    • count

      public int count(FastAccess.FunctionMatches<T> test)
      Counts the number of times an element returns true when passed into 'test'
    • forEach

      public void forEach(int idx0, int idx1, FastAccess.FunctionEach<T> function)
      For each with a range of values specified
      Parameters:
      idx0 - lower extent, inclusive
      idx1 - upper extent, exclusive