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.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
Fields Modifier and Type Field Description private java.util.Set<E>
copy
private boolean
copyless
(package private) java.util.concurrent.locks.ReadWriteLock
readWriteLock
private static long
serialVersionUID
private java.util.Set<E>
set
private static java.lang.String
UNMODIFIABLE
-
Constructor Summary
Constructors Modifier Constructor Description private
CopyOnDemandSet(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 boolean
add(E e)
boolean
addAll(java.util.Collection<? extends E> c)
void
clear()
boolean
contains(java.lang.Object o)
boolean
containsAll(java.util.Collection<?> c)
boolean
equals(java.lang.Object o)
Compares the specified object with this set for equality.void
forEach(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.int
hashCode()
Return the backing set's hashcode.boolean
isCopyless()
Return whether copyless mode is used for iteration.boolean
isEmpty()
java.util.Iterator<E>
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.java.util.stream.Stream<E>
parallelStream()
Return a possibly parallelStream
with the backing set's unmodifiable copy as its source.boolean
remove(java.lang.Object o)
boolean
removeAll(java.util.Collection<?> c)
boolean
removeIf(java.util.function.Predicate<? super E> filter)
boolean
retainAll(java.util.Collection<?> c)
int
size()
java.util.Spliterator<E>
spliterator()
Creates aSpliterator
over the elements in the set's unmodifiable copy.java.util.stream.Stream<E>
stream()
Return a sequentialStream
with the backing set's unmodifiable copy as its source.java.lang.Object[]
toArray()
<T> T[]
toArray(T[] a)
java.lang.String
toString()
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:
true
if the set uses copyless mode,false
otherwise
-
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:
forEach
in interfacejava.lang.Iterable<E>
-
removeIf
public boolean removeIf(java.util.function.Predicate<? super E> filter)
- Specified by:
removeIf
in interfacejava.util.Collection<E>
-
spliterator
public java.util.Spliterator<E> spliterator()
Creates aSpliterator
over the elements in the set's unmodifiable copy.
-
stream
public java.util.stream.Stream<E> stream()
Return a sequentialStream
with the backing set's unmodifiable copy as its source.- Specified by:
stream
in interfacejava.util.Collection<E>
- Returns:
- a sequential
Stream
with the backing set's unmodifiable copy as its source.
-
parallelStream
public java.util.stream.Stream<E> parallelStream()
Return a possibly parallelStream
with the backing set's unmodifiable copy as its source.- Specified by:
parallelStream
in interfacejava.util.Collection<E>
- Returns:
- a possibly parallel
Stream
with 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:
equals
in interfacejava.util.Collection<E>
- Specified by:
equals
in interfacejava.util.Set<E>
- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- object to be compared for equality with this set.- Returns:
true
if 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:
toString
in 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.
-
-