Package rx.internal.util
Class LinkedArrayList
- java.lang.Object
-
- rx.internal.util.LinkedArrayList
-
- Direct Known Subclasses:
CachedObservable.CacheState
public class LinkedArrayList extends java.lang.ObjectA 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) intcapacityHintThe capacity of each array segment.(package private) java.lang.Object[]headContains the head of the linked array list if not null.(package private) intindexInTailThe next available slot in the current tail.(package private) intsizeThe 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) java.lang.Object[]tailThe 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(java.lang.Object o)Adds a new element to this list.intcapacityHint()Returns the capacity hint that indicates the capacity of each buffer segment.java.lang.Object[]head()Returns the head buffer segment or null if the list is empty.intindexInTail()Returns the index of the next slot in the tail buffer segment.intsize()Returns the total size of the list.java.lang.Object[]tail()Returns the tail buffer segment or null if the list is empty.(package private) java.util.List<java.lang.Object>toList()java.lang.StringtoString()
-
-
-
Field Detail
-
capacityHint
final int capacityHint
The capacity of each array segment.
-
head
java.lang.Object[] head
Contains the head of the linked array list if not null. The length is always capacityHint + 1 and the last element is an Object[] pointing to the next element of the linked array list.
-
tail
java.lang.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.
-
-
Method Detail
-
add
public void add(java.lang.Object o)
Adds a new element to this list.- Parameters:
o- the object to add, nulls are accepted
-
head
public java.lang.Object[] head()
Returns the head buffer segment or null if the list is empty.- Returns:
- the head object array
-
tail
public java.lang.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
java.util.List<java.lang.Object> toList()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-