Class ZArrayList<T>

Type Parameters:
T - Type of array elements
All Implemented Interfaces:
Serializable, Cloneable, Iterable<T>, Collection<T>, List<T>, RandomAccess

public class ZArrayList<T>
extends ArrayList<T>
A synchronized implementation of ArrayList.

The Java implementation of ArrayList is unsynchronized. This class extends the implementation to provide synchronization.

See Also:
Serialized Form
  • Constructor Details

    • ZArrayList

      public ZArrayList()
      Constructs an empty list with an initial capacity of 10.
  • Method Details

    • lockRead

      public final void lockRead()
      Locks the list for reading.

      This method is used by the class internally to provide synchronization, but you can use it directly when you need to perform a synchronized bulk read operation on the list.

    • lockWrite

      public final void lockWrite()
      Locks the list for writing.

      This method is used by the class internally to provide synchronization, but you can use it directly when you need to perform a synchronized bulk write operation on the list.

    • unlockRead

      public final void unlockRead()
      Unlocks the list after reading.

      This method is used by the class internally, but you should use it directly if you use lockRead() directly.

    • unlockWrite

      public final void unlockWrite()
      Unlocks the list after writing.

      This method is used by the class internally, but you should use it directly if you use lockWrite() directly.

    • add

      public boolean add​(T e)
      Synchronized implementation of ArrayList.add(java.lang.Object).
      Specified by:
      add in interface Collection<T>
      Specified by:
      add in interface List<T>
      Overrides:
      add in class ArrayList<T>
      Parameters:
      e - element to be appended to this list.
      Returns:
      true (as specified by Collection.add(java.lang.Object)).
    • add

      public void add​(int index, T element)
      Synchronized implementation of ArrayList.add(int, java.lang.Object).
      Specified by:
      add in interface List<T>
      Overrides:
      add in class ArrayList<T>
      Parameters:
      index - index at which the specified element is to be inserted.
      element - element to be inserted.
    • addAll

      public boolean addAll​(Collection<? extends T> c)
      Synchronized implementation of ArrayList.addAll(java.util.Collection).
      Specified by:
      addAll in interface Collection<T>
      Specified by:
      addAll in interface List<T>
      Overrides:
      addAll in class ArrayList<T>
      Parameters:
      c - collection containing elements to be added to this list.
      Returns:
      true if this list changed as a result of the call.
    • clear

      public void clear()
      Synchronized implementation of ArrayList.clear().
      Specified by:
      clear in interface Collection<T>
      Specified by:
      clear in interface List<T>
      Overrides:
      clear in class ArrayList<T>
    • forEach

      public void forEach​(Consumer<? super T> action)
      Synchronized implementation of ArrayList.forEach(java.util.function.Consumer)
      Specified by:
      forEach in interface Iterable<T>
      Overrides:
      forEach in class ArrayList<T>
      Parameters:
      action - The action to be performed for each element
    • get

      public T get​(int index)
      Synchronized implementation of ArrayList.get(int).
      Specified by:
      get in interface List<T>
      Overrides:
      get in class ArrayList<T>
      Parameters:
      index - index of the element to return.
      Returns:
      the element at the specified position in this list.
    • remove

      public T remove​(int index)
      Synchronized implementation of ArrayList.remove(int).
      Specified by:
      remove in interface List<T>
      Overrides:
      remove in class ArrayList<T>
      Parameters:
      index - the index of the element to be removed.
      Returns:
      the element that was removed from the list.
    • remove

      public boolean remove​(Object o)
      Synchronized implementation of ArrayList.remove(java.lang.Object).
      Specified by:
      remove in interface Collection<T>
      Specified by:
      remove in interface List<T>
      Overrides:
      remove in class ArrayList<T>
      Parameters:
      o - element to be removed from this list, if present.
      Returns:
      true if this list contained the specified element.
    • anyMatch

      public boolean anyMatch​(Predicate<? super T> predicate)
      Returns whether any elements of this array match the provided predicate.

      Returns whether any elements of this array match the provided predicate. The method synchronizes the set for reading before searching for a match.

      Parameters:
      predicate - a non-interfering, stateless predicate to apply to elements of this array
      Returns:
      true if any elements of the array match the provided predicate, otherwise false