Class FastArray<T>

  • All Implemented Interfaces:
    java.lang.Iterable<T>

    public class FastArray<T>
    extends java.lang.Object
    implements java.lang.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
    Author:
    Bela Ban
    • Field Detail

      • elements

        protected T[] elements
      • index

        protected int index
      • size

        protected int size
      • increment

        protected int increment
      • print_limit

        protected int print_limit
    • Constructor Detail

      • FastArray

        public FastArray​(int capacity)
    • Method Detail

      • 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​(java.util.Collection<T> list)
      • 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)
      • anyMatch

        public boolean anyMatch​(java.util.function.Predicate<T> pred)
      • remove

        public FastArray<T> remove​(int idx)
      • removeIf

        public FastArray<T> removeIf​(java.util.function.Predicate<T> filter,
                                     boolean replace_all)
      • replaceIf

        public FastArray<T> replaceIf​(java.util.function.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.FastIterator iterator()
        Iterator which iterates only over non-null elements, skipping null elements
        Specified by:
        iterator in interface java.lang.Iterable<T>
      • iterator

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

        public java.util.stream.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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • print

        public java.lang.String print()
      • resize

        public FastArray<T> resize​(int new_capacity)
      • print

        protected java.lang.String print​(int limit)
      • ensurePositive

        protected static int ensurePositive​(int i)