Package com.cedarsoftware.io.util
Class SealableMap<K,V>
java.lang.Object
com.cedarsoftware.io.util.SealableMap<K,V>
- All Implemented Interfaces:
Map<K,
V>
SealableMap provides a Map or Map wrapper that can be 'sealed' and 'unsealed.' When sealed, the
Map is mutable, when unsealed it is immutable (read-only). The view methods iterator(), keySet(),
values(), and entrySet() return 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 ([email protected])
Copyright (c) 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.
-
Nested Class Summary
-
Constructor Summary
ConstructorsConstructorDescriptionSealableMap
(Supplier<Boolean> sealedSupplier) Create a SealableMap.Use this constructor to wrap a Map (any kind of Map) and make it a SealableMap. -
Method Summary
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
SealableMap
Create a SealableMap. Since a Map is not supplied, this will use a ConcurrentHashMapNullSafe internally. If you want a HashMap to be used internally, use the SealableMap constructor that takes a Map and pass it the instance you want it to wrap.- Parameters:
sealedSupplier
-Supplier<Boolean>
that returns 'true' to indicate sealed, 'false' for mutable.
-
SealableMap
Use this constructor to wrap a Map (any kind of Map) and make it a SealableMap. No duplicate of the Map is created and the original map is operated on directly if unsealed, or protected from changes if sealed.- Parameters:
map
- Map 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() -
containsKey
- Specified by:
containsKey
in interfaceMap<K,
V>
-
containsValue
- Specified by:
containsValue
in interfaceMap<K,
V>
-
get
-
keySet
-
values
-
entrySet
-
put
-
remove
-
putAll
-
clear
public void clear()
-