Package org.apache.juneau.collections
Class ControlledArrayList<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.ArrayList<E>
org.apache.juneau.collections.ControlledArrayList<E>
- Type Parameters:
E- The element type.
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<E>,Collection<E>,List<E>,RandomAccess
- Direct Known Subclasses:
HeaderList,PartList
An array list that allows you to control whether it's read-only via a constructor parameter.
Override methods such as overrideAdd(int, Object) are provided that bypass the unmodifiable restriction
on the list. They allow you to manipulate the list while not exposing the ability to manipulate the list through
any of the methods provided by the List interface (meaning you can pass the object around as an unmodifiable List).
- See Also:
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionControlledArrayList(boolean unmodifiable) Constructor.ControlledArrayList(boolean unmodifiable, List<? extends E> list) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanbooleanaddAll(int index, Collection<? extends E> c) booleanaddAll(Collection<? extends E> c) protected final voidThrows anUnsupportedOperationExceptionif the unmodifiable flag is set on this bean.voidclear()booleanReturnstrue if this list is modifiable.iterator()listIterator(int index) voidoverrideAdd(int index, E element) Same asadd(int, Object)but bypasses the modifiable flag.booleanoverrideAdd(E element) Same asadd(Object)but bypasses the modifiable flag.booleanoverrideAddAll(int index, Collection<? extends E> c) Same asaddAll(int,Collection)but bypasses the modifiable flag.booleanoverrideAddAll(Collection<? extends E> c) Same asaddAll(Collection)but bypasses the modifiable flag.voidSame asclear()but bypasses the modifiable flag.Same asiterator()but bypasses the modifiable flag.overrideListIterator(int index) Same aslistIterator()but bypasses the modifiable flag.overrideRemove(int index) Same asremove(int)but bypasses the modifiable flag.booleanSame asremove(Object)but bypasses the modifiable flag.booleanoverrideRemoveAll(Collection<?> c) Same asremoveAll(Collection)but bypasses the modifiable flag.booleanoverrideRemoveIf(Predicate<? super E> filter) Same asremoveIf(Predicate)but bypasses the modifiable flag.voidoverrideReplaceAll(UnaryOperator<E> operator) Same asreplaceAll(UnaryOperator)but bypasses the modifiable flag.booleanoverrideRetainAll(Collection<?> c) Same asretainAll(Collection)but bypasses the modifiable flag.overrideSet(int index, E element) Same asset(int, Object)but bypasses the modifiable flag.voidoverrideSort(Comparator<? super E> c) Same asoverrideSort(Comparator)but bypasses the modifiable flag.remove(int index) booleanbooleanremoveAll(Collection<?> coll) booleanvoidreplaceAll(UnaryOperator<E> operator) booleanretainAll(Collection<?> c) Specifies whether this bean should be unmodifiable.voidsort(Comparator<? super E> c) subList(int fromIndex, int toIndex) Methods inherited from class java.util.ArrayList
clone, contains, ensureCapacity, equals, forEach, get, hashCode, indexOf, isEmpty, lastIndexOf, removeRange, size, spliterator, toArray, toArray, trimToSizeMethods inherited from class java.util.AbstractCollection
containsAll, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, stream, toArrayMethods inherited from interface java.util.List
containsAll
-
Constructor Details
-
ControlledArrayList
Constructor.- Parameters:
unmodifiable- Iftrue , this list cannot be modified through normal list operation methods on theListinterface.
-
ControlledArrayList
Constructor.- Parameters:
unmodifiable- Iftrue , this list cannot be modified through normal list operation methods on theListinterface.list- The initial contents of this list.
-
-
Method Details
-
setUnmodifiable
Specifies whether this bean should be unmodifiable.When enabled, attempting to set any properties on this bean will cause an
UnsupportedOperationException.- Returns:
- This object.
-
assertModifiable
Throws anUnsupportedOperationExceptionif the unmodifiable flag is set on this bean. -
isModifiable
Returnstrue if this list is modifiable.- Returns:
true if this list is modifiable.
-
set
-
overrideSet
Same asset(int, Object)but bypasses the modifiable flag.- Parameters:
index- Index of the element to replace.element- Element to be stored at the specified position.- Returns:
- The element previously at the specified position.
-
add
-
overrideAdd
Same asadd(int, Object)but bypasses the modifiable flag.- Parameters:
index- Index of the element to replace.element- Element to be stored at the specified position.
-
remove
-
overrideRemove
Same asremove(int)but bypasses the modifiable flag.- Parameters:
index- Index of the element to remove.- Returns:
- The element that was removed from the list.
-
addAll
-
overrideAddAll
Same asaddAll(int,Collection)but bypasses the modifiable flag.- Parameters:
index- Index at which to insert the first element from the specified collection.c- Collection containing elements to be added to this list.- Returns:
true if this list changed as a result of the call.
-
replaceAll
- Specified by:
replaceAllin interfaceList<E>- Overrides:
replaceAllin classArrayList<E>
-
overrideReplaceAll
Same asreplaceAll(UnaryOperator)but bypasses the modifiable flag.- Parameters:
operator- The operator to apply to each element.
-
sort
-
overrideSort
Same asoverrideSort(Comparator)but bypasses the modifiable flag.- Parameters:
c- The Comparator used to compare list elements. A null value indicates that the elements' natural ordering should be used.
-
add
-
overrideAdd
Same asadd(Object)but bypasses the modifiable flag.- Parameters:
element- Element to be stored at the specified position.- Returns:
true .
-
remove
-
overrideRemove
Same asremove(Object)but bypasses the modifiable flag.- Parameters:
o- Element to be removed from this list, if present.- Returns:
true if this list contained the specified element.
-
addAll
-
overrideAddAll
Same asaddAll(Collection)but bypasses the modifiable flag.- Parameters:
c- Collection containing elements to be added to this list.- Returns:
true if this list changed as a result of the call.
-
removeAll
-
overrideRemoveAll
Same asremoveAll(Collection)but bypasses the modifiable flag.- Parameters:
c- Collection containing elements to be removed from this list.- Returns:
true if this list changed as a result of the call.
-
retainAll
-
overrideRetainAll
Same asretainAll(Collection)but bypasses the modifiable flag.- Parameters:
c- Collection containing elements to be retained in this list.- Returns:
true if this list changed as a result of the call.
-
clear
-
overrideClear
Same asclear()but bypasses the modifiable flag. -
removeIf
-
overrideRemoveIf
Same asremoveIf(Predicate)but bypasses the modifiable flag.- Parameters:
filter- A predicate which returns true for elements to be removed.- Returns:
true if any elements were removed.
-
subList
-
listIterator
- Specified by:
listIteratorin interfaceList<E>- Overrides:
listIteratorin classArrayList<E>
-
listIterator
- Specified by:
listIteratorin interfaceList<E>- Overrides:
listIteratorin classArrayList<E>
-
overrideListIterator
Same aslistIterator()but bypasses the modifiable flag.- Parameters:
index- Index of the first element to be returned from the list iterator.- Returns:
- A list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.
-
iterator
-
overrideIterator
Same asiterator()but bypasses the modifiable flag.- Returns:
- An iterator over the elements in this list in proper sequence.
-