Module org.jgrapht.core
Package org.jgrapht.graph.concurrent
Class AsSynchronizedGraph.CopyOnDemandSet<E>
java.lang.Object
org.jgrapht.graph.concurrent.AsSynchronizedGraph.CopyOnDemandSet<E>
- Type Parameters:
E
- the class of the objects in the set
- All Implemented Interfaces:
Serializable
,Iterable<E>
,Collection<E>
,Set<E>
- Enclosing class:
AsSynchronizedGraph<V,
E>
private static class AsSynchronizedGraph.CopyOnDemandSet<E>
extends Object
implements Set<E>, Serializable
Create a synchronized (thread-safe) and unmodifiable Set backed by the specified Set. In
order to guarantee serial access, it is critical that all access to the
backing Set is accomplished through the created Set.
When a traversal over the set is started via a method such as iterator(), a snapshot of the underlying set is copied for iteration purposes (unless copyless mode is enabled).
The created Set's hashCode is equal to the backing Set's hashCode. And the created Set is equal to another set if they are the same Set or the backing Set is equal to the other Set.
The created set will be serializable if the backing set is serializable.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final boolean
(package private) final ReadWriteLock
private static final long
private static final String
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
CopyOnDemandSet
(Set<E> s, ReadWriteLock readWriteLock, boolean copyless) Constructor for CopyOnDemandSet. -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(Collection<? extends E> c) void
clear()
boolean
boolean
containsAll
(Collection<?> c) boolean
Compares the specified object with this set for equality.void
getCopy()
Get the backing set's unmodifiable copy, or a direct reference to the backing set if in copyless mode.int
hashCode()
Return the backing set's hashcode.boolean
Return whether copyless mode is used for iteration.boolean
isEmpty()
iterator()
Returns an iterator over the elements in the backing set's unmodifiable copy.private void
modified()
If the backing set is modified, call this method to let this set knows the backing set's copy need to update.Return a possibly parallelStream
with the backing set's unmodifiable copy as its source.boolean
boolean
removeAll
(Collection<?> c) boolean
boolean
retainAll
(Collection<?> c) int
size()
Creates aSpliterator
over the elements in the set's unmodifiable copy.stream()
Return a sequentialStream
with the backing set's unmodifiable copy as its source.Object[]
toArray()
<T> T[]
toArray
(T[] a) toString()
Return the backing set's toString result.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
toArray
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
set
-
copyless
private final boolean copyless -
copy
-
readWriteLock
-
UNMODIFIABLE
- See Also:
-
-
Constructor Details
-
CopyOnDemandSet
Constructor for CopyOnDemandSet.- Parameters:
s
- the backing set.readWriteLock
- the ReadWriteLock on which to lockedcopyless
- whether copyless mode should be used
-
-
Method Details
-
isCopyless
public boolean isCopyless()Return whether copyless mode is used for iteration.- Returns:
true
if the set uses copyless mode,false
otherwise
-
size
public int size() -
isEmpty
public boolean isEmpty() -
contains
-
iterator
Returns an iterator over the elements in the backing set's unmodifiable copy. The elements are returned in the same order of the backing set. -
toArray
-
toArray
public <T> T[] toArray(T[] a) -
add
-
remove
-
containsAll
- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceSet<E>
-
addAll
-
retainAll
-
removeAll
-
clear
public void clear() -
forEach
-
removeIf
- Specified by:
removeIf
in interfaceCollection<E>
-
spliterator
Creates aSpliterator
over the elements in the set's unmodifiable copy.- Specified by:
spliterator
in interfaceCollection<E>
- Specified by:
spliterator
in interfaceIterable<E>
- Specified by:
spliterator
in interfaceSet<E>
- Returns:
- a
Spliterator
over the elements in the backing set's unmodifiable copy.
-
stream
Return a sequentialStream
with the backing set's unmodifiable copy as its source.- Specified by:
stream
in interfaceCollection<E>
- Returns:
- a sequential
Stream
with the backing set's unmodifiable copy as its source.
-
parallelStream
Return a possibly parallelStream
with the backing set's unmodifiable copy as its source.- Specified by:
parallelStream
in interfaceCollection<E>
- Returns:
- a possibly parallel
Stream
with the backing set's unmodifiable copy as its source.
-
equals
Compares the specified object with this set for equality. -
hashCode
public int hashCode()Return the backing set's hashcode. -
toString
Return the backing set's toString result. -
getCopy
Get the backing set's unmodifiable copy, or a direct reference to the backing set if in copyless mode.- Returns:
- the backing set or its unmodifiable copy
-
modified
private void modified()If the backing set is modified, call this method to let this set knows the backing set's copy need to update.
-