Class SealableMap<K,V>

java.lang.Object
com.cedarsoftware.io.util.SealableMap<K,V>
All Implemented Interfaces:
Map<K,V>

public class SealableMap<K,V> extends Object implements 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.

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.
  • Constructor Details

    • SealableMap

      public SealableMap(Supplier<Boolean> sealedSupplier)
      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

      public SealableMap(Map<K,V> map, Supplier<Boolean> sealedSupplier)
      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