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:
java.io.Serializable,java.lang.Iterable<E>,java.util.Collection<E>,java.util.Set<E>
- Enclosing class:
- AsSynchronizedGraph<V,E>
private static class AsSynchronizedGraph.CopyOnDemandSet<E> extends java.lang.Object implements java.util.Set<E>, java.io.SerializableCreate 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
Fields Modifier and Type Field Description private java.util.Set<E>copyprivate booleancopyless(package private) java.util.concurrent.locks.ReadWriteLockreadWriteLockprivate static longserialVersionUIDprivate java.util.Set<E>setprivate static java.lang.StringUNMODIFIABLE
-
Constructor Summary
Constructors Modifier Constructor Description privateCopyOnDemandSet(java.util.Set<E> s, java.util.concurrent.locks.ReadWriteLock readWriteLock, boolean copyless)Constructor for CopyOnDemandSet.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E e)booleanaddAll(java.util.Collection<? extends E> c)voidclear()booleancontains(java.lang.Object o)booleancontainsAll(java.util.Collection<?> c)booleanequals(java.lang.Object o)Compares the specified object with this set for equality.voidforEach(java.util.function.Consumer<? super E> action)private java.util.Set<E>getCopy()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.booleanisCopyless()Return whether copyless mode is used for iteration.booleanisEmpty()java.util.Iterator<E>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.java.util.stream.Stream<E>parallelStream()Return a possibly parallelStreamwith the backing set's unmodifiable copy as its source.booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)booleanremoveIf(java.util.function.Predicate<? super E> filter)booleanretainAll(java.util.Collection<?> c)intsize()java.util.Spliterator<E>spliterator()Creates aSpliteratorover the elements in the set's unmodifiable copy.java.util.stream.Stream<E>stream()Return a sequentialStreamwith the backing set's unmodifiable copy as its source.java.lang.Object[]toArray()<T> T[]toArray(T[] a)java.lang.StringtoString()Return the backing set's toString result.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
set
private java.util.Set<E> set
-
copyless
private final boolean copyless
-
copy
private transient volatile java.util.Set<E> copy
-
readWriteLock
final java.util.concurrent.locks.ReadWriteLock readWriteLock
-
UNMODIFIABLE
private static final java.lang.String UNMODIFIABLE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CopyOnDemandSet
private CopyOnDemandSet(java.util.Set<E> s, java.util.concurrent.locks.ReadWriteLock readWriteLock, boolean copyless)
Constructor for CopyOnDemandSet.- Parameters:
s- the backing set.readWriteLock- the ReadWriteLock on which to lockedcopyless- whether copyless mode should be used
-
-
Method Detail
-
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
public boolean contains(java.lang.Object o)
-
iterator
public java.util.Iterator<E> 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
public java.lang.Object[] toArray()
-
toArray
public <T> T[] toArray(T[] a)
-
add
public boolean add(E e)
-
remove
public boolean remove(java.lang.Object o)
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
-
addAll
public boolean addAll(java.util.Collection<? extends E> c)
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
-
clear
public void clear()
-
forEach
public void forEach(java.util.function.Consumer<? super E> action)
- Specified by:
forEachin interfacejava.lang.Iterable<E>
-
removeIf
public boolean removeIf(java.util.function.Predicate<? super E> filter)
- Specified by:
removeIfin interfacejava.util.Collection<E>
-
spliterator
public java.util.Spliterator<E> spliterator()
Creates aSpliteratorover the elements in the set's unmodifiable copy.
-
stream
public java.util.stream.Stream<E> stream()
Return a sequentialStreamwith the backing set's unmodifiable copy as its source.- Specified by:
streamin interfacejava.util.Collection<E>- Returns:
- a sequential
Streamwith the backing set's unmodifiable copy as its source.
-
parallelStream
public java.util.stream.Stream<E> parallelStream()
Return a possibly parallelStreamwith the backing set's unmodifiable copy as its source.- Specified by:
parallelStreamin interfacejava.util.Collection<E>- Returns:
- a possibly parallel
Streamwith the backing set's unmodifiable copy as its source.
-
equals
public boolean equals(java.lang.Object o)
Compares the specified object with this set for equality.- Specified by:
equalsin interfacejava.util.Collection<E>- Specified by:
equalsin interfacejava.util.Set<E>- Overrides:
equalsin classjava.lang.Object- Parameters:
o- object to be compared for equality with this set.- Returns:
trueif o and this set are the same object or o is equal to the backing object, false otherwise.
-
hashCode
public int hashCode()
Return the backing set's hashcode.
-
toString
public java.lang.String toString()
Return the backing set's toString result.- Overrides:
toStringin classjava.lang.Object- Returns:
- the backing set's toString result.
-
getCopy
private java.util.Set<E> 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.
-
-