|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.levigo.util.base.glazedlists.AbstractEventList<E> com.levigo.util.base.glazedlists.DebugList<E>
public class DebugList<E>
DebugList is meant to be used as a drop-in replacement for
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.
Field Summary |
---|
Fields inherited from class com.levigo.util.base.glazedlists.AbstractEventList |
---|
publisher, readWriteLock, updates |
Constructor Summary | |
---|---|
DebugList()
Constructs a DebugList which, by default, performs no debugging. |
Method Summary | ||
---|---|---|
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. |
|
|
createNewDebugList()
Returns a new empty DebugList which shares the same
ListEventListener and ReadWriteLock with this DebugList. |
|
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()
Returns the Set of Threads that are allowed to perform reads on
this DebugList. |
|
Set<Thread> |
getSanctionedWriterThreads()
Returns the Set of Threads that are allowed to perform writes on
this DebugList. |
|
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()
Returns true if DebugList is currently checking the calling Thread for lock ownership before each read and write operation. |
|
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)
If 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. |
|
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. |
|
|
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. |
Methods inherited from class com.levigo.util.base.glazedlists.AbstractEventList |
---|
addListEventListener, iterator, listIterator, listIterator, removeListEventListener, subList |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public DebugList()
Method Detail |
---|
public boolean isLockCheckingEnabled()
public void setLockCheckingEnabled(boolean 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 Set<Thread> getSanctionedReaderThreads()
Set
of Threads that are allowed to perform reads on
this DebugList. If the Set
is empty, all Threads are allowed to
read from this DebugList. Users are expected to add and remove Threads
directly on this Set
.
public Set<Thread> getSanctionedWriterThreads()
Set
of Threads that are allowed to perform writes on
this DebugList. If the Set
is empty, all Threads are allowed to
write to this DebugList. Users are expected to add and remove Threads
directly on this Set
.
public <E> 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.
getPublisher
in interface EventList<E>
getPublisher
in class AbstractEventList<E>
public E get(int index)
get
in interface List<E>
get
in class AbstractEventList<E>
index
- index of element to return.
public int size()
size
in interface Collection<E>
size
in interface List<E>
size
in class AbstractEventList<E>
public boolean contains(Object object)
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.
public boolean containsAll(Collection<?> 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.
AbstractEventList.contains(Object)
public boolean equals(Object object)
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.
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)
indexOf
in interface List<E>
indexOf
in class AbstractEventList<E>
object
- element to search for.
public int lastIndexOf(Object object)
lastIndexOf
in interface List<E>
lastIndexOf
in class AbstractEventList<E>
object
- element to search for.
public boolean isEmpty()
isEmpty
in interface Collection<E>
isEmpty
in interface List<E>
isEmpty
in class AbstractEventList<E>
public Object[] toArray()
toArray
in interface Collection<E>
toArray
in interface List<E>
toArray
in class AbstractEventList<E>
Arrays.asList(T...)
public <T> T[] toArray(T[] array)
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()
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.
public boolean remove(Object toRemove)
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.
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.
AbstractEventList.add(Object)
public boolean addAll(int index, Collection<? extends E> values)
addAll
in interface List<E>
addAll
in class AbstractEventList<E>
index
- index at which to insert first element from the specified collection.values
- elements to be inserted into this list.
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.
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.
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)
set
in interface List<E>
set
in class AbstractEventList<E>
index
- index of element to replace.value
- element to be stored at the specified position.
public void add(int index, E value)
add
in interface List<E>
add
in class AbstractEventList<E>
index
- index at which the specified element is to be inserted.value
- element to be inserted.public E remove(int index)
remove
in interface List<E>
remove
in class AbstractEventList<E>
index
- the index of the element to removed.
public void dispose()
Warning: It is an error
to call any method on an EventList
after it has been disposed.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |