Class EmptyList<T>
- java.lang.Object
-
- org.eclipse.collections.impl.AbstractRichIterable<T>
-
- org.eclipse.collections.impl.collection.mutable.AbstractMutableCollection<T>
-
- org.eclipse.collections.impl.list.mutable.AbstractMutableList<T>
-
- org.eclipse.collections.impl.list.fixed.AbstractMemoryEfficientMutableList<T>
-
- org.eclipse.collections.impl.list.fixed.EmptyList<T>
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.lang.Iterable<T>
,java.util.Collection<T>
,java.util.List<T>
,java.util.RandomAccess
,FixedSizeCollection<T>
,MutableCollection<T>
,InternalIterable<T>
,FixedSizeList<T>
,ListIterable<T>
,MutableList<T>
,OrderedIterable<T>
,ReversibleIterable<T>
,RichIterable<T>
final class EmptyList<T> extends AbstractMemoryEfficientMutableList<T> implements java.io.Serializable
This class is a memory efficient list with no elements. It is created by calling Lists.fixedSize.of() which actually returns a singleton instance.
-
-
Field Summary
Fields Modifier and Type Field Description private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description EmptyList()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EmptyList<T>
clone()
boolean
contains(java.lang.Object obj)
Returns true if the iterable has an element which responds true to element.equals(object).void
each(Procedure<? super T> procedure)
The procedure is executed for each element in the iterable.<P> void
forEachWith(Procedure2<? super T,? super P> procedure, P parameter)
The procedure2 is evaluated for each element in the iterable with the specified parameter provided as the second argument.void
forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure)
Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.T
get(int index)
Returns the item at the specified position in this list iterable.T
getFirst()
Returns the first element of an iterable.T
getLast()
Returns the last element of an iterable.T
getOnly()
Returns the element if the iterable has exactly one element.java.util.Iterator<T>
iterator()
java.util.ListIterator<T>
listIterator()
java.util.ListIterator<T>
listIterator(int index)
T
max()
Returns the maximum element out of this container based on the natural order.T
max(java.util.Comparator<? super T> comparator)
Returns the maximum element out of this container based on the comparator.<V extends java.lang.Comparable<? super V>>
TmaxBy(Function<? super T,? extends V> function)
Returns the maximum elements out of this container based on the natural order of the attribute returned by Function.T
min()
Returns the minimum element out of this container based on the natural order.T
min(java.util.Comparator<? super T> comparator)
Returns the minimum element out of this container based on the comparator.<V extends java.lang.Comparable<? super V>>
TminBy(Function<? super T,? extends V> function)
Returns the minimum elements out of this container based on the natural order of the attribute returned by Function.private java.lang.Object
readResolve()
void
replaceAll(java.util.function.UnaryOperator<T> operator)
T
set(int index, T element)
int
size()
Returns the number of items in this iterable.void
sort(java.util.Comparator<? super T> comparator)
This method checks if comparator is null and use a ComparableComparator if it is.EmptyList<T>
sortThis(java.util.Comparator<? super T> comparator)
Sorts the internal data structure of this list and returns the list itself as a convenience.<V extends java.lang.Comparable<? super V>>
MutableList<T>sortThisBy(Function<? super T,? extends V> function)
Sorts the internal data structure of this list based on the natural order of the attribute returned byfunction
.MutableList<T>
sortThisByBoolean(BooleanFunction<? super T> function)
MutableList<T>
sortThisByByte(ByteFunction<? super T> function)
MutableList<T>
sortThisByChar(CharFunction<? super T> function)
MutableList<T>
sortThisByDouble(DoubleFunction<? super T> function)
MutableList<T>
sortThisByFloat(FloatFunction<? super T> function)
MutableList<T>
sortThisByInt(IntFunction<? super T> function)
MutableList<T>
sortThisByLong(LongFunction<? super T> function)
MutableList<T>
sortThisByShort(ShortFunction<? super T> function)
ImmutableList<T>
toImmutable()
Returns an immutable copy of this list.SingletonList<T>
with(T value)
This method allows mutable and fixed size collections the ability to add elements to their existing elements.<S> MutableList<Pair<T,S>>
zip(java.lang.Iterable<S> that)
Returns aRichIterable
formed from thisRichIterable
and anotherRichIterable
by combining corresponding elements in pairs.MutableList<Pair<T,java.lang.Integer>>
zipWithIndex()
Zips thisRichIterable
with its indices.-
Methods inherited from class org.eclipse.collections.impl.list.fixed.AbstractMemoryEfficientMutableList
add, add, addAll, addAll, addAllIterable, clear, remove, remove, removeAll, removeAllIterable, removeIf, removeIfWith, retainAll, retainAllIterable, subList, tap, toReversed, withAll, without, withoutAll
-
Methods inherited from class org.eclipse.collections.impl.list.mutable.AbstractMutableList
allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, asParallel, asReversed, asSynchronized, asUnmodifiable, binarySearch, chunk, collect, collectIf, collectWith, containsAll, corresponds, count, countWith, detect, detectIndex, detectLastIndex, detectOptional, detectWith, detectWithOptional, distinct, distinct, distinctBy, drop, dropWhile, equals, flatCollect, forEach, forEachWithIndex, groupBy, groupByEach, groupByUniqueKey, hashCode, indexOf, injectInto, injectInto, injectInto, injectInto, injectIntoWith, lastIndexOf, newEmpty, noneSatisfy, noneSatisfyWith, partition, partitionWhile, partitionWith, reject, rejectWith, select, selectAndRejectWith, selectInstancesOf, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, take, takeWhile, toSet, toSortedList, zip, zipWithIndex
-
Methods inherited from class org.eclipse.collections.impl.collection.mutable.AbstractMutableCollection
countBy, countByEach, countByWith, reduce, sumByDouble, sumByFloat, sumByInt, sumByLong
-
Methods inherited from class org.eclipse.collections.impl.AbstractRichIterable
asLazy, containsAllArguments, containsAllIterable, detectWithIfNone, forEach, groupBy, groupByEach, groupByUniqueKey, injectInto, into, isEmpty, toArray, toArray, toBag, toBiMap, toList, toMap, toSortedBag, toSortedBag, toSortedBagBy, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, toString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.collections.api.list.FixedSizeList
sortThis
-
Methods inherited from interface org.eclipse.collections.api.InternalIterable
forEach
-
Methods inherited from interface java.util.List
containsAll, equals, hashCode, indexOf, isEmpty, lastIndexOf, spliterator, toArray, toArray
-
Methods inherited from interface org.eclipse.collections.api.list.ListIterable
asParallel, binarySearch, binarySearch, equals, forEachInBoth, hashCode, lastIndexOf
-
Methods inherited from interface org.eclipse.collections.api.collection.MutableCollection
aggregateBy, aggregateInPlaceBy, countBy, countByEach, countByWith, groupByUniqueKey, injectIntoWith, selectAndRejectWith, sumByDouble, sumByFloat, sumByInt, sumByLong
-
Methods inherited from interface org.eclipse.collections.api.list.MutableList
asSynchronized, asUnmodifiable, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, collectWithIndex, distinct, distinct, distinctBy, drop, dropWhile, flatCollect, flatCollectWith, groupBy, groupByEach, newEmpty, partition, partitionWhile, partitionWith, reject, rejectWith, rejectWithIndex, reverseThis, select, selectInstancesOf, selectWith, selectWithIndex, shuffleThis, shuffleThis, take, takeWhile, toImmutableList
-
Methods inherited from interface org.eclipse.collections.api.ordered.OrderedIterable
collectWithIndex, corresponds, detectIndex, forEach, forEachWithIndex, getFirstOptional, getLastOptional, indexOf, rejectWithIndex, selectWithIndex, toStack, zip, zipWithIndex
-
Methods inherited from interface org.eclipse.collections.api.ordered.ReversibleIterable
asReversed, detectLastIndex, reverseForEach, reverseForEachWithIndex
-
Methods inherited from interface org.eclipse.collections.api.RichIterable
aggregateBy, allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, chunk, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, containsAll, containsAllArguments, containsAllIterable, containsAny, containsAnyIterable, containsBy, containsNone, containsNoneIterable, count, countBy, countByEach, countByWith, countWith, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, groupBy, groupByAndCollect, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, injectIntoDouble, injectIntoFloat, injectIntoInt, injectIntoLong, into, isEmpty, makeString, makeString, makeString, makeString, maxByOptional, maxOptional, maxOptional, minByOptional, minOptional, minOptional, noneSatisfy, noneSatisfyWith, notEmpty, reduce, reduceInPlace, reduceInPlace, reject, rejectWith, select, selectWith, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toBiMap, toImmutableBag, toImmutableBiMap, toImmutableMap, toImmutableSet, toImmutableSortedBag, toImmutableSortedBag, toImmutableSortedBagBy, toImmutableSortedList, toImmutableSortedList, toImmutableSortedListBy, toImmutableSortedSet, toImmutableSortedSet, toImmutableSortedSetBy, toList, toMap, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, toString
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Method Detail
-
readResolve
private java.lang.Object readResolve()
-
with
public SingletonList<T> with(T value)
Description copied from interface:MutableCollection
This method allows mutable and fixed size collections the ability to add elements to their existing elements. In order to support fixed size a new instance of a collection would have to be returned taking the elements of the original collection and appending the new element to form the new collection. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:MutableCollection<String> list = list.with("1"); list = list.with("2"); return list;
In the case ofFixedSizeCollection
a new instance of MutableCollection will be returned by with, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling add on itself.- Specified by:
with
in interfaceFixedSizeCollection<T>
- Specified by:
with
in interfaceFixedSizeList<T>
- Specified by:
with
in interfaceMutableCollection<T>
- Specified by:
with
in interfaceMutableList<T>
- See Also:
Collection.add(Object)
-
clone
public EmptyList<T> clone()
- Specified by:
clone
in interfaceMutableList<T>
- Overrides:
clone
in classAbstractMemoryEfficientMutableList<T>
-
size
public int size()
Description copied from interface:RichIterable
Returns the number of items in this iterable.- Specified by:
size
in interfacejava.util.Collection<T>
- Specified by:
size
in interfacejava.util.List<T>
- Specified by:
size
in interfaceRichIterable<T>
-
contains
public boolean contains(java.lang.Object obj)
Description copied from interface:RichIterable
Returns true if the iterable has an element which responds true to element.equals(object).- Specified by:
contains
in interfacejava.util.Collection<T>
- Specified by:
contains
in interfacejava.util.List<T>
- Specified by:
contains
in interfaceRichIterable<T>
- Overrides:
contains
in classAbstractMutableList<T>
-
get
public T get(int index)
Description copied from interface:ListIterable
Returns the item at the specified position in this list iterable.- Specified by:
get
in interfacejava.util.List<T>
- Specified by:
get
in interfaceListIterable<T>
-
replaceAll
public void replaceAll(java.util.function.UnaryOperator<T> operator)
- Specified by:
replaceAll
in interfacejava.util.List<T>
- Since:
- 10.0 - Overridden for efficiency
-
sort
public void sort(java.util.Comparator<? super T> comparator)
Description copied from class:AbstractMemoryEfficientMutableList
This method checks if comparator is null and use a ComparableComparator if it is.- Specified by:
sort
in interfacejava.util.List<T>
- Overrides:
sort
in classAbstractMemoryEfficientMutableList<T>
- Since:
- 10.0 - Overridden for efficiency
-
sortThis
public EmptyList<T> sortThis(java.util.Comparator<? super T> comparator)
Description copied from interface:MutableList
Sorts the internal data structure of this list and returns the list itself as a convenience.- Specified by:
sortThis
in interfaceFixedSizeList<T>
- Specified by:
sortThis
in interfaceMutableList<T>
-
sortThisBy
public <V extends java.lang.Comparable<? super V>> MutableList<T> sortThisBy(Function<? super T,? extends V> function)
Description copied from interface:MutableList
Sorts the internal data structure of this list based on the natural order of the attribute returned byfunction
.- Specified by:
sortThisBy
in interfaceMutableList<T>
-
sortThisByInt
public MutableList<T> sortThisByInt(IntFunction<? super T> function)
- Specified by:
sortThisByInt
in interfaceMutableList<T>
- Overrides:
sortThisByInt
in classAbstractMutableList<T>
-
sortThisByBoolean
public MutableList<T> sortThisByBoolean(BooleanFunction<? super T> function)
- Specified by:
sortThisByBoolean
in interfaceMutableList<T>
- Overrides:
sortThisByBoolean
in classAbstractMutableList<T>
-
sortThisByChar
public MutableList<T> sortThisByChar(CharFunction<? super T> function)
- Specified by:
sortThisByChar
in interfaceMutableList<T>
- Overrides:
sortThisByChar
in classAbstractMutableList<T>
-
sortThisByByte
public MutableList<T> sortThisByByte(ByteFunction<? super T> function)
- Specified by:
sortThisByByte
in interfaceMutableList<T>
- Overrides:
sortThisByByte
in classAbstractMutableList<T>
-
sortThisByShort
public MutableList<T> sortThisByShort(ShortFunction<? super T> function)
- Specified by:
sortThisByShort
in interfaceMutableList<T>
- Overrides:
sortThisByShort
in classAbstractMutableList<T>
-
sortThisByFloat
public MutableList<T> sortThisByFloat(FloatFunction<? super T> function)
- Specified by:
sortThisByFloat
in interfaceMutableList<T>
- Overrides:
sortThisByFloat
in classAbstractMutableList<T>
-
sortThisByLong
public MutableList<T> sortThisByLong(LongFunction<? super T> function)
- Specified by:
sortThisByLong
in interfaceMutableList<T>
- Overrides:
sortThisByLong
in classAbstractMutableList<T>
-
sortThisByDouble
public MutableList<T> sortThisByDouble(DoubleFunction<? super T> function)
- Specified by:
sortThisByDouble
in interfaceMutableList<T>
- Overrides:
sortThisByDouble
in classAbstractMutableList<T>
-
getFirst
public T getFirst()
Description copied from interface:RichIterable
Returns the first element of an iterable. In the case of a List it is the element at the first index. In the case of any other Collection, it is the first element that would be returned during an iteration. If the iterable is empty, null is returned. If null is a valid element of the container, then a developer would need to check to see if the iterable is empty to validate that a null result was not due to the container being empty.The order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use this method, the first element could be any element from the Set.
- Specified by:
getFirst
in interfaceListIterable<T>
- Specified by:
getFirst
in interfaceOrderedIterable<T>
- Specified by:
getFirst
in interfaceRichIterable<T>
- Overrides:
getFirst
in classAbstractMutableList<T>
-
getLast
public T getLast()
Description copied from interface:RichIterable
Returns the last element of an iterable. In the case of a List it is the element at the last index. In the case of any other Collection, it is the last element that would be returned during an iteration. If the iterable is empty, null is returned. If null is a valid element of the container, then a developer would need to check to see if the iterable is empty to validate that a null result was not due to the container being empty.The order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use this method, the last element could be any element from the Set.
- Specified by:
getLast
in interfaceListIterable<T>
- Specified by:
getLast
in interfaceOrderedIterable<T>
- Specified by:
getLast
in interfaceRichIterable<T>
- Overrides:
getLast
in classAbstractMutableList<T>
-
getOnly
public T getOnly()
Description copied from interface:RichIterable
Returns the element if the iterable has exactly one element. Otherwise, throwIllegalStateException
.- Specified by:
getOnly
in interfaceRichIterable<T>
- Returns:
- an element of an iterable.
-
each
public void each(Procedure<? super T> procedure)
Description copied from interface:RichIterable
The procedure is executed for each element in the iterable.Example using a Java 8 lambda expression:
people.each(person -> LOGGER.info(person.getName()));
Example using an anonymous inner class:
people.each(new Procedure<Person>() { public void value(Person person) { LOGGER.info(person.getName()); } });
This method is a variant ofInternalIterable.forEach(Procedure)
that has a signature conflict withIterable.forEach(java.util.function.Consumer)
.- Specified by:
each
in interfaceRichIterable<T>
- Overrides:
each
in classAbstractMutableList<T>
- See Also:
InternalIterable.forEach(Procedure)
,Iterable.forEach(java.util.function.Consumer)
-
forEachWithIndex
public void forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure)
Description copied from interface:InternalIterable
Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.Example using a Java 8 lambda:
people.forEachWithIndex((Person person, int index) -> LOGGER.info("Index: " + index + " person: " + person.getName()));
Example using an anonymous inner class:
people.forEachWithIndex(new ObjectIntProcedure<Person>() { public void value(Person person, int index) { LOGGER.info("Index: " + index + " person: " + person.getName()); } });
- Specified by:
forEachWithIndex
in interfaceInternalIterable<T>
- Specified by:
forEachWithIndex
in interfaceOrderedIterable<T>
- Overrides:
forEachWithIndex
in classAbstractMutableList<T>
-
forEachWith
public <P> void forEachWith(Procedure2<? super T,? super P> procedure, P parameter)
Description copied from interface:InternalIterable
The procedure2 is evaluated for each element in the iterable with the specified parameter provided as the second argument.Example using a Java 8 lambda:
people.forEachWith((Person person, Person other) -> { if (person.isRelatedTo(other)) { LOGGER.info(person.getName()); } }, fred);
Example using an anonymous inner class:
people.forEachWith(new Procedure2<Person, Person>() { public void value(Person person, Person other) { if (person.isRelatedTo(other)) { LOGGER.info(person.getName()); } } }, fred);
- Specified by:
forEachWith
in interfaceInternalIterable<T>
- Overrides:
forEachWith
in classAbstractMutableList<T>
-
iterator
public java.util.Iterator<T> iterator()
-
listIterator
public java.util.ListIterator<T> listIterator()
- Specified by:
listIterator
in interfacejava.util.List<T>
- Specified by:
listIterator
in interfaceListIterable<T>
- Overrides:
listIterator
in classAbstractMemoryEfficientMutableList<T>
- See Also:
List.listIterator()
-
listIterator
public java.util.ListIterator<T> listIterator(int index)
- Specified by:
listIterator
in interfacejava.util.List<T>
- Specified by:
listIterator
in interfaceListIterable<T>
- Overrides:
listIterator
in classAbstractMemoryEfficientMutableList<T>
- See Also:
List.listIterator(int)
-
min
public T min(java.util.Comparator<? super T> comparator)
Description copied from interface:RichIterable
Returns the minimum element out of this container based on the comparator.- Specified by:
min
in interfaceRichIterable<T>
- Overrides:
min
in classAbstractMutableList<T>
-
max
public T max(java.util.Comparator<? super T> comparator)
Description copied from interface:RichIterable
Returns the maximum element out of this container based on the comparator.- Specified by:
max
in interfaceRichIterable<T>
- Overrides:
max
in classAbstractMutableList<T>
-
min
public T min()
Description copied from interface:RichIterable
Returns the minimum element out of this container based on the natural order.- Specified by:
min
in interfaceOrderedIterable<T>
- Specified by:
min
in interfaceRichIterable<T>
- Overrides:
min
in classAbstractMutableList<T>
-
max
public T max()
Description copied from interface:RichIterable
Returns the maximum element out of this container based on the natural order.- Specified by:
max
in interfaceOrderedIterable<T>
- Specified by:
max
in interfaceRichIterable<T>
- Overrides:
max
in classAbstractMutableList<T>
-
minBy
public <V extends java.lang.Comparable<? super V>> T minBy(Function<? super T,? extends V> function)
Description copied from interface:RichIterable
Returns the minimum elements out of this container based on the natural order of the attribute returned by Function.- Specified by:
minBy
in interfaceRichIterable<T>
- Overrides:
minBy
in classAbstractMutableList<T>
-
maxBy
public <V extends java.lang.Comparable<? super V>> T maxBy(Function<? super T,? extends V> function)
Description copied from interface:RichIterable
Returns the maximum elements out of this container based on the natural order of the attribute returned by Function.- Specified by:
maxBy
in interfaceRichIterable<T>
- Overrides:
maxBy
in classAbstractMutableList<T>
-
zip
public <S> MutableList<Pair<T,S>> zip(java.lang.Iterable<S> that)
Description copied from interface:RichIterable
Returns aRichIterable
formed from thisRichIterable
and anotherRichIterable
by combining corresponding elements in pairs. If one of the twoRichIterable
s is longer than the other, its remaining elements are ignored.- Specified by:
zip
in interfaceListIterable<T>
- Specified by:
zip
in interfaceMutableCollection<T>
- Specified by:
zip
in interfaceMutableList<T>
- Specified by:
zip
in interfaceOrderedIterable<T>
- Specified by:
zip
in interfaceReversibleIterable<T>
- Specified by:
zip
in interfaceRichIterable<T>
- Overrides:
zip
in classAbstractMutableList<T>
- Type Parameters:
S
- the type of the second half of the returned pairs- Parameters:
that
- TheRichIterable
providing the second half of each result pair- Returns:
- A new
RichIterable
containing pairs consisting of corresponding elements of thisRichIterable
and that. The length of the returnedRichIterable
is the minimum of the lengths of thisRichIterable
and that.
-
zipWithIndex
public MutableList<Pair<T,java.lang.Integer>> zipWithIndex()
Description copied from interface:RichIterable
Zips thisRichIterable
with its indices.- Specified by:
zipWithIndex
in interfaceListIterable<T>
- Specified by:
zipWithIndex
in interfaceMutableCollection<T>
- Specified by:
zipWithIndex
in interfaceMutableList<T>
- Specified by:
zipWithIndex
in interfaceOrderedIterable<T>
- Specified by:
zipWithIndex
in interfaceReversibleIterable<T>
- Specified by:
zipWithIndex
in interfaceRichIterable<T>
- Overrides:
zipWithIndex
in classAbstractMutableList<T>
- Returns:
- A new
RichIterable
containing pairs consisting of all elements of thisRichIterable
paired with their index. Indices start at 0. - See Also:
RichIterable.zip(Iterable)
-
toImmutable
public ImmutableList<T> toImmutable()
Description copied from interface:MutableList
Returns an immutable copy of this list. If the list is immutable, it returns itself.- Specified by:
toImmutable
in interfaceListIterable<T>
- Specified by:
toImmutable
in interfaceMutableCollection<T>
- Specified by:
toImmutable
in interfaceMutableList<T>
-
-