Top Description Inners Fields Constructors Methods
org.apache.commons.collections4.list

public Class FixedSizeList<E>

extends AbstractSerializableListDecorator<E>
implements BoundedCollection<E>
Class Inheritance
All Implemented Interfaces
org.apache.commons.collections4.BoundedCollection, java.util.Collection, java.lang.Iterable
Type Parameters
<E>
the type of elements in this collection
Imports
java.util.Collection, .Iterator, .List, .ListIterator, java.util.function.Predicate, org.apache.commons.collections4.BoundedCollection, org.apache.commons.collections4.iterators.AbstractListIteratorDecorator, .UnmodifiableIterator

Decorates another List to fix the size preventing add/remove.

The add, remove, clear and retain operations are unsupported. The set method is allowed (as it doesn't change the list size).

Note

Modifying the decorated list directly would results in influencing the outcome of method calls on this object. For example, the bounds of this list would reflect a newly added object to the underlying list.

This class is Serializable from Commons Collections 3.1.

Since
3.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
FixedSizeList.FixedSizeListIterator

List iterator that only permits changes via set()

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
protected
FixedSizeList(final List<E>
the list to decorate, must not be null
list
)

Constructor that wraps (not copies).

Method Summary

Modifier and TypeMethod and Description
public boolean
add(final E
element whose presence in this collection is to be ensured
object
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.add.

Implements java.util.Collection.add, java.util.List.add.

Ensures that this collection contains the specified element (optional operation).
public void
add(final int
index at which the specified element is to be inserted
index
,
final E
element to be inserted
object
)

Overrides org.apache.commons.collections4.list.AbstractListDecorator.add.

Implements java.util.List.add.

Inserts the specified element at the specified position in this list (optional operation).
public boolean
addAll(final Collection<? extends E>
collection containing elements to be added to this collection
coll
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.addAll.

Implements java.util.Collection.addAll, java.util.List.addAll.

Adds all of the elements in the specified collection to this collection (optional operation).
public boolean
addAll(final int
index at which to insert the first element from the specified collection
index
,
final Collection<? extends E>
collection containing elements to be added to this list
coll
)

Overrides org.apache.commons.collections4.list.AbstractListDecorator.addAll.

Implements java.util.List.addAll.

Inserts all of the elements in the specified collection into this list at the specified position (optional operation).
public void
clear()

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.clear.

Implements java.util.Collection.clear, java.util.List.clear.

Removes all of the elements from this collection (optional operation).
public static <
the type of the elements in the list
E
>
FixedSizeList<E>

Returns:

a new fixed size list
fixedSizeList
(final List<E>
the list to decorate, must not be null
list
)

Factory method to create a fixed size list.

public E
get(final int
index of the element to return
index
)

Overrides org.apache.commons.collections4.list.AbstractListDecorator.get.

Implements java.util.List.get.

Returns the element at the specified position in this list.
public int
indexOf(final Object
element to search for
object
)

Overrides org.apache.commons.collections4.list.AbstractListDecorator.indexOf.

Implements java.util.List.indexOf.

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
public boolean
isFull()

Implements org.apache.commons.collections4.BoundedCollection.isFull.

Returns true if this collection is full and no new elements can be added.
public Iterator<E>
public int
lastIndexOf(final Object
element to search for
object
)

Overrides org.apache.commons.collections4.list.AbstractListDecorator.lastIndexOf.

Implements java.util.List.lastIndexOf.

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.
public ListIterator<E>
listIterator()

Overrides org.apache.commons.collections4.list.AbstractListDecorator.listIterator.

Implements java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence).
public ListIterator<E>
listIterator(final int
index of the first element to be returned from the list iterator (by a call to next)
index
)

Overrides org.apache.commons.collections4.list.AbstractListDecorator.listIterator.

Implements java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.
public int
maxSize()

Implements org.apache.commons.collections4.BoundedCollection.maxSize.

Gets the maximum size of the collection (the bound).
public E
remove(final int
the index of the element to be removed
index
)

Overrides org.apache.commons.collections4.list.AbstractListDecorator.remove.

Implements java.util.List.remove.

Removes the element at the specified position in this list (optional operation).
public boolean
remove(final Object
element to be removed from this collection, if present
object
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.remove.

Implements java.util.Collection.remove, java.util.List.remove.

Removes a single instance of the specified element from this collection, if it is present (optional operation).
public boolean
removeAll(final Collection<?>
collection containing elements to be removed from this collection
coll
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.removeAll.

Implements java.util.Collection.removeAll, java.util.List.removeAll.

Removes all of this collection's elements that are also contained in the specified collection (optional operation).
public boolean
removeIf(Predicate<? super E>
a predicate which returns true for elements to be removed
filter
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.removeIf.

Overrides default java.util.Collection.removeIf.

Removes all of the elements of this collection that satisfy the given predicate.
public boolean
retainAll(final Collection<?>
collection containing elements to be retained in this collection
coll
)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.retainAll.

Implements java.util.Collection.retainAll, java.util.List.retainAll.

Retains only the elements in this collection that are contained in the specified collection (optional operation).
public E
set(final int
index of the element to replace
index
,
final E
element to be stored at the specified position
object
)

Overrides org.apache.commons.collections4.list.AbstractListDecorator.set.

Implements java.util.List.set.

Replaces the element at the specified position in this list with the specified element (optional operation).
public List<E>
subList(final int
low endpoint (inclusive) of the subList
fromIndex
,
final int
high endpoint (exclusive) of the subList
toIndex
)

Overrides org.apache.commons.collections4.list.AbstractListDecorator.subList.

Implements java.util.List.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
private static UnsupportedOperationException

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.collections4.list.AbstractSerializableListDecorator.serialVersionUID.

Serialization version

Constructor Detail

FixedSizeListback to summary
protected FixedSizeList(final List<E> list)

Constructor that wraps (not copies).

Parameters
list:List<E>

the list to decorate, must not be null

Exceptions
NullPointerException:
if list is null

Method Detail

addback to summary
public boolean add(final E object)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.add.

Implements java.util.Collection.add, java.util.List.add.

Doc from java.util.Collection.add.

Ensures that this collection contains the specified element (optional operation). Returns true if this collection changed as a result of the call. (Returns false if this collection does not permit duplicates and already contains the specified element.)

Collections that support this operation may place limitations on what elements may be added to this collection. In particular, some collections will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. Collection classes should clearly specify in their documentation any restrictions on what elements may be added.

If a collection refuses to add a particular element for any reason other than that it already contains the element, it must throw an exception (rather than returning false). This preserves the invariant that a collection always contains the specified element after this call returns.

Parameters
object:E

element whose presence in this collection is to be ensured

Returns:boolean

true if this collection changed as a result of the call

Annotations
@Override
addback to summary
public void add(final int index, final E object)

Overrides org.apache.commons.collections4.list.AbstractListDecorator.add.

Implements java.util.List.add.

Doc from java.util.List.add.

Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Parameters
index:int

index at which the specified element is to be inserted

object:E

element to be inserted

Annotations
@Override
addAllback to summary
public boolean addAll(final Collection<? extends E> coll)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.addAll.

Implements java.util.Collection.addAll, java.util.List.addAll.

Doc from java.util.Collection.addAll.

Adds all of the elements in the specified collection to this collection (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this collection, and this collection is nonempty.) If the specified collection has a defined encounter order, processing of its elements generally occurs in that order.

Parameters
coll:Collection<? extends E>

collection containing elements to be added to this collection

Returns:boolean

true if this collection changed as a result of the call

Annotations
@Override
addAllback to summary
public boolean addAll(final int index, final Collection<? extends E> coll)

Overrides org.apache.commons.collections4.list.AbstractListDecorator.addAll.

Implements java.util.List.addAll.

Doc from java.util.List.addAll.

Inserts all of the elements in the specified collection into this list at the specified position (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in this list in the order that they are returned by the specified collection's iterator. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)

Parameters
index:int

index at which to insert the first element from the specified collection

coll:Collection<? extends E>

collection containing elements to be added to this list

Returns:boolean

true if this list changed as a result of the call

Annotations
@Override
clearback to summary
public void clear()

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.clear.

Implements java.util.Collection.clear, java.util.List.clear.

Doc from java.util.Collection.clear.

Removes all of the elements from this collection (optional operation). The collection will be empty after this method returns.

Annotations
@Override
fixedSizeListback to summary
public static <E> FixedSizeList<E> fixedSizeList(final List<E> list)

Factory method to create a fixed size list.

Parameters
<E>
the type of the elements in the list
list:List<E>

the list to decorate, must not be null

Returns:FixedSizeList<E>

a new fixed size list

Exceptions
NullPointerException:
if list is null
Since
4.0
getback to summary
public E get(final int index)

Overrides org.apache.commons.collections4.list.AbstractListDecorator.get.

Implements java.util.List.get.

Doc from java.util.List.get.

Returns the element at the specified position in this list.

Parameters
index:int

index of the element to return

Returns:E

the element at the specified position in this list

Annotations
@Override
indexOfback to summary
public int indexOf(final Object object)

Overrides org.apache.commons.collections4.list.AbstractListDecorator.indexOf.

Implements java.util.List.indexOf.

Doc from java.util.List.indexOf.

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that Objects.equals(o, get(i)), or -1 if there is no such index.

Parameters
object:Object

element to search for

Returns:int

the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element

Annotations
@Override
isFullback to summary
public boolean isFull()

Implements org.apache.commons.collections4.BoundedCollection.isFull.

Doc from org.apache.commons.collections4.BoundedCollection.isFull.

Returns true if this collection is full and no new elements can be added.

Returns:boolean

true if the collection is full.

Annotations
@Override
iteratorback to summary
public Iterator<E> iterator()

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.iterator.

Implements java.util.Collection.iterator, java.util.List.iterator.

Doc from java.util.Collection.iterator.

Returns an iterator over the elements in this collection. There are no guarantees concerning the order in which the elements are returned (unless this collection is an instance of some class that provides a guarantee).

Returns:Iterator<E>

an Iterator over the elements in this collection

Annotations
@Override
lastIndexOfback to summary
public int lastIndexOf(final Object object)

Overrides org.apache.commons.collections4.list.AbstractListDecorator.lastIndexOf.

Implements java.util.List.lastIndexOf.

Doc from java.util.List.lastIndexOf.

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the highest index i such that Objects.equals(o, get(i)), or -1 if there is no such index.

Parameters
object:Object

element to search for

Returns:int

the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element

Annotations
@Override
listIteratorback to summary
public ListIterator<E> listIterator()

Overrides org.apache.commons.collections4.list.AbstractListDecorator.listIterator.

Implements java.util.List.listIterator.

Doc from java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence).

Returns:ListIterator<E>

a list iterator over the elements in this list (in proper sequence)

Annotations
@Override
listIteratorback to summary
public ListIterator<E> listIterator(final int index)

Overrides org.apache.commons.collections4.list.AbstractListDecorator.listIterator.

Implements java.util.List.listIterator.

Doc from java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list. The specified index indicates the first element that would be returned by an initial call to next. An initial call to previous would return the element with the specified index minus one.

Parameters
index:int

index of the first element to be returned from the list iterator (by a call to next)

Returns:ListIterator<E>

a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list

Annotations
@Override
maxSizeback to summary
public int maxSize()

Implements org.apache.commons.collections4.BoundedCollection.maxSize.

Doc from org.apache.commons.collections4.BoundedCollection.maxSize.

Gets the maximum size of the collection (the bound).

Returns:int

the maximum number of elements the collection can hold.

Annotations
@Override
removeback to summary
public E remove(final int index)

Overrides org.apache.commons.collections4.list.AbstractListDecorator.remove.

Implements java.util.List.remove.

Doc from java.util.List.remove.

Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.

Parameters
index:int

the index of the element to be removed

Returns:E

the element previously at the specified position

Annotations
@Override
removeback to summary
public boolean remove(final Object object)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.remove.

Implements java.util.Collection.remove, java.util.List.remove.

Doc from java.util.Collection.remove.

Removes a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an element e such that Objects.equals(o, e), if this collection contains one or more such elements. Returns true if this collection contained the specified element (or equivalently, if this collection changed as a result of the call).

Parameters
object:Object

element to be removed from this collection, if present

Returns:boolean

true if an element was removed as a result of this call

Annotations
@Override
removeAllback to summary
public boolean removeAll(final Collection<?> coll)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.removeAll.

Implements java.util.Collection.removeAll, java.util.List.removeAll.

Doc from java.util.Collection.removeAll.

Removes all of this collection's elements that are also contained in the specified collection (optional operation). After this call returns, this collection will contain no elements in common with the specified collection.

Parameters
coll:Collection<?>

collection containing elements to be removed from this collection

Returns:boolean

true if this collection changed as a result of the call

Annotations
@Override
removeIfback to summary
public boolean removeIf(Predicate<? super E> filter)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.removeIf.

Overrides default java.util.Collection.removeIf.

Doc from java.util.Collection.removeIf.

Removes all of the elements of this collection that satisfy the given predicate. Errors or runtime exceptions thrown during iteration or by the predicate are relayed to the caller.

Parameters
filter:Predicate<? super E>

a predicate which returns true for elements to be removed

Returns:boolean

true if any elements were removed

Annotations
@Override
Since
4.4
retainAllback to summary
public boolean retainAll(final Collection<?> coll)

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.retainAll.

Implements java.util.Collection.retainAll, java.util.List.retainAll.

Doc from java.util.Collection.retainAll.

Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection.

Parameters
coll:Collection<?>

collection containing elements to be retained in this collection

Returns:boolean

true if this collection changed as a result of the call

Annotations
@Override
setback to summary
public E set(final int index, final E object)

Overrides org.apache.commons.collections4.list.AbstractListDecorator.set.

Implements java.util.List.set.

Doc from java.util.List.set.

Replaces the element at the specified position in this list with the specified element (optional operation).

Parameters
index:int

index of the element to replace

object:E

element to be stored at the specified position

Returns:E

the element previously at the specified position

Annotations
@Override
subListback to summary
public List<E> subList(final int fromIndex, final int toIndex)

Overrides org.apache.commons.collections4.list.AbstractListDecorator.subList.

Implements java.util.List.subList.

Doc from java.util.List.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned list is empty.) The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of the optional list operations supported by this list.

This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays). Any operation that expects a list can be used as a range operation by passing a subList view instead of a whole list. For example, the following idiom removes a range of elements from a list:

list.subList(from, to).clear();
Similar idioms may be constructed for indexOf and lastIndexOf, and all of the algorithms in the Collections class can be applied to a subList.

The semantics of the list returned by this method become undefined if the backing list (i.e., this list) is structurally modified in any way other than via the returned list. (Structural modifications are those that change the size of this list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)

Parameters
fromIndex:int

low endpoint (inclusive) of the subList

toIndex:int

high endpoint (exclusive) of the subList

Returns:List<E>

a view of the specified range within this list

Annotations
@Override
unsupportedOperationExceptionback to summary
private static UnsupportedOperationException unsupportedOperationException()
org.apache.commons.collections4.list back to summary

private Class FixedSizeList.FixedSizeListIterator

extends AbstractListIteratorDecorator<E>
Class Inheritance

List iterator that only permits changes via set()

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public void
add(final Object
the element to insert
object
)

Overrides org.apache.commons.collections4.iterators.AbstractListIteratorDecorator.add.

Implements java.util.ListIterator.add.

Inserts the specified element into the list (optional operation).
public void
remove()

Overrides org.apache.commons.collections4.iterators.AbstractListIteratorDecorator.remove.

Implements java.util.ListIterator.remove.

Removes from the list the last element that was returned by next or previous (optional operation).
Inherited from org.apache.commons.collections4.iterators.AbstractListIteratorDecorator:
getListIteratorhasNexthasPreviousnextnextIndexpreviouspreviousIndexset

Constructor Detail

FixedSizeListIteratorback to summary
protected FixedSizeListIterator(final ListIterator<E> iterator)

Method Detail

addback to summary
public void add(final Object object)

Overrides org.apache.commons.collections4.iterators.AbstractListIteratorDecorator.add.

Implements java.util.ListIterator.add.

Doc from org.apache.commons.collections4.iterators.AbstractListIteratorDecorator.add.

Inserts the specified element into the list (optional operation). The element is inserted immediately before the element that would be returned by next, if any, and after the element that would be returned by previous, if any. (If the list contains no elements, the new element becomes the sole element on the list.) The new element is inserted before the implicit cursor: a subsequent call to next would be unaffected, and a subsequent call to previous would return the new element. (This call increases by one the value that would be returned by a call to nextIndex or previousIndex.)

Parameters
object:Object

Doc from java.util.ListIterator.add.

the element to insert

Annotations
@Override
removeback to summary
public void remove()

Overrides org.apache.commons.collections4.iterators.AbstractListIteratorDecorator.remove.

Implements java.util.ListIterator.remove.

Doc from org.apache.commons.collections4.iterators.AbstractListIteratorDecorator.remove.

Removes from the list the last element that was returned by next or previous (optional operation). This call can only be made once per call to next or previous. It can be made only if add has not been called after the last call to next or previous.

Annotations
@Override