Package org.linkki.util
Record Class Sequence<T>
java.lang.Object
java.lang.Record
org.linkki.util.Sequence<T>
- All Implemented Interfaces:
Serializable,Iterable<T>
This sequence is a wrapper for a list to create immutable lists easily. It could be instantiated
using the static of-methods or the
empty() method.
If you already have such a Sequence object you could create a new Sequence
concatenated with additional objects using the with-methods.
To allow access to the elements of this sequence it implements the Iterable interface and
provides methods like list() or stream() to access the internal list.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncollect()static <T> Sequence<T>empty()Creates an emptySequence.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.iterator()list()Returns the value of thelistrecord component.static <T> Sequence<T>of(Collection<? extends T> elements) Creates a newSequencewith the elements of the givenCollection.static <T> Sequence<T>of(T... elements) Creates a newSequencewith the given elements.stream()Directly access the stream of the list that contains all the elements of this sequence.toString()Returns a string representation of this record class.with(Collection<T> elements) Returns a newSequenceconcatenated with the given elements.Returns a newSequenceconcatenated with the given sequence of elements.Returns a newSequenceconcatenated with the given elements.withNewElementsFrom(Collection<T> elements) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Sequence
Creates an instance of aSequencerecord class.- Parameters:
list- the value for thelistrecord component
-
-
Method Details
-
of
Creates a newSequencewith the elements of the givenCollection.- Parameters:
elements- the elements that should be part of this sequence- Returns:
- the new
Sequencewith the given elements
-
of
Creates a newSequencewith the given elements.- Parameters:
elements- the elements that should be part of this sequence- Returns:
- the new
Sequencewith the given elements
-
empty
Creates an emptySequence.- Returns:
- an empty
Sequence
-
with
- Parameters:
elements- the new elements that should be concatenated- Returns:
- a new sequence with all elements of this
Sequenceconcatenated with the new elements
-
withNewElementsFrom
Returns a newSequenceconcatenated with those of the given elements that are not already contained in thisSequence. ThisSequenceis not affected.- Parameters:
elements- the new elements that should be concatenated if they are not already contained- Returns:
- a new sequence with all elements of this
Sequenceconcatenated with the new elements
-
with
Returns a newSequenceconcatenated with the given sequence of elements. -
with
- Parameters:
newElements- the new elements that should be concatenated- Returns:
- a new sequence with all elements of this
Sequenceconcatenated with the new elements
-
withIf
-
withIf
-
iterator
-
stream
Directly access the stream of the list that contains all the elements of this sequence. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
collect
-
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
list
Returns the value of thelistrecord component.- Returns:
- the value of the
listrecord component
-