Class LinkedArrayList

java.lang.Object
rx.internal.util.LinkedArrayList
Direct Known Subclasses:
CachedObservable.CacheState

public class LinkedArrayList extends Object
A list implementation which combines an ArrayList with a LinkedList to avoid copying values when the capacity needs to be increased.

The class is non final to allow embedding it directly and thus saving on object allocation.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) final int
    The capacity of each array segment.
    (package private) Object[]
    Contains the head of the linked array list if not null.
    (package private) int
    The next available slot in the current tail.
    (package private) int
    The total size of the list; written after elements have been added (release) and and when read, the value indicates how many elements can be safely read (acquire).
    (package private) Object[]
    The tail array where new elements will be added.
  • Constructor Summary

    Constructors
    Constructor
    Description
    LinkedArrayList(int capacityHint)
    Constructor with the capacity hint of each array segment.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a new element to this list.
    int
    Returns the capacity hint that indicates the capacity of each buffer segment.
    Returns the head buffer segment or null if the list is empty.
    int
    Returns the index of the next slot in the tail buffer segment.
    int
    Returns the total size of the list.
    Returns the tail buffer segment or null if the list is empty.
    (package private) List<Object>
     
     

    Methods inherited from class java.lang.Object

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

    • capacityHint

      final int capacityHint
      The capacity of each array segment.
    • tail

      Object[] tail
      The tail array where new elements will be added.
    • size

      volatile int size
      The total size of the list; written after elements have been added (release) and and when read, the value indicates how many elements can be safely read (acquire).
    • indexInTail

      int indexInTail
      The next available slot in the current tail.
  • Constructor Details

    • LinkedArrayList

      public LinkedArrayList(int capacityHint)
      Constructor with the capacity hint of each array segment.
      Parameters:
      capacityHint -
  • Method Details

    • add

      public void add(Object o)
      Adds a new element to this list.
      Parameters:
      o - the object to add, nulls are accepted
    • head

      public Object[] head()
      Returns the head buffer segment or null if the list is empty.
      Returns:
      the head object array
    • tail

      public Object[] tail()
      Returns the tail buffer segment or null if the list is empty.
      Returns:
      the tail object array
    • size

      public int size()
      Returns the total size of the list.
      Returns:
      the total size of the list
    • indexInTail

      public int indexInTail()
      Returns the index of the next slot in the tail buffer segment.
      Returns:
      the index of the next slot in the tail buffer segment
    • capacityHint

      public int capacityHint()
      Returns the capacity hint that indicates the capacity of each buffer segment.
      Returns:
      the capacity hint that indicates the capacity of each buffer segment
    • toList

      List<Object> toList()
    • toString

      public String toString()
      Overrides:
      toString in class Object