com.jthreadkit.collection
Class WrappedSizeMonitoredSortedSet
java.lang.Object
|
+--com.jthreadkit.AbstractSizeMonitored
|
+--com.jthreadkit.collection.WrappedSizeMonitoredCollection
|
+--com.jthreadkit.collection.WrappedSizeMonitoredSet
|
+--com.jthreadkit.collection.WrappedSizeMonitoredSortedSet
- All Implemented Interfaces:
- AccessibleLock, Collection, Set, SimpleShutdown, SizeMonitored, SizeMonitoredCollection, SizeMonitoredSet, SizeMonitoredSortedSet, SortedSet, TimedOutExceptionOption
- public class WrappedSizeMonitoredSortedSet
- extends WrappedSizeMonitoredSet
- implements SizeMonitoredSortedSet, SortedSet, SizeMonitored
Used to wrap an instance of SortedSet with synchronization
and implementation of all the methods of SizeMonitored.
This class can be used like this:
|
SizeMonitoredSortedSet smss =
new WrappedSizeMonitoredSortedSet(new TreeSet());
SizeMonitored sm = smss; // can be viewed as a SizeMonitored
SortedSet ss = smss; // can be viewed as a SortedSet too
|
Note that when possible it's best to avoid keeping a direct reference to
the underlying "raw" SortedSet (like this example above). This
makes accidental use of the un-synchronized one impossible.
All method calls are synchronized on the object returned
by getLockObject().
The object to lock on can be specified during construction
or defaults to this. [There is no
need to wrap the raw or resulting wrapped object by using
Collections.synchronizedSortedSet().]
To safely iterate in an multithreaded environment, use code like this:
|
SizeMonitoredSortedSet smss = //...
//...
synchronized ( smss.getLockObject() ) {
Iterator iter = smss.iterator();
while ( iter.hasNext() ) {
Object obj = iter.next();
//...
}
}
|
The methods of SizeMonitored are nicely combined so that
we can have one thread doing something like this:
while another thread is modifying (adding and removing elements) the
object.
| Methods inherited from class com.jthreadkit.collection.WrappedSizeMonitoredCollection |
add, addAll, clear, contains, containsAll, equals, hashCode, iterator, remove, removeAll, retainAll, setCapacity, size, toArray, toArray |
| Methods inherited from class com.jthreadkit.AbstractSizeMonitored |
addSizeChangeListener, getCapacity, getLockObject, getSize, isEmpty, isFull, isUseTimedOutExceptionSet, removeSizeChangeListener, setUseTimedOutException, shutdown, shutdownWhenEmpty, waitForSizeToChange, waitForSizeToChange, waitForSizeToClimbTo, waitForSizeToClimbTo, waitForSizeToFallTo, waitForSizeToFallTo, waitUntilEmpty, waitUntilEmpty, waitUntilFull, waitUntilFull, waitUntilSizeInRange, waitUntilSizeInRange, waitUntilSizeIs, waitUntilSizeIs, waitWhileEmpty, waitWhileEmpty, waitWhileFull, waitWhileFull, waitWhileSizeInRange, waitWhileSizeInRange, waitWhileSizeIs, waitWhileSizeIs |
| Methods inherited from interface com.jthreadkit.SizeMonitored |
addSizeChangeListener, getCapacity, getSize, isEmpty, isFull, removeSizeChangeListener, setCapacity, shutdownWhenEmpty, waitForSizeToChange, waitForSizeToChange, waitForSizeToClimbTo, waitForSizeToClimbTo, waitForSizeToFallTo, waitForSizeToFallTo, waitUntilEmpty, waitUntilEmpty, waitUntilFull, waitUntilFull, waitUntilSizeInRange, waitUntilSizeInRange, waitUntilSizeIs, waitUntilSizeIs, waitWhileEmpty, waitWhileEmpty, waitWhileFull, waitWhileFull, waitWhileSizeInRange, waitWhileSizeInRange, waitWhileSizeIs, waitWhileSizeIs |
| Methods inherited from interface java.util.Set |
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray |
WrappedSizeMonitoredSortedSet
public WrappedSizeMonitoredSortedSet(SortedSet ss,
Object lock,
boolean useTimedOutException)
WrappedSizeMonitoredSortedSet
public WrappedSizeMonitoredSortedSet(SortedSet ss)
comparator
public Comparator comparator()
- Specified by:
comparator in interface SortedSet
first
public Object first()
- Specified by:
first in interface SortedSet
headSet
public SortedSet headSet(Object toElement)
- Specified by:
headSet in interface SortedSet
last
public Object last()
- Specified by:
last in interface SortedSet
subSet
public SortedSet subSet(Object fromElement,
Object toElement)
- Specified by:
subSet in interface SortedSet
tailSet
public SortedSet tailSet(Object fromElement)
- Specified by:
tailSet in interface SortedSet
© Copyright 2000-2001 Programix Incorporated. All rights reserved. JThreadKit home