Class SealableSet<T>

java.lang.Object
com.cedarsoftware.io.util.SealableSet<T>
All Implemented Interfaces:
Iterable<T>, Collection<T>, Set<T>

public class SealableSet<T> extends Object implements 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.

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 Details

    • SealableSet

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

      public SealableSet(Collection<T> col, Supplier<Boolean> sealedSupplier)
      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

      public SealableSet(Set<T> set, Supplier<Boolean> sealedSupplier)
      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