Class FastArray<T>

java.lang.Object
org.jgroups.util.FastArray<T>
Type Parameters:
T - T
All Implemented Interfaces:
Iterable<T>, Collection<T>, List<T>, SequencedCollection<T>

public class FastArray<T> extends Object implements Iterable<T>, List<T>
Simple
unsynchronized
array. The array can only grow, but never shrinks (no arraycopy()). Elements are removed by nulling them. A size variable is maintained for quick size() / isEmpty().
Since:
5.2
Author:
Bela Ban
  • Field Details

    • elements

      protected T[] elements
    • index

      protected int index
    • size

      protected int size
    • increment

      protected int increment
  • Constructor Details

    • FastArray

      public FastArray()
    • FastArray

      public FastArray(int capacity)
    • FastArray

      public FastArray(T[] elements, int index)
    • FastArray

      public FastArray(Collection<? extends T> c)
  • Method Details

    • capacity

      public int capacity()
    • index

      public int index()
    • size

      public int size()
      Specified by:
      size in interface Collection<T>
      Specified by:
      size in interface List<T>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<T>
      Specified by:
      isEmpty in interface List<T>
    • increment

      public int increment()
    • increment

      public FastArray<T> increment(int i)
    • printLimit

      public int printLimit()
    • printLimit

      public FastArray<T> printLimit(int l)
    • add

      public boolean add(T el)
      Specified by:
      add in interface Collection<T>
      Specified by:
      add in interface List<T>
    • add

      public boolean add(T el, boolean resize)
    • add

      public void add(int idx, T el)
      Specified by:
      add in interface List<T>
    • addAll

      public boolean addAll(T[] els, int length)
      Adds elements from an array els to this array
      Parameters:
      els - The other array, can have null elements
      length - The number of elements to add. must be <= els.length
      Returns:
      The number of elements added
    • addAll

      @SafeVarargs public final boolean addAll(T... els)
    • addAll

      public boolean addAll(Collection<? extends T> list)
      Specified by:
      addAll in interface Collection<T>
      Specified by:
      addAll in interface List<T>
    • addAll

      public boolean addAll(FastArray<T> fa)
    • addAll

      public boolean addAll(FastArray<T> fa, boolean resize)
    • addAll

      public boolean addAll(int idx, Collection<? extends T> c)
      Specified by:
      addAll in interface List<T>
    • transferFrom

      public int transferFrom(FastArray<T> other, boolean clear)
      Copies the messages from the other array into this one,
      including
      null elements (using System.arraycopy(Object, int, Object, int, int). This is the same as calling clear(boolean) followed by addAll(FastArray, boolean), but faster.
      Parameters:
      other - The other array
      clear - Clears the other array after the transfer when true
      Returns:
      The number of non-null elements transferred from other
    • contains

      public boolean contains(Object o)
      Specified by:
      contains in interface Collection<T>
      Specified by:
      contains in interface List<T>
    • containsAll

      public boolean containsAll(Collection<?> c)
      Specified by:
      containsAll in interface Collection<T>
      Specified by:
      containsAll in interface List<T>
    • equals

      public boolean equals(Object obj)
      Specified by:
      equals in interface Collection<T>
      Specified by:
      equals in interface List<T>
      Overrides:
      equals in class Object
    • indexOf

      public int indexOf(Object o)
      Specified by:
      indexOf in interface List<T>
    • lastIndexOf

      public int lastIndexOf(Object o)
      Specified by:
      lastIndexOf in interface List<T>
    • anyMatch

      public boolean anyMatch(Predicate<T> pred)
    • get

      public T get(int idx)
      Specified by:
      get in interface List<T>
    • set

      public T set(int idx, T el)
      Specified by:
      set in interface List<T>
    • set

      public FastArray<T> set(T[] elements)
    • remove

      public T remove(int idx)
      Specified by:
      remove in interface List<T>
    • remove

      public boolean remove(Object o)
      Specified by:
      remove in interface Collection<T>
      Specified by:
      remove in interface List<T>
    • removeFirst

      public T removeFirst()
      Removes the first non-null element starting at index 0
      Specified by:
      removeFirst in interface List<T>
      Specified by:
      removeFirst in interface SequencedCollection<T>
    • removeLast

      public T removeLast()
      Specified by:
      removeLast in interface List<T>
      Specified by:
      removeLast in interface SequencedCollection<T>
    • removeAll

      public boolean removeAll(Collection<?> c)
      Specified by:
      removeAll in interface Collection<T>
      Specified by:
      removeAll in interface List<T>
    • removeIf

      public FastArray<T> removeIf(Predicate<T> filter, boolean replace_all)
    • replaceIf

      public FastArray<T> replaceIf(Predicate<T> filter, T new_el, boolean replace_all)
      Replaces any or all elements matching filter with a new element
      Parameters:
      filter - The filter, must ne non-null or no replacements will take place
      new_el - The new element, can be null
      replace_all - When false, the method returns after the first match (if any). Otherwise, all matching elements are replaced
    • retainAll

      public boolean retainAll(Collection<?> c)
      Specified by:
      retainAll in interface Collection<T>
      Specified by:
      retainAll in interface List<T>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<T>
      Specified by:
      clear in interface List<T>
    • clear

      public FastArray<T> clear(boolean null_elements)
    • trimTo

      public FastArray<T> trimTo(int new_capacity)
      Attempts to reduce the current capacity to new_capacity
      Parameters:
      new_capacity - The new capacity. If greater than the current capacity, this will be a no-op. If smaller than the current size, the current size will be taken instead as new capacity.
    • iterator

      public FastArray<T>.FastIterator iterator()
      Iterator which iterates only over non-null elements, skipping null elements
      Specified by:
      iterator in interface Collection<T>
      Specified by:
      iterator in interface Iterable<T>
      Specified by:
      iterator in interface List<T>
    • iterator

      public FastArray<T>.FastIterator iterator(Predicate<T> filter)
      Iterates over all non-null elements which match filter
    • stream

      public Stream<T> stream()
      Specified by:
      stream in interface Collection<T>
    • listIterator

      public ListIterator<T> listIterator()
      Specified by:
      listIterator in interface List<T>
    • listIterator

      public ListIterator<T> listIterator(int index)
      Specified by:
      listIterator in interface List<T>
    • subList

      public List<T> subList(int fromIndex, int toIndex)
      Specified by:
      subList in interface List<T>
    • toArray

      public Object[] toArray()
      Specified by:
      toArray in interface Collection<T>
      Specified by:
      toArray in interface List<T>
    • toArray

      public <T1> T1[] toArray(T1[] a)
      Specified by:
      toArray in interface Collection<T>
      Specified by:
      toArray in interface List<T>
    • count

      public int count()
      Returns the number of non-null elements, should have the same result as size(). Only used for testing!
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • print

      public String print()
    • resize

      public FastArray<T> resize(int new_capacity)
    • equalsArrayList

      protected boolean equalsArrayList(FastArray<?> other)
    • equalsRange

      protected boolean equalsRange(List<?> other, int from, int to)
    • print

      protected String print(int limit)
    • checkIndex

      protected int checkIndex(int idx)