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
ConstructorDescriptionControlledArrayList
(boolean unmodifiable) Constructor.ControlledArrayList
(boolean unmodifiable, List<? extends E> list) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
boolean
addAll
(int index, Collection<? extends E> c) boolean
addAll
(Collection<? extends E> c) protected final void
Throws anUnsupportedOperationException
if the unmodifiable flag is set on this bean.void
clear()
boolean
Returnstrue if this list is modifiable.iterator()
listIterator
(int index) void
overrideAdd
(int index, E element) Same asadd(int, Object)
but bypasses the modifiable flag.boolean
overrideAdd
(E element) Same asadd(Object)
but bypasses the modifiable flag.boolean
overrideAddAll
(int index, Collection<? extends E> c) Same asaddAll(int,Collection)
but bypasses the modifiable flag.boolean
overrideAddAll
(Collection<? extends E> c) Same asaddAll(Collection)
but bypasses the modifiable flag.void
Same 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.boolean
Same asremove(Object)
but bypasses the modifiable flag.boolean
overrideRemoveAll
(Collection<?> c) Same asremoveAll(Collection)
but bypasses the modifiable flag.boolean
overrideRemoveIf
(Predicate<? super E> filter) Same asremoveIf(Predicate)
but bypasses the modifiable flag.void
overrideReplaceAll
(UnaryOperator<E> operator) Same asreplaceAll(UnaryOperator)
but bypasses the modifiable flag.boolean
overrideRetainAll
(Collection<?> c) Same asretainAll(Collection)
but bypasses the modifiable flag.overrideSet
(int index, E element) Same asset(int, Object)
but bypasses the modifiable flag.void
overrideSort
(Comparator<? super E> c) Same asoverrideSort(Comparator)
but bypasses the modifiable flag.remove
(int index) boolean
boolean
removeAll
(Collection<?> coll) boolean
void
replaceAll
(UnaryOperator<E> operator) boolean
retainAll
(Collection<?> c) Specifies whether this bean should be unmodifiable.void
sort
(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, trimToSize
Methods inherited from class java.util.AbstractCollection
containsAll, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
Methods 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 theList
interface.
-
ControlledArrayList
Constructor.- Parameters:
unmodifiable
- Iftrue , this list cannot be modified through normal list operation methods on theList
interface.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 anUnsupportedOperationException
if 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:
replaceAll
in interfaceList<E>
- Overrides:
replaceAll
in 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:
listIterator
in interfaceList<E>
- Overrides:
listIterator
in classArrayList<E>
-
listIterator
- Specified by:
listIterator
in interfaceList<E>
- Overrides:
listIterator
in 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.
-