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 ReadWriteLockprivate static final longprivate static final String -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateCopyOnDemandSet(Set<E> s, ReadWriteLock readWriteLock, boolean copyless) Constructor for CopyOnDemandSet. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanaddAll(Collection<? extends E> c) voidclear()booleanbooleancontainsAll(Collection<?> c) booleanCompares the specified object with this set for equality.voidgetCopy()Get the backing set's unmodifiable copy, or a direct reference to the backing set if in copyless mode.inthashCode()Return the backing set's hashcode.booleanReturn whether copyless mode is used for iteration.booleanisEmpty()iterator()Returns an iterator over the elements in the backing set's unmodifiable copy.private voidmodified()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 parallelStreamwith the backing set's unmodifiable copy as its source.booleanbooleanremoveAll(Collection<?> c) booleanbooleanretainAll(Collection<?> c) intsize()Creates aSpliteratorover the elements in the set's unmodifiable copy.stream()Return a sequentialStreamwith 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, waitMethods 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:
trueif the set uses copyless mode,falseotherwise
-
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:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceSet<E>
-
addAll
-
retainAll
-
removeAll
-
clear
public void clear() -
forEach
-
removeIf
- Specified by:
removeIfin interfaceCollection<E>
-
spliterator
Creates aSpliteratorover the elements in the set's unmodifiable copy.- Specified by:
spliteratorin interfaceCollection<E>- Specified by:
spliteratorin interfaceIterable<E>- Specified by:
spliteratorin interfaceSet<E>- Returns:
- a
Spliteratorover the elements in the backing set's unmodifiable copy.
-
stream
Return a sequentialStreamwith the backing set's unmodifiable copy as its source.- Specified by:
streamin interfaceCollection<E>- Returns:
- a sequential
Streamwith the backing set's unmodifiable copy as its source.
-
parallelStream
Return a possibly parallelStreamwith the backing set's unmodifiable copy as its source.- Specified by:
parallelStreamin interfaceCollection<E>- Returns:
- a possibly parallel
Streamwith 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.
-