public class DebugList<E> extends AbstractEventList<E>
BasicEventList
at the root of
pipelines of EventList
s during development. It provides methods for turning on various
types of assertions which throw RuntimeException
s when they are violated. The goal is to
detect and fail fast on error conditions in much the same way Iterators commonly throw
ConcurrentModificationException
s.
Some of the assertions that are controlled by this DebugList include:
setLockCheckingEnabled(boolean)
toggles whether this DebugList asserts that all read
operations are guarded by read locks and all write operations are guarded by write locks.
getSanctionedReaderThreads()
is the Set of Threads which are allowed to read from
the DebugList. If the Set is empty then ALL Threads are assumed to be sanctioned
readers.
getSanctionedWriterThreads()
is the Set of Threads which are allowed to write to the
DebugList. If the Set is empty then ALL Threads are assumed to be sanctioned
writers.
publisher, readWriteLock, updates
Constructor and Description |
---|
DebugList()
Constructs a DebugList which, by default, performs no debugging.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E value)
Appends the specified element to the end of this list (optional operation).
|
void |
add(int index,
E value)
Inserts the specified element at the specified position in this list (optional operation).
|
boolean |
addAll(Collection<? extends E> values)
Appends all of the elements in the specified collection to the end of this list, in the order
that they are returned by the specified collection's iterator (optional operation).
|
boolean |
addAll(int index,
Collection<? extends E> values)
Inserts all of the elements in the specified collection into this list at the specified
position (optional operation).
|
protected void |
afterReadOperation()
This method is currently a no-op and exists for parity.
|
protected void |
afterWriteOperation()
This method is currently a no-op and exists for parity.
|
protected void |
beforeReadOperation()
This generic method is called immediately before any read operation is invoked.
|
protected void |
beforeWriteOperation()
This generic method is called immediately before any write operation is invoked.
|
void |
clear()
Removes all of the elements from this list (optional operation).
|
boolean |
contains(Object object)
Returns
true if this list contains the specified element. |
boolean |
containsAll(Collection<?> collection)
Returns
true if this list contains all of the elements of the specified collection. |
DebugList<E> |
createNewDebugList() |
void |
dispose()
Disposing an EventList will make it eligible for garbage collection.
|
boolean |
equals(Object object)
Compares the specified object with this list for equality.
|
E |
get(int index)
Returns the element at the specified position in this list.
|
ListEventPublisher |
getPublisher()
Get the publisher used to distribute
ListEvent s. |
ReadWriteLock |
getReadWriteLock()
Gets the lock required to share this list between multiple threads.
|
Set<Thread> |
getSanctionedReaderThreads() |
Set<Thread> |
getSanctionedWriterThreads() |
int |
hashCode()
Returns the hash code value for this list.
|
int |
indexOf(Object object)
Returns the index in this list of the first occurrence of the specified element, or -1 if this
list does not contain this element.
|
boolean |
isEmpty()
Returns
true if this list contains no elements. |
boolean |
isLockCheckingEnabled() |
int |
lastIndexOf(Object object)
Returns the index in this list of the last occurrence of the specified element, or -1 if this
list does not contain this element.
|
E |
remove(int index)
Removes the element at the specified position in this list (optional operation).
|
boolean |
remove(Object toRemove)
Removes the first occurrence in this list of the specified element (optional operation).
|
boolean |
removeAll(Collection<?> values)
Removes from this list all the elements that are contained in the specified collection
(optional operation).
|
boolean |
retainAll(Collection<?> values)
Retains only the elements in this list that are contained in the specified collection (optional
operation).
|
E |
set(int index,
E value)
Replaces the element at the specified position in this list with the specified element
(optional operation).
|
void |
setLockCheckingEnabled(boolean lockCheckingEnabled) |
int |
size()
Returns the number of elements in this list.
|
Object[] |
toArray()
Returns an array containing all of the elements in this list in proper sequence.
|
<T> T[] |
toArray(T[] array)
Returns an array containing all of the elements in this list in proper sequence; the runtime
type of the returned array is that of the specified array.
|
String |
toString()
Returns a string representation of this collection.
|
addListEventListener, iterator, listIterator, listIterator, removeListEventListener, subList
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
replaceAll, sort, spliterator
parallelStream, removeIf, stream
public DebugList()
public boolean isLockCheckingEnabled()
true
if DebugList is currently checking the calling Thread for lock ownership
before each read and write operation.public void setLockCheckingEnabled(boolean lockCheckingEnabled)
lockCheckingEnabled
- lockCheckingEnabled
is true
this DebugList will check the
calling Thread for lock ownership before each read and write operation;
false
indicates this check shouldn't be performed.public DebugList<E> createNewDebugList()
DebugList
which shares the same ListEventListener
and
ReadWriteLock
with this DebugList. This method is particularly useful when debugging a
CompositeList
where some member lists are DebugLists and thus must share an identical
publisher and locks in order to participate in the CompositeList.protected void beforeReadOperation()
protected void afterReadOperation()
protected void beforeWriteOperation()
protected void afterWriteOperation()
public ReadWriteLock getReadWriteLock()
getReadWriteLock
in interface EventList<E>
getReadWriteLock
in class AbstractEventList<E>
ReadWriteLock
that guarantees thread safe access to this list.public ListEventPublisher getPublisher()
ListEvent
s. It's always defined.getPublisher
in interface EventList<E>
getPublisher
in class AbstractEventList<E>
ListEvent
s.public E get(int index)
public int size()
Integer.MAX_VALUE
elements, returns Integer.MAX_VALUE
.size
in interface Collection<E>
size
in interface List<E>
size
in class AbstractEventList<E>
public boolean contains(Object object)
true
if this list contains the specified element. More formally, returns
true
if and only if this list contains at least one element e
such that
(o==null ? e==null : o.equals(e))
.contains
in interface Collection<E>
contains
in interface List<E>
contains
in class AbstractEventList<E>
object
- element whose presence in this list is to be tested.true
if this list contains the specified element.public boolean containsAll(Collection<?> collection)
true
if this list contains all of the elements of the specified collection.containsAll
in interface Collection<E>
containsAll
in interface List<E>
containsAll
in class AbstractEventList<E>
collection
- collection to be checked for containment in this list.true
if this list contains all of the elements of the specified collection.AbstractEventList.contains(Object)
public boolean equals(Object object)
true
if and only if
the specified object is also a list, both lists have the same size, and all corresponding pairs
of elements in the two lists are equal. (Two elements e1
and e2
are
equal if (e1==null ? e2==null :
e1.equals(e2))
.) In other words, two lists are defined to be equal if they contain the
same elements in the same order. This definition ensures that the equals method works properly
across different implementations of the List
interface.equals
in interface Collection<E>
equals
in interface List<E>
equals
in class AbstractEventList<E>
object
- the object to be compared for equality with this list.true
if the specified object is equal to this list.public int hashCode()
hashCode = 1; Iterator i = list.iterator(); while (i.hasNext()) { Object obj = i.next(); hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode()); }This ensures that
list1.equals(list2)
implies that
list1.hashCode()==list2.hashCode()
for any two lists, list1
and
list2
, as required by the general contract of Object.hashCode
.hashCode
in interface Collection<E>
hashCode
in interface List<E>
hashCode
in class AbstractEventList<E>
Object.hashCode()
,
Object.equals(Object)
,
AbstractEventList.equals(Object)
public int indexOf(Object object)
i
such
that (o==null ? get(i)==null : o.equals(get(i)))
, or -1 if there is no such index.public int lastIndexOf(Object object)
i
such
that (o==null ? get(i)==null : o.equals(get(i)))
, or -1 if there is no such index.lastIndexOf
in interface List<E>
lastIndexOf
in class AbstractEventList<E>
object
- element to search for.public boolean isEmpty()
true
if this list contains no elements.isEmpty
in interface Collection<E>
isEmpty
in interface List<E>
isEmpty
in class AbstractEventList<E>
true
if this list contains no elements.public Object[] toArray()
Collection.toArray
method.toArray
in interface Collection<E>
toArray
in interface List<E>
toArray
in class AbstractEventList<E>
Arrays.asList(T...)
public <T> T[] toArray(T[] array)
Collection.toArray(Object[])
method.toArray
in interface Collection<E>
toArray
in interface List<E>
toArray
in class AbstractEventList<E>
array
- the array into which the elements of this list are to be stored, if it is big
enough; otherwise, a new array of the same runtime type is allocated for this purpose.public String toString()
"[]"
). Adjacent elements are separated by the characters
", "
(comma and space). Elements are converted to strings as by
String.valueOf(Object)
.
This implementation creates an empty string buffer, appends a left square bracket, and iterates
over the collection appending the string representation of each element in turn. After
appending each element except the last, the string ", "
is appended. Finally a right
bracket is appended. A string is obtained from the string buffer, and returned.
toString
in class AbstractEventList<E>
public boolean add(E value)
Lists that support this operation may place limitations on what elements may be added to this list. In particular, some lists will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. List classes should clearly specify in their documentation any restrictions on what elements may be added.
add
in interface Collection<E>
add
in interface List<E>
add
in class AbstractEventList<E>
value
- element to be appended to this list.true
(as per the general contract of the Collection.add
method).public boolean remove(Object toRemove)
(o==null ? get(i)==null : o.equals(get(i)))
(if such
an element exists).remove
in interface Collection<E>
remove
in interface List<E>
remove
in class AbstractEventList<E>
toRemove
- element to be removed from this list, if present.true
if this list contained the specified element.public boolean addAll(Collection<? extends E> values)
addAll
in interface Collection<E>
addAll
in interface List<E>
addAll
in class AbstractEventList<E>
values
- collection whose elements are to be added to this list.true
if this list changed as a result of the call.AbstractEventList.add(Object)
public boolean addAll(int index, Collection<? extends E> values)
public boolean removeAll(Collection<?> values)
removeAll
in interface Collection<E>
removeAll
in interface List<E>
removeAll
in class AbstractEventList<E>
values
- collection that defines which elements will be removed from this list.true
if this list changed as a result of the call.AbstractEventList.remove(Object)
,
AbstractEventList.contains(Object)
public boolean retainAll(Collection<?> values)
retainAll
in interface Collection<E>
retainAll
in interface List<E>
retainAll
in class AbstractEventList<E>
values
- collection that defines which elements this set will retain.true
if this list changed as a result of the call.AbstractEventList.remove(Object)
,
AbstractEventList.contains(Object)
public void clear()
clear
in interface Collection<E>
clear
in interface List<E>
clear
in class AbstractEventList<E>
public E set(int index, E value)
public void add(int index, E value)
public E remove(int index)
public void dispose()
Warning: It is an error to call any method on an EventList
after it has been disposed.
Copyright © 2024 levigo holding gmbh. All rights reserved.