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>
ArrayList
.
The Java implementation of ArrayList
is unsynchronized. This class extends the implementation to provide
synchronization.
- See Also:
- Serialized Form
-
Field Summary
-
Constructor Summary
Constructors Constructor Description ZArrayList()
Constructs an empty list with an initial capacity of 10. -
Method Summary
Modifier and Type Method Description void
add(int index, T element)
Synchronized implementation ofArrayList.add(int, java.lang.Object)
.boolean
add(T e)
Synchronized implementation ofArrayList.add(java.lang.Object)
.boolean
addAll(Collection<? extends T> c)
Synchronized implementation ofArrayList.addAll(java.util.Collection)
.boolean
anyMatch(Predicate<? super T> predicate)
Returns whether any elements of this array match the provided predicate.void
clear()
Synchronized implementation ofArrayList.clear()
.void
forEach(Consumer<? super T> action)
Synchronized implementation ofArrayList.forEach(java.util.function.Consumer)
T
get(int index)
Synchronized implementation ofArrayList.get(int)
.void
lockRead()
Locks the list for reading.void
lockWrite()
Locks the list for writing.T
remove(int index)
Synchronized implementation ofArrayList.remove(int)
.boolean
remove(Object o)
Synchronized implementation ofArrayList.remove(java.lang.Object)
.void
unlockRead()
Unlocks the list after reading.void
unlockWrite()
Unlocks the list after writing.Methods inherited from class java.util.ArrayList
addAll, clone, contains, ensureCapacity, equals, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
-
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
Synchronized implementation ofArrayList.add(java.lang.Object)
.- Specified by:
add
in interfaceCollection<T>
- Specified by:
add
in interfaceList<T>
- Overrides:
add
in classArrayList<T>
- Parameters:
e
- element to be appended to this list.- Returns:
- true (as specified by
Collection.add(java.lang.Object)
).
-
add
Synchronized implementation ofArrayList.add(int, java.lang.Object)
. -
addAll
Synchronized implementation ofArrayList.addAll(java.util.Collection)
. -
clear
public void clear()Synchronized implementation ofArrayList.clear()
. -
forEach
Synchronized implementation ofArrayList.forEach(java.util.function.Consumer)
-
get
Synchronized implementation ofArrayList.get(int)
. -
remove
Synchronized implementation ofArrayList.remove(int)
. -
remove
Synchronized implementation ofArrayList.remove(java.lang.Object)
. -
anyMatch
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, otherwisefalse
-