Package com.cedarsoftware.util
Class SealableList<T>
java.lang.Object
com.cedarsoftware.util.SealableList<T>
- All Implemented Interfaces:
Iterable<T>
,Collection<T>
,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.
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 Summary
ConstructorsConstructorDescriptionSealableList
(Collection<T> col, Supplier<Boolean> sealedSupplier) Create a SealableList.SealableList
(Supplier<Boolean> sealedSupplier) Create a SealableList.SealableList
(List<T> list, Supplier<Boolean> sealedSupplier) Use this constructor to wrap a List (any kind of List) and make it a SealableList. -
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
boolean
addAll
(int index, Collection<? extends T> col) boolean
addAll
(Collection<? extends T> col) void
clear()
boolean
boolean
containsAll
(Collection<?> col) boolean
get
(int index) int
hashCode()
int
boolean
isEmpty()
iterator()
int
listIterator
(int index) remove
(int index) boolean
boolean
removeAll
(Collection<?> col) boolean
retainAll
(Collection<?> col) int
size()
subList
(int fromIndex, int toIndex) 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
Methods inherited from interface java.util.List
replaceAll, sort, spliterator
-
Constructor Details
-
SealableList
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
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
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
-
equals
-
hashCode
public int hashCode() -
toString
-
size
public int size() -
isEmpty
public boolean isEmpty() -
contains
-
containsAll
- Specified by:
containsAll
in interfaceCollection<T>
- Specified by:
containsAll
in interfaceList<T>
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOf
in interfaceList<T>
-
get
-
toArray
-
toArray
public <T1> T1[] toArray(T1[] a) -
iterator
-
listIterator
- Specified by:
listIterator
in interfaceList<T>
-
listIterator
- Specified by:
listIterator
in interfaceList<T>
-
subList
-
add
-
remove
-
addAll
-
addAll
-
removeAll
-
retainAll
-
clear
public void clear() -
set
-
add
-
remove
-