Class SealableList<T>

java.lang.Object
com.cedarsoftware.util.SealableList<T>
All Implemented Interfaces:
Iterable<T>, Collection<T>, List<T>

public class SealableList<T> extends Object implements List<T>
SealableList provides a List or List wrapper that can be 'sealed' and 'unsealed.' When sealed, the List is immutable, when unsealed it is mutable. The iterator(), listIterator(), and subList() return views that honor 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

    • SealableList

      public SealableList(Supplier<Boolean> sealedSupplier)
      Create a SealableList. Since no List is being supplied, this will use an ConcurrentList internally. If you want to use an ArrayList for example, use SealableList constructor that takes a List and pass it the instance you want it to wrap.
      Parameters:
      sealedSupplier - Supplier<Boolean> that returns 'true' to indicate sealed, 'false' for mutable.
    • SealableList

      public SealableList(Collection<T> col, Supplier<Boolean> sealedSupplier)
      Create a SealableList. Since a List is not supplied, the elements from the passed in Collection will be copied to an internal ConcurrentList. If you want to use an ArrayList for example, use SealableList constructor that takes a List and pass it the instance you want it to wrap.
      Parameters:
      col - Collection to supply initial elements. These are copied to an internal ConcurrentList.
      sealedSupplier - Supplier<Boolean> that returns 'true' to indicate sealed, 'false' for mutable.
    • SealableList

      public SealableList(List<T> list, Supplier<Boolean> sealedSupplier)
      Use this constructor to wrap a List (any kind of List) and make it a SealableList. No duplicate of the List is created and the original list is operated on directly if unsealed, or protected from changes if sealed.
      Parameters:
      list - List instance to protect.
      sealedSupplier - Supplier<Boolean> that returns 'true' to indicate sealed, 'false' for mutable.
  • Method Details