Package org.semanticweb.owlapi.util
Class CollectionFactory.ConditionalCopySet<T>
java.lang.Object
org.semanticweb.owlapi.util.CollectionFactory.ConditionalCopySet<T>
- Type Parameters:
T
- the type contained
- All Implemented Interfaces:
Iterable<T>
,Collection<T>
,Set<T>
- Enclosing class:
CollectionFactory
a set implementation that uses a delegate collection for all read-only operations and makes a
copy if changes are attempted. Useful for cheap defensive copies: no costly rehashing on the
original collection is made unless changes are attempted. Changes are not mirrored back to
the original collection, although changes to the original set BEFORE changes to the copy are
reflected in the copy. If the source collection is not supposed to change, then this
collection behaves just like a regular defensive copy; if the source collection can change,
then this collection should be built from a cheap copy of the original collection. For
example, if the source collection is a set, it can be copied into a list; the cost of the
copy operation from set to list is approximately 1/3 of the cost of copying into a new
HashSet. This is not efficient if the most common operations performed on the copy are
contains() or containsAll(), since they are more expensive for lists wrt sets; a counter for
these calls is maintained by the collection, so if a large number of contains/containsAll
calls takes place, the delegate is turned into a regular set. This implementation is not
threadsafe even if the source set is: there is no lock during the copy, and the new set is
not threadsafe.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(Collection<? extends T> c) void
clear()
boolean
boolean
containsAll
(Collection<?> c) boolean
int
hashCode()
boolean
isEmpty()
iterator()
boolean
boolean
removeAll
(Collection<?> c) boolean
retainAll
(Collection<?> c) int
size()
Object[]
toArray()
<Q> Q[]
toArray
(Q[] a) toString()
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.Set
spliterator
-
Constructor Details
-
ConditionalCopySet
- Parameters:
source
- initial elementslistCopy
- true if a copy must be made
-
-
Method Details
-
equals
-
hashCode
public int hashCode() -
toString
-
add
-
addAll
-
clear
public void clear() -
contains
-
containsAll
- Specified by:
containsAll
in interfaceCollection<T>
- Specified by:
containsAll
in interfaceSet<T>
-
isEmpty
public boolean isEmpty() -
iterator
-
remove
-
removeAll
-
retainAll
-
size
public int size() -
toArray
-
toArray
public <Q> Q[] toArray(@Nullable Q[] a)
-