Package com.cedarsoftware.io.util
Class SealableSet<T>
java.lang.Object
com.cedarsoftware.io.util.SealableSet<T>
- All Implemented Interfaces:
Iterable<T>
,Collection<T>
,Set<T>
SealableSet provides a Set or Set wrapper that can be 'sealed' and 'unsealed.' When sealed, the
Set is mutable, when unsealed it is immutable (read-only). The iterator() returns a view that
honors the Supplier's sealed state. The sealed state can be changed as often as needed.
NOTE: Please do not reformat this code as the current format makes it easy to see the overall structure.
NOTE: Please do not reformat this code as the current format makes it easy to see the overall structure.
- Author:
- John DeRegnaucourt
Copyright Cedar Software LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
License
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
Constructor Summary
ConstructorsConstructorDescriptionSealableSet
(Collection<T> col, Supplier<Boolean> sealedSupplier) Create a SealableSet.SealableSet
(Supplier<Boolean> sealedSupplier) Create a SealableSet.SealableSet
(Set<T> set, Supplier<Boolean> sealedSupplier) Use this constructor to wrap a Set (any kind of Set) and make it a SealableSet. -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(Collection<? extends T> col) void
clear()
boolean
boolean
containsAll
(Collection<?> col) boolean
int
hashCode()
boolean
isEmpty()
iterator()
boolean
boolean
removeAll
(Collection<?> col) boolean
retainAll
(Collection<?> col) int
size()
Object[]
toArray()
<T1> T1[]
toArray
(T1[] a) toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.Set
spliterator
-
Constructor Details
-
SealableSet
Create a SealableSet. Since a Set is not supplied, this will use a ConcurrentSet internally. If you want a HashSet to be used internally, use SealableSet constructor that takes a Set and pass it the instance you want it to wrap.- Parameters:
sealedSupplier
-Supplier<Boolean>
that returns 'true' to indicate sealed, 'false' for mutable.
-
SealableSet
Create a SealableSet. Since a Set is not supplied, the elements from the passed in Collection will be copied to an internal ConcurrentHashMap.newKeySet. If you want to use a HashSet for example, use SealableSet constructor that takes a Set and pass it the instance you want it to wrap.- Parameters:
col
- Collection to supply initial elements. These are copied to an internal ConcurrentHashMap.newKeySet.sealedSupplier
-Supplier<Boolean>
that returns 'true' to indicate sealed, 'false' for mutable.
-
SealableSet
Use this constructor to wrap a Set (any kind of Set) and make it a SealableSet. No duplicate of the Set is created and the original set is operated on directly if unsealed, or protected from changes if sealed.- Parameters:
set
- Set instance to protect.sealedSupplier
-Supplier<Boolean>
that returns 'true' to indicate sealed, 'false' for mutable.
-
-
Method Details
-
equals
-
hashCode
public int hashCode() -
toString
-
size
public int size() -
isEmpty
public boolean isEmpty() -
contains
-
toArray
-
toArray
public <T1> T1[] toArray(T1[] a) -
containsAll
- Specified by:
containsAll
in interfaceCollection<T>
- Specified by:
containsAll
in interfaceSet<T>
-
add
-
remove
-
addAll
-
removeAll
-
retainAll
-
clear
public void clear() -
iterator
-