Top Description Fields Constructors Methods
org.eclipse.collections.impl.list.fixed

pack-priv final Class DoubletonList<T>

extends AbstractMemoryEfficientMutableList<T>
implements Externalizable
Class Inheritance
All Implemented Interfaces
java.io.Externalizable, java.io.Serializable
Imports
java.io.Externalizable, .IOException, .ObjectInput, .ObjectOutput, java.util.Objects, java.util.function.UnaryOperator, org.eclipse.collections.api.block.procedure.Procedure, .Procedure2, org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure

A DoubletonList is a two-element memory efficient List. It is created by calling Lists.fixedSize.of(one, two).

Field Summary

Modifier and TypeField and Description
private T
private T
private static final long

Constructor Summary

AccessConstructor and Description
public
pack-priv
DoubletonList(T obj1, T obj2)

Method Summary

Modifier and TypeMethod and Description
public DoubletonList<T>
public boolean
public void
each(Procedure<? super T> procedure)

Overrides org.eclipse.collections.impl.list.mutable.AbstractMutableList.each.

Implements org.eclipse.collections.api.RichIterable.each.

The procedure is executed for each element in the iterable.

public <P> void
forEachWith(Procedure2<? super T, ? super P> procedure, P parameter)

Overrides org.eclipse.collections.impl.list.mutable.AbstractMutableList.forEachWith.

Implements org.eclipse.collections.api.InternalIterable.forEachWith.

The procedure2 is evaluated for each element in the iterable with the specified parameter provided as the second argument.

public void
forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure)

Overrides org.eclipse.collections.impl.list.mutable.AbstractMutableList.forEachWithIndex.

Implements org.eclipse.collections.api.InternalIterable.forEachWithIndex, org.eclipse.collections.api.ordered.OrderedIterable.forEachWithIndex.

Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.

public T
get(int index)

Implements java.util.List.get, org.eclipse.collections.api.list.ListIterable.get.

Returns the element at the specified position in this list.

public T
getFirst()

Overrides org.eclipse.collections.impl.list.mutable.AbstractMutableList.getFirst.

Overrides default org.eclipse.collections.api.list.MutableList.getFirst.

Implements org.eclipse.collections.api.RichIterable.getFirst.

This default override exists because java.util.List added a default getFirst() method in Java 21.

public T
getLast()

Overrides org.eclipse.collections.impl.list.mutable.AbstractMutableList.getLast.

Overrides default org.eclipse.collections.api.list.MutableList.getLast.

Implements org.eclipse.collections.api.RichIterable.getLast.

This default override exists because java.util.List added a default getLast() method in Java 21.

public T
getOnly()

Overrides default org.eclipse.collections.api.RichIterable.getOnly.

Returns the element if the iterable has exactly one element.

public void
readExternal(ObjectInput in)

Implements java.io.Externalizable.readExternal.

The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.

public void
replaceAll(UnaryOperator<T> operator)

Overrides default java.util.List.replaceAll.

Replaces each element of this list with the result of applying the operator to that element (optional operation).

public T
set(int index, T element)

Implements java.util.List.set.

set is implemented purely to allow the List to be sorted, not because this List should be considered mutable.

public int
size()

Implements java.util.Collection.size, org.eclipse.collections.api.RichIterable.size, java.util.List.size.

Returns the number of elements in this list.

public TripletonList<T>
with(T value)

Overrides default org.eclipse.collections.api.list.MutableList.with.

Implements org.eclipse.collections.api.list.FixedSizeList.with, org.eclipse.collections.api.collection.MutableCollection.with.

This method allows fixed size collections the ability to add elements to their existing elements.

public void
writeExternal(ObjectOutput out)

Implements java.io.Externalizable.writeExternal.

The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

Inherited from org.eclipse.collections.impl.list.fixed.AbstractMemoryEfficientMutableList:
addaddaddAlladdAlladdAllIterableclearlistIteratorlistIteratorremoveremoveremoveAllremoveAllIterableremoveIfremoveIfWithretainAllretainAllIterablesortsubListtaptoReversedwithAllwithoutwithoutAll

Field Detail

element1back to summary
private T element1
element2back to summary
private T element2
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

DoubletonListback to summary
public DoubletonList()
Annotations
@SuppressWarnings:UnusedDeclaration
DoubletonListback to summary
pack-priv DoubletonList(T obj1, T obj2)

Method Detail

cloneback to summary
public DoubletonList<T> clone()

Overrides org.eclipse.collections.impl.list.fixed.AbstractMemoryEfficientMutableList.clone.

Implements org.eclipse.collections.api.list.MutableList.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Annotations
@Override
containsback to summary
public boolean contains(Object obj)

Overrides org.eclipse.collections.impl.list.mutable.AbstractMutableList.contains.

Implements java.util.Collection.contains, org.eclipse.collections.api.RichIterable.contains, java.util.List.contains.

Doc from java.util.List.contains.

Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that Objects.equals(o, e).

Annotations
@Override
eachback to summary
public void each(Procedure<? super T> procedure)

Overrides org.eclipse.collections.impl.list.mutable.AbstractMutableList.each.

Implements org.eclipse.collections.api.RichIterable.each.

Doc from org.eclipse.collections.api.RichIterable.each.

The procedure is executed for each element in the iterable.

Example using a Java 8 lambda expression:

people.each(person -> LOGGER.info(person.getName()));
This method is a variant of InternalIterable#forEach(Procedure) that has a signature conflict with Iterable#forEach(java.util.function.Consumer).
Annotations
@Override
forEachWithback to summary
public <P> void forEachWith(Procedure2<? super T, ? super P> procedure, P parameter)

Overrides org.eclipse.collections.impl.list.mutable.AbstractMutableList.forEachWith.

Implements org.eclipse.collections.api.InternalIterable.forEachWith.

Doc from org.eclipse.collections.api.InternalIterable.forEachWith.

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);
Annotations
@Override
forEachWithIndexback to summary
public void forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure)

Overrides org.eclipse.collections.impl.list.mutable.AbstractMutableList.forEachWithIndex.

Implements org.eclipse.collections.api.InternalIterable.forEachWithIndex, org.eclipse.collections.api.ordered.OrderedIterable.forEachWithIndex.

Doc from org.eclipse.collections.api.InternalIterable.forEachWithIndex.

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());
    }
});
Annotations
@Override
getback to summary
public T get(int index)

Implements java.util.List.get, org.eclipse.collections.api.list.ListIterable.get.

Doc from java.util.List.get.

Returns the element at the specified position in this list.

Annotations
@Override
getFirstback to summary
public T getFirst()

Overrides org.eclipse.collections.impl.list.mutable.AbstractMutableList.getFirst.

Overrides default org.eclipse.collections.api.list.MutableList.getFirst.

Implements org.eclipse.collections.api.RichIterable.getFirst.

Doc from org.eclipse.collections.api.list.MutableList.getFirst.

This default override exists because java.util.List added a default getFirst() method in Java 21.

Annotations
@Override
getLastback to summary
public T getLast()

Overrides org.eclipse.collections.impl.list.mutable.AbstractMutableList.getLast.

Overrides default org.eclipse.collections.api.list.MutableList.getLast.

Implements org.eclipse.collections.api.RichIterable.getLast.

Doc from org.eclipse.collections.api.list.MutableList.getLast.

This default override exists because java.util.List added a default getLast() method in Java 21.

Annotations
@Override
getOnlyback to summary
public T getOnly()

Overrides default org.eclipse.collections.api.RichIterable.getOnly.

Doc from org.eclipse.collections.api.RichIterable.getOnly.

Returns the element if the iterable has exactly one element. Otherwise, throw IllegalStateException.

Annotations
@Override
readExternalback to summary
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException

Implements java.io.Externalizable.readExternal.

Doc from java.io.Externalizable.readExternal.

The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.

Annotations
@Override
Exceptions
IOException:
if I/O errors occur
ClassNotFoundException:
If the class for an object being restored cannot be found.
replaceAllback to summary
public void replaceAll(UnaryOperator<T> operator)

Overrides default java.util.List.replaceAll.

Doc from java.util.List.replaceAll.

Replaces each element of this list with the result of applying the operator to that element (optional operation). Errors or runtime exceptions thrown by the operator are relayed to the caller.

Annotations
@Override
Since
10.0
setback to summary
public T set(int index, T element)

Implements java.util.List.set.

set is implemented purely to allow the List to be sorted, not because this List should be considered mutable.

Annotations
@Override
sizeback to summary
public int size()

Implements java.util.Collection.size, org.eclipse.collections.api.RichIterable.size, java.util.List.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.

Annotations
@Override
withback to summary
public TripletonList<T> with(T value)

Overrides default org.eclipse.collections.api.list.MutableList.with.

Implements org.eclipse.collections.api.list.FixedSizeList.with, org.eclipse.collections.api.collection.MutableCollection.with.

Doc from org.eclipse.collections.api.collection.FixedSizeCollection.with.

This method allows fixed size collections the ability to add elements to their existing elements. A new instance of MutableCollection is returned containing the elements of the original collection with the new element added. Implementations will return a new FixedSizeCollection where possible. In order to use this method properly with mutable and fixed size collections the following approach must be taken:

MutableCollection<String> list;
list = list.with("1");
list = list.with("2");
return list;
Annotations
@Override
writeExternalback to summary
public void writeExternal(ObjectOutput out) throws IOException

Implements java.io.Externalizable.writeExternal.

Doc from java.io.Externalizable.writeExternal.

The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

Annotations
@Override
Exceptions
IOException:
Includes any I/O exceptions that may occur