Class FastArray<T>

java.lang.Object
org.jgroups.util.FastArray<T>
All Implemented Interfaces:
Iterable<T>

public class FastArray<T> extends Object implements Iterable<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
  • Field Details

    • elements

      protected T[] elements
    • index

      protected int index
    • size

      protected int size
    • increment

      protected int increment
  • Constructor Details

    • FastArray

      public FastArray(int capacity)
  • Method Details

    • capacity

      public int capacity()
    • index

      public int index()
    • size

      public int size()
    • isEmpty

      public boolean isEmpty()
    • increment

      public int increment()
    • increment

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

      public int printLimit()
    • printLimit

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

      public int add(T el)
    • add

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

      public int add(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
    • add

      @SafeVarargs public final int add(T... els)
    • add

      public int add(Collection<T> list)
    • add

      public int add(FastArray<T> fa)
    • add

      public int add(FastArray<T> fa, boolean resize)
    • 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 add(FastArray, boolean), but supposedly 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
    • get

      public T get(int idx)
    • set

      public FastArray<T> set(int idx, T el)
    • set

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

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

      public FastArray<T> remove(int idx)
    • 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
    • clear

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

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

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

      public Stream<T> stream()
    • 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)
    • print

      protected String print(int limit)
    • ensurePositive

      protected static int ensurePositive(int i)