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

public Class ListUtils

extends Object
Class Inheritance
Imports
java.util.AbstractList, .ArrayList, .Collection, .Collections, .HashSet, .Iterator, .List, org.apache.commons.collections4.bag.HashBag, org.apache.commons.collections4.functors.DefaultEquator, org.apache.commons.collections4.list.FixedSizeList, .LazyList, .PredicatedList, .TransformedList, .UnmodifiableList, org.apache.commons.collections4.sequence.CommandVisitor, .EditScript, .SequencesComparator

Provides utility methods and decorators for List instances.
Since
1.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
ListUtils.CharSequenceAsList

A simple wrapper to use a CharSequence as List.

private static class
ListUtils.LcsVisitor<E>

A helper class used to construct the longest common subsequence.

private static class
ListUtils.Partition<T>

Provides a partition view on a List.

Constructor Summary

AccessConstructor and Description
private
ListUtils()

ListUtils should not normally be instantiated.

Method Summary

Modifier and TypeMethod and Description
public static <
the element type
T
>
List<T>

Returns:

an empty list if the argument is null
defaultIfNull
(final List<T>
the list, possibly null
list
,
final List<T>
the returned values if list is null
defaultList
)

Returns either the passed in list, or if the list is null, the value of defaultList.

public static <
the element type
T
>
List<T>

Returns:

an empty list if the argument is null
emptyIfNull
(final List<T>
the list, possibly null
list
)

Returns an immutable empty list if the argument is null, or the argument itself otherwise.

public static <
the element type
E
>
List<E>

Returns:

a fixed-size list backed by that list
fixedSizeList
(final List<E>
the list whose size to fix, must not be null
list
)

Returns a fixed-sized list backed by the given list.

public static int

Returns:

the hash code
hashCodeForList
(final Collection<?>
the list to generate the hashCode for, may be null
list
)

Generates a hash code using the algorithm specified in java.util.List#hashCode().

public static <
the element type
E
>
int

Returns:

the first index of an Object in the List which matches the predicate or -1 if none could be found
indexOf
(final List<E>
the List to search, may be null
list
,
final Predicate<E>
the predicate to use, may be null
predicate
)

Finds the first index in the given List which matches the given predicate.

public static <
the element type
E
>
List<E>

Returns:

the intersection of those two lists
intersection
(final List<? extends E>
the first list
list1
,
final List<? extends E>
the second list
list2
)

Returns a new list containing all elements that are contained in both given lists.

public static boolean

Returns:

whether the lists are equal by value comparison
isEqualList
(final Collection<?>
the first list, may be null
list1
,
final Collection<?>
the second list, may be null
list2
)

Tests two lists for value-equality as per the equality contract in java.util.List#equals(java.lang.Object).

public static <
the element type
E
>
List<E>

Returns:

a lazy list backed by the given list
lazyList
(final List<E>
the list to make lazy, must not be null
list
,
final Factory<? extends E>
the factory for creating new objects, must not be null
factory
)

Returns a "lazy" list whose elements will be created on demand.

public static <
the element type
E
>
List<E>

Returns:

a lazy list backed by the given list
lazyList
(final List<E>
the list to make lazy, must not be null
list
,
final Transformer<Integer, ? extends E>
the transformer for creating new objects, must not be null
transformer
)

Returns a "lazy" list whose elements will be created on demand.

public static <
the element type
E
>
List<E>

Returns:

the longest common subsequence
longestCommonSubsequence
(final List<E>
the first list
a
,
final List<E>
the second list
b
)

Returns the longest common subsequence (LCS) of two sequences (lists).

public static <
the element type
E
>
List<E>

Returns:

the longest common subsequence
longestCommonSubsequence
(final List<E>
the first list
a
,
final List<E>
the second list
b
,
final Equator<? super E>
the equator used to test object equality
equator
)

Returns the longest common subsequence (LCS) of two sequences (lists).

public static String

Returns:

the longest common subsequence as String
longestCommonSubsequence
(final CharSequence
the first sequence
a
,
final CharSequence
the second sequence
b
)

Returns the longest common subsequence (LCS) of two CharSequence objects.

public static <
the element type
T
>
List<List<T>>

Returns:

a list of consecutive sublists
partition
(final List<T>
the list to return consecutive sublists of
list
,
final int
the desired size of each sublist (the last may be smaller)
size
)

Returns consecutive sublists of a list, each of the same size (the final list may be smaller).

public static <
the element type
E
>
List<E>

Returns:

a predicated list backed by the given list
predicatedList
(final List<E>
the list to predicate, must not be null
list
,
final Predicate<E>
the predicate for the list, must not be null
predicate
)

Returns a predicated (validating) list backed by the given list.

public static <
the element type
E
>
List<E>

Returns:

a List containing all the elements of c except any elements that also occur in remove.
removeAll
(final Collection<E>
the collection from which items are removed (in the returned collection)
collection
,
final Collection<?>
the items to be removed from the returned collection
remove
)

Removes the elements in remove from collection.

public static <
the element type
E
>
List<E>

Returns:

a List containing all the elements of c that occur at least once in retain.
retainAll
(final Collection<E>
the collection whose contents are the target of the #retailAll operation
collection
,
final Collection<?>
the collection containing the elements to be retained in the returned collection
retain
)

Returns a List containing all the elements in collection that are also in retain.

public static <
the element type
E
>
List<E>

Returns:

the elements matching the predicate (new list)
select
(final Collection<? extends E>
the collection to get the input from, may not be null
inputCollection
,
final Predicate<? super E>
the predicate to use, may be null
predicate
)

Selects all elements from input collection which match the given predicate into an output list.

public static <
the element type
E
>
List<E>

Returns:

the elements not matching the predicate (new list)
selectRejected
(final Collection<? extends E>
the collection to get the input from, may not be null
inputCollection
,
final Predicate<? super E>
the predicate to use, may be null
predicate
)

Selects all elements from inputCollection which don't match the given predicate into an output collection.

public static <
the element type
E
>
List<E>

Returns:

a new list containing the results
subtract
(final List<E>
the list to subtract from
list1
,
final List<? extends E>
the list to subtract
list2
)

Subtracts all elements in the second list from the first list, placing the results in a new list.

public static <
the element type
E
>
List<E>

Returns:

a new list containing the sum of those lists
sum
(final List<? extends E>
the first list
list1
,
final List<? extends E>
the second list
list2
)

Returns the sum of the given lists.

public static <
the element type
E
>
List<E>

Returns:

a synchronized list backed by the given list
synchronizedList
(final List<E>
the list to synchronize, must not be null
list
)

Returns a synchronized list backed by the given list.

public static <
the element type
E
>
List<E>

Returns:

a transformed list backed by the given list
transformedList
(final List<E>
the list to predicate, must not be null
list
,
final Transformer<? super E, ? extends E>
the transformer for the list, must not be null
transformer
)

Returns a transformed list backed by the given list.

public static <
the element type
E
>
List<E>

Returns:

a new list containing the union of those lists
union
(final List<? extends E>
the first list
list1
,
final List<? extends E>
the second list
list2
)

Returns a new list containing the second list appended to the first list.

public static <
the element type
E
>
List<E>

Returns:

an unmodifiable list backed by the given list
unmodifiableList
(final List<? extends E>
the list to make unmodifiable, must not be null
list
)

Returns an unmodifiable list backed by the given list.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ListUtilsback to summary
private ListUtils()

ListUtils should not normally be instantiated.

Method Detail

defaultIfNullback to summary
public static <T> List<T> defaultIfNull(final List<T> list, final List<T> defaultList)

Returns either the passed in list, or if the list is null, the value of defaultList.

Parameters
<T>
the element type
list:List<T>

the list, possibly null

defaultList:List<T>

the returned values if list is null

Returns:List<T>

an empty list if the argument is null

Since
4.0
emptyIfNullback to summary
public static <T> List<T> emptyIfNull(final List<T> list)

Returns an immutable empty list if the argument is null, or the argument itself otherwise.

Parameters
<T>
the element type
list:List<T>

the list, possibly null

Returns:List<T>

an empty list if the argument is null

fixedSizeListback to summary
public static <E> List<E> fixedSizeList(final List<E> list)

Returns a fixed-sized list backed by the given list. Elements may not be added or removed from the returned list, but existing elements can be changed (for instance, via the List#set(int, Object) method).

Parameters
<E>
the element type
list:List<E>

the list whose size to fix, must not be null

Returns:List<E>

a fixed-size list backed by that list

Exceptions
NullPointerException:
if the List is null
hashCodeForListback to summary
public static int hashCodeForList(final Collection<?> list)

Generates a hash code using the algorithm specified in java.util.List#hashCode().

This method is useful for implementing List when you cannot extend AbstractList. The method takes Collection instances to enable other collection types to use the List implementation algorithm.

Parameters
list:Collection<?>

the list to generate the hashCode for, may be null

Returns:int

the hash code

See Also
java.util.List#hashCode()
indexOfback to summary
public static <E> int indexOf(final List<E> list, final Predicate<E> predicate)

Finds the first index in the given List which matches the given predicate.

If the input List or predicate is null, or no element of the List matches the predicate, -1 is returned.

Parameters
<E>
the element type
list:List<E>

the List to search, may be null

predicate:Predicate<E>

the predicate to use, may be null

Returns:int

the first index of an Object in the List which matches the predicate or -1 if none could be found

intersectionback to summary
public static <E> List<E> intersection(final List<? extends E> list1, final List<? extends E> list2)

Returns a new list containing all elements that are contained in both given lists.

Parameters
<E>
the element type
list1:List<? extends E>

the first list

list2:List<? extends E>

the second list

Returns:List<E>

the intersection of those two lists

Exceptions
NullPointerException:
if either list is null
isEqualListback to summary
public static boolean isEqualList(final Collection<?> list1, final Collection<?> list2)

Tests two lists for value-equality as per the equality contract in java.util.List#equals(java.lang.Object).

This method is useful for implementing List when you cannot extend AbstractList. The method takes Collection instances to enable other collection types to use the List implementation algorithm.

The relevant text (slightly paraphrased as this is a static method) is:

Compares the two list objects for equality. Returns true if and only if both lists have the same size, and all corresponding pairs of elements in the two lists are equal. (Two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).) In other words, two lists are defined to be equal if they contain the same elements in the same order. This definition ensures that the equals method works properly across different implementations of the List interface.

Note

The behaviour of this method is undefined if the lists are modified during the equals comparison.

Parameters
list1:Collection<?>

the first list, may be null

list2:Collection<?>

the second list, may be null

Returns:boolean

whether the lists are equal by value comparison

See Also
java.util.List
lazyListback to summary
public static <E> List<E> lazyList(final List<E> list, final Factory<? extends E> factory)

Returns a "lazy" list whose elements will be created on demand.

When the index passed to the returned list's get method is greater than the list's size, then the factory will be used to create a new object and that object will be inserted at that index.

For instance:

Factory<Date> factory = new Factory<Date>() {
    public Date create() {
        return new Date();
    }
}
List<Date> lazy = ListUtils.lazyList(new ArrayList<Date>(), factory);
Date date = lazy.get(3);
After the above code is executed, date will refer to a new Date instance. Furthermore, that Date instance is the fourth element in the list. The first, second, and third element are all set to null.
Parameters
<E>
the element type
list:List<E>

the list to make lazy, must not be null

factory:Factory<? extends E>

the factory for creating new objects, must not be null

Returns:List<E>

a lazy list backed by the given list

Exceptions
NullPointerException:
if the List or Factory is null
lazyListback to summary
public static <E> List<E> lazyList(final List<E> list, final Transformer<Integer, ? extends E> transformer)

Returns a "lazy" list whose elements will be created on demand.

When the index passed to the returned list's get method is greater than the list's size, then the transformer will be used to create a new object and that object will be inserted at that index.

For instance:

List<Integer> hours = Arrays.asList(7, 5, 8, 2);
Transformer<Integer,Date> transformer = input -> LocalDateTime.now().withHour(hours.get(input));
List<LocalDateTime> lazy = ListUtils.lazyList(new ArrayList<LocalDateTime>(), transformer);
Date date = lazy.get(3);
After the above code is executed, date will refer to a new Date instance. Furthermore, that Date instance is the fourth element in the list. The first, second, and third element are all set to null.
Parameters
<E>
the element type
list:List<E>

the list to make lazy, must not be null

transformer:Transformer<Integer, ? extends E>

the transformer for creating new objects, must not be null

Returns:List<E>

a lazy list backed by the given list

Exceptions
NullPointerException:
if the List or Transformer is null
longestCommonSubsequenceback to summary
public static <E> List<E> longestCommonSubsequence(final List<E> a, final List<E> b)

Returns the longest common subsequence (LCS) of two sequences (lists).

Parameters
<E>
the element type
a:List<E>

the first list

b:List<E>

the second list

Returns:List<E>

the longest common subsequence

Exceptions
NullPointerException:
if either list is null
Since
4.0
longestCommonSubsequenceback to summary
public static <E> List<E> longestCommonSubsequence(final List<E> a, final List<E> b, final Equator<? super E> equator)

Returns the longest common subsequence (LCS) of two sequences (lists).

Parameters
<E>
the element type
a:List<E>

the first list

b:List<E>

the second list

equator:Equator<? super E>

the equator used to test object equality

Returns:List<E>

the longest common subsequence

Exceptions
NullPointerException:
if either list or the equator is null
Since
4.0
longestCommonSubsequenceback to summary
public static String longestCommonSubsequence(final CharSequence a, final CharSequence b)

Returns the longest common subsequence (LCS) of two CharSequence objects.

This is a convenience method for using longestCommonSubsequence(List, List) with CharSequence instances.

Parameters
a:CharSequence

the first sequence

b:CharSequence

the second sequence

Returns:String

the longest common subsequence as String

Exceptions
NullPointerException:
if either sequence is null
Since
4.0
partitionback to summary
public static <T> List<List<T>> partition(final List<T> list, final int size)

Returns consecutive sublists of a list, each of the same size (the final list may be smaller). For example, partitioning a list containing [a, b, c, d, e] with a partition size of 3 yields [[a, b, c], [d, e]] -- an outer list containing two inner lists of three and two elements, all in the original order.

The outer list is unmodifiable, but reflects the latest state of the source list. The inner lists are sublist views of the original list, produced on demand using List#subList(int, int), and are subject to all the usual caveats about modification as explained in that API.

Adapted from http://code.google.com/p/guava-libraries/

Parameters
<T>
the element type
list:List<T>

the list to return consecutive sublists of

size:int

the desired size of each sublist (the last may be smaller)

Returns:List<List<T>>

a list of consecutive sublists

Exceptions
NullPointerException:
if list is null
IllegalArgumentException:
if size is not strictly positive
Since
4.0
predicatedListback to summary
public static <E> List<E> predicatedList(final List<E> list, final Predicate<E> predicate)

Returns a predicated (validating) list backed by the given list.

Only objects that pass the test in the given predicate can be added to the list. Trying to add an invalid object results in an IllegalArgumentException. It is important not to use the original list after invoking this method, as it is a backdoor for adding invalid objects.

Parameters
<E>
the element type
list:List<E>

the list to predicate, must not be null

predicate:Predicate<E>

the predicate for the list, must not be null

Returns:List<E>

a predicated list backed by the given list

Exceptions
NullPointerException:
if the List or Predicate is null
removeAllback to summary
public static <E> List<E> removeAll(final Collection<E> collection, final Collection<?> remove)

Removes the elements in remove from collection. That is, this method returns a list containing all the elements in collection that are not in remove. The cardinality of an element e in the returned collection is the same as the cardinality of e in collection unless remove contains e, in which case the cardinality is zero. This method is useful if you do not wish to modify collection and thus cannot call collection.removeAll(remove);.

This implementation iterates over collection, checking each element in turn to see if it's contained in remove. If it's not contained, it's added to the returned list. As a consequence, it is advised to use a collection type for remove that provides a fast (e.g. O(1)) implementation of Collection#contains(Object).

Parameters
<E>
the element type
collection:Collection<E>

the collection from which items are removed (in the returned collection)

remove:Collection<?>

the items to be removed from the returned collection

Returns:List<E>

a List containing all the elements of c except any elements that also occur in remove.

Exceptions
NullPointerException:
if either parameter is null
Since
3.2
retainAllback to summary
public static <E> List<E> retainAll(final Collection<E> collection, final Collection<?> retain)

Returns a List containing all the elements in collection that are also in retain. The cardinality of an element e in the returned list is the same as the cardinality of e in collection unless retain does not contain e, in which case the cardinality is zero. This method is useful if you do not wish to modify the collection c and thus cannot call collection.retainAll(retain);.

This implementation iterates over collection, checking each element in turn to see if it's contained in retain. If it's contained, it's added to the returned list. As a consequence, it is advised to use a collection type for retain that provides a fast (e.g. O(1)) implementation of Collection#contains(Object).

Parameters
<E>
the element type
collection:Collection<E>

the collection whose contents are the target of the #retailAll operation

retain:Collection<?>

the collection containing the elements to be retained in the returned collection

Returns:List<E>

a List containing all the elements of c that occur at least once in retain.

Exceptions
NullPointerException:
if either parameter is null
Since
3.2
selectback to summary
public static <E> List<E> select(final Collection<? extends E> inputCollection, final Predicate<? super E> predicate)

Selects all elements from input collection which match the given predicate into an output list.

A null predicate matches no elements.

Parameters
<E>
the element type
inputCollection:Collection<? extends E>

the collection to get the input from, may not be null

predicate:Predicate<? super E>

the predicate to use, may be null

Returns:List<E>

the elements matching the predicate (new list)

Exceptions
NullPointerException:
if the input list is null
Since
4.0
See Also
CollectionUtils#select(Iterable, Predicate)
selectRejectedback to summary
public static <E> List<E> selectRejected(final Collection<? extends E> inputCollection, final Predicate<? super E> predicate)

Selects all elements from inputCollection which don't match the given predicate into an output collection.

If the input predicate is null, the result is an empty list.

Parameters
<E>
the element type
inputCollection:Collection<? extends E>

the collection to get the input from, may not be null

predicate:Predicate<? super E>

the predicate to use, may be null

Returns:List<E>

the elements not matching the predicate (new list)

Exceptions
NullPointerException:
if the input collection is null
Since
4.0
See Also
CollectionUtils#selectRejected(Iterable, Predicate)
subtractback to summary
public static <E> List<E> subtract(final List<E> list1, final List<? extends E> list2)

Subtracts all elements in the second list from the first list, placing the results in a new list.

This differs from List#removeAll(Collection) in that cardinality is respected; if list1 contains two occurrences of null and list2 only contains one occurrence, then the returned list will still contain one occurrence.

Parameters
<E>
the element type
list1:List<E>

the list to subtract from

list2:List<? extends E>

the list to subtract

Returns:List<E>

a new list containing the results

Exceptions
NullPointerException:
if either list is null
sumback to summary
public static <E> List<E> sum(final List<? extends E> list1, final List<? extends E> list2)

Returns the sum of the given lists. This is their intersection subtracted from their union.

Parameters
<E>
the element type
list1:List<? extends E>

the first list

list2:List<? extends E>

the second list

Returns:List<E>

a new list containing the sum of those lists

Exceptions
NullPointerException:
if either list is null
synchronizedListback to summary
public static <E> List<E> synchronizedList(final List<E> list)

Returns a synchronized list backed by the given list.

You must manually synchronize on the returned list's iterator to avoid non-deterministic behavior:

List list = ListUtils.synchronizedList(myList);
synchronized (list) {
    Iterator i = list.iterator();
    while (i.hasNext()) {
        process (i.next());
    }
}
This method is just a wrapper for Collections#synchronizedList(List).
Parameters
<E>
the element type
list:List<E>

the list to synchronize, must not be null

Returns:List<E>

a synchronized list backed by the given list

Exceptions
NullPointerException:
if the list is null
transformedListback to summary
public static <E> List<E> transformedList(final List<E> list, final Transformer<? super E, ? extends E> transformer)

Returns a transformed list backed by the given list.

This method returns a new list (decorating the specified list) that will transform any new entries added to it. Existing entries in the specified list will not be transformed.

Each object is passed through the transformer as it is added to the List. It is important not to use the original list after invoking this method, as it is a backdoor for adding untransformed objects.

Existing entries in the specified list will not be transformed. If you want that behaviour, see TransformedList#transformedList.

Parameters
<E>
the element type
list:List<E>

the list to predicate, must not be null

transformer:Transformer<? super E, ? extends E>

the transformer for the list, must not be null

Returns:List<E>

a transformed list backed by the given list

Exceptions
NullPointerException:
if the List or Transformer is null
unionback to summary
public static <E> List<E> union(final List<? extends E> list1, final List<? extends E> list2)

Returns a new list containing the second list appended to the first list. The List#addAll(Collection) operation is used to append the two given lists into a new list.

Parameters
<E>
the element type
list1:List<? extends E>

the first list

list2:List<? extends E>

the second list

Returns:List<E>

a new list containing the union of those lists

Exceptions
NullPointerException:
if either list is null
unmodifiableListback to summary
public static <E> List<E> unmodifiableList(final List<? extends E> list)

Returns an unmodifiable list backed by the given list.

This method uses the implementation in the decorators subpackage.

Parameters
<E>
the element type
list:List<? extends E>

the list to make unmodifiable, must not be null

Returns:List<E>

an unmodifiable list backed by the given list

Exceptions
NullPointerException:
if the list is null
org.apache.commons.collections4 back to summary

private final Class ListUtils.CharSequenceAsList

extends AbstractList<Character>
Class Inheritance

A simple wrapper to use a CharSequence as List.

Field Summary

Modifier and TypeField and Description
private final CharSequence
Inherited from java.util.AbstractList:
modCount

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Character
get(final int
index of the element to return
index
)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Returns the element at the specified position in this list.
public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Returns the number of elements in this list.
Inherited from java.util.AbstractList:
addaddaddAllclearequalshashCodeindexOfiteratorlastIndexOflistIteratorlistIteratorremoveremoveRangesetsubList

Field Detail

sequenceback to summary
private final CharSequence sequence

Constructor Detail

CharSequenceAsListback to summary
public CharSequenceAsList(final CharSequence sequence)

Method Detail

getback to summary
public Character get(final int index)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Doc from java.util.AbstractList.get.

Returns the element at the specified position in this list.

Parameters
index:int

Doc from java.util.List.get.

index of the element to return

Returns:Character

Doc from java.util.List.get.

the element at the specified position in this list

Annotations
@Override
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Doc from java.util.List.size.

Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this list

Annotations
@Override
org.apache.commons.collections4 back to summary

private final Class ListUtils.LcsVisitor<E>

extends Object
implements CommandVisitor<E>
Class Inheritance
All Implemented Interfaces
org.apache.commons.collections4.sequence.CommandVisitor

A helper class used to construct the longest common subsequence.

Field Summary

Modifier and TypeField and Description
private final ArrayList<E>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public List<E>
public void
visitDeleteCommand(final E
object to delete (this object comes from the first sequence)
object
)

Implements org.apache.commons.collections4.sequence.CommandVisitor.visitDeleteCommand.

Method called when a delete command is encountered.
public void
visitInsertCommand(final E
object to insert (this object comes from the second sequence)
object
)

Implements org.apache.commons.collections4.sequence.CommandVisitor.visitInsertCommand.

Method called when an insert command is encountered.
public void
visitKeepCommand(final E
object to keep (this object comes from the first sequence)
object
)

Implements org.apache.commons.collections4.sequence.CommandVisitor.visitKeepCommand.

Method called when a keep command is encountered.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

sequenceback to summary
private final ArrayList<E> sequence

Constructor Detail

LcsVisitorback to summary
public LcsVisitor()

Method Detail

getSubSequenceback to summary
public List<E> getSubSequence()
visitDeleteCommandback to summary
public void visitDeleteCommand(final E object)

Implements org.apache.commons.collections4.sequence.CommandVisitor.visitDeleteCommand.

Doc from org.apache.commons.collections4.sequence.CommandVisitor.visitDeleteCommand.

Method called when a delete command is encountered.

Parameters
object:E

object to delete (this object comes from the first sequence)

Annotations
@Override
visitInsertCommandback to summary
public void visitInsertCommand(final E object)

Implements org.apache.commons.collections4.sequence.CommandVisitor.visitInsertCommand.

Doc from org.apache.commons.collections4.sequence.CommandVisitor.visitInsertCommand.

Method called when an insert command is encountered.

Parameters
object:E

object to insert (this object comes from the second sequence)

Annotations
@Override
visitKeepCommandback to summary
public void visitKeepCommand(final E object)

Implements org.apache.commons.collections4.sequence.CommandVisitor.visitKeepCommand.

Doc from org.apache.commons.collections4.sequence.CommandVisitor.visitKeepCommand.

Method called when a keep command is encountered.

Parameters
object:E

object to keep (this object comes from the first sequence)

Annotations
@Override
org.apache.commons.collections4 back to summary

private Class ListUtils.Partition<T>

extends AbstractList<List<T>>
Class Inheritance

Provides a partition view on a List.
Since
4.0

Field Summary

Modifier and TypeField and Description
private final List<T>
private final int
Inherited from java.util.AbstractList:
modCount

Constructor Summary

AccessConstructor and Description
private
Partition(final List<T> list, final int size)

Method Summary

Modifier and TypeMethod and Description
public List<T>
get(final int
index of the element to return
index
)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Returns the element at the specified position in this list.
public boolean
isEmpty()

Overrides java.util.AbstractCollection.isEmpty.

Implements java.util.List.isEmpty, java.util.Collection.isEmpty.

Returns true if this list contains no elements.
public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Returns the number of elements in this list.
Inherited from java.util.AbstractList:
addaddaddAllclearequalshashCodeindexOfiteratorlastIndexOflistIteratorlistIteratorremoveremoveRangesetsubList

Field Detail

listback to summary
private final List<T> list
sizeback to summary
private final int size

Constructor Detail

Partitionback to summary
private Partition(final List<T> list, final int size)

Method Detail

getback to summary
public List<T> get(final int index)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Doc from java.util.AbstractList.get.

Returns the element at the specified position in this list.

Parameters
index:int

Doc from java.util.List.get.

index of the element to return

Returns:List<T>

Doc from java.util.List.get.

the element at the specified position in this list

Annotations
@Override
isEmptyback to summary
public boolean isEmpty()

Overrides java.util.AbstractCollection.isEmpty.

Implements java.util.List.isEmpty, java.util.Collection.isEmpty.

Doc from java.util.List.isEmpty.

Returns true if this list contains no elements.

Returns:boolean

true if this list contains no elements

Annotations
@Override
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Doc from java.util.List.size.

Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this list

Annotations
@Override