Interface ISequence<ITEM extends IItem>
- Type Parameters:
ITEM- the Java type of the items in a sequence
- All Superinterfaces:
Collection<ITEM>,ICollectionValue,Iterable<ITEM>,List<ITEM>
Items is a sequence are typically ordered based on their position in the original node graph based on a depth first ordering.
-
Method Summary
Modifier and TypeMethodDescriptiondefault Stream<IAnyAtomicItem>atomize()An implementation of XPath 3.1 fn:data supporting item atomization.default ISequence<?>Get the collection value as a sequence.copyOf(Collection<? extends T> collection) Returns an unmodifiable sequence containing the items of the given Collection, in its iteration order.countTypes(Set<Class<? extends T>> classes) Count the occurrences of items in this sequence that are instances of the provided type classes.empty()Get an empty sequence.flatten()Get the stream of items for the collection value.default ITEMgetFirstItem(boolean requireSingleton) Retrieves the first item in this sequence.static <T extends IItem>
TgetFirstItem(ISequence<T> items, boolean requireSingleton) Retrieves the first item in a sequence.static <T extends IItem>
TgetFirstItem(Stream<T> items, boolean requireSingleton) Retrieves the first item in a stream of items.Get a list of the Java class types for each item in this sequence.Apply the providedmapFunctionto each item in the sequence.of()Returns an unmodifiable sequence containing zero elements.Returns an unmodifiable sequence containing the provideditems.of(T item) Returns an unmodifiable sequence containing the provideditem.of(T... items) Returns an unmodifiable sequence containing an arbitrary number of items.of(T e1, T e2) Returns an unmodifiable sequence containing two items.of(T e1, T e2, T e3) Returns an unmodifiable sequence containing three elements.of(T e1, T e2, T e3, T e4) Returns an unmodifiable sequence containing four items.of(T e1, T e2, T e3, T e4, T e5) Returns an unmodifiable sequence containing five items.of(T e1, T e2, T e3, T e4, T e5, T e6) Returns an unmodifiable sequence containing six items.of(T e1, T e2, T e3, T e4, T e5, T e6, T e7) Returns an unmodifiable sequence containing seven items.of(T e1, T e2, T e3, T e4, T e5, T e6, T e7, T e8) Returns an unmodifiable sequence containing eight items.of(T e1, T e2, T e3, T e4, T e5, T e6, T e7, T e8, T e9) Returns an unmodifiable sequence containing nine items.of(T e1, T e2, T e3, T e4, T e5, T e6, T e7, T e8, T e9, T e10) Returns an unmodifiable sequence containing ten items.ofCollection(Collection<ITEM_TYPE> items) Returns an unmodifiable sequence containing the provideditems.reusable()Ensure the sequence is able to be iterated over multiple times.Get a stream guaranteed to be backed by a list.stream()Get the items in this sequence as aStream.default ICollectionValueGet this sequence as a collection value.Get this sequence.Methods inherited from interface java.util.Collection
parallelStream, removeIf, toArrayMethods inherited from interface dev.metaschema.core.metapath.item.ICollectionValue
deepEquals, toSignatureMethods inherited from interface java.util.List
add, add, addAll, addAll, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray
-
Method Details
-
empty
Get an empty sequence.- Type Parameters:
T- the item type- Returns:
- the empty sequence
-
reusable
Ensure the sequence is able to be iterated over multiple times.This method can be used to ensure that the sequence can be streamed or iterated over multiple times. Implementations should make sure that when this method is called, the resulting stream is supported by an underlying list.
- Returns:
- a sequence with the same contents, which may be the same sequence
-
safeStream
Get a stream guaranteed to be backed by a list.This call ensures that the sequence is backed by a
Listand not aStream, so the underlying collection can be reused. This is done by first callingreusable().- Returns:
- the stream
-
stream
Get the items in this sequence as aStream.- Specified by:
streamin interfaceCollection<ITEM extends IItem>- Returns:
- a stream containing all the items of the sequence
-
getFirstItem
Retrieves the first item in a sequence.If the sequence is empty, a
nullresult is returned. If requireSingleton istrueand the sequence contains more than one item, aTypeMetapathExceptionis thrown.- Type Parameters:
T- the item type to return derived from the provided sequence- Parameters:
items- the sequence to retrieve the first item fromrequireSingleton- iftruethen aTypeMetapathExceptionis thrown if the sequence contains more than one item- Returns:
nullif the sequence is empty, or the item otherwise- Throws:
TypeMetapathException- if the sequence contains more than one item and requireSingleton istrue
-
getFirstItem
Retrieves the first item in a stream of items.If the sequence is empty, a
nullresult is returned. If requireSingleton istrueand the sequence contains more than one item, aTypeMetapathExceptionis thrown.- Type Parameters:
T- the item type to return derived from the provided sequence- Parameters:
items- the sequence to retrieve the first item fromrequireSingleton- iftruethen aTypeMetapathExceptionis thrown if the sequence contains more than one item- Returns:
nullif the sequence is empty, or the item otherwise- Throws:
TypeMetapathException- if the sequence contains more than one item and requireSingleton istrue
-
getFirstItem
Retrieves the first item in this sequence.If the sequence is empty, a
nullresult is returned. If requireSingleton istrueand the sequence contains more than one item, aTypeMetapathExceptionis thrown.- Parameters:
requireSingleton- iftruethen aTypeMetapathExceptionis thrown if the sequence contains more than one item- Returns:
nullif the sequence is empty, or the item otherwise- Throws:
TypeMetapathException- if the sequence contains more than one item and requireSingleton istrue
-
atomize
An implementation of XPath 3.1 fn:data supporting item atomization.- Specified by:
atomizein interfaceICollectionValue- Returns:
- the atomized result
-
toCollectionValue
Get this sequence as a collection value.- Returns:
- the collection value
-
flatten
Description copied from interface:ICollectionValueGet the stream of items for the collection value.If the collection value contains items, then these items are returned.
- Specified by:
flattenin interfaceICollectionValue- Returns:
- a stream of related items
-
toSequence
Get this sequence.- Specified by:
toSequencein interfaceICollectionValue- Returns:
- this sequence
-
contentsAsSequence
Description copied from interface:ICollectionValueGet the collection value as a sequence.If the value is already a sequence, the value is returned as a sequence. Otherwise, if the value is an item, what is returned depends on the item type:
IArrayItemorIMapItem: the contents of the returned sequence are the items of the array or map. Any member values that are a sequence are flattened.- Any other item: A singleton sequence is returned containing the item.
- Specified by:
contentsAsSequencein interfaceICollectionValue- Returns:
- the resulting sequence
-
map
static <T extends R,R extends IItem> ISequence<R> map(@NonNull Function<T, R> mapFunction, @NonNull ISequence<T> seq) Apply the providedmapFunctionto each item in the sequence.- Type Parameters:
T- the Java type of the provided itemsR- the Java type of the resulting items- Parameters:
mapFunction- the map function to apply to each item in the provided sequenceseq- the sequence of items to map- Returns:
- a new sequence containing the mapped items
-
ofCollection
@NonNull static <ITEM_TYPE extends IItem> ISequence<ITEM_TYPE> ofCollection(@NonNull Collection<ITEM_TYPE> items) Returns an unmodifiable sequence containing the provideditems.If the provided collection is already an
ISequence, it is returned unchanged. Otherwise, the collection is wrapped directly without making a defensive copy. If you need a sequence that is independent of the original collection, usecopyOf(Collection)instead.- Type Parameters:
ITEM_TYPE- the type of items contained in the sequence.- Parameters:
items- the items to add to the sequence- Returns:
- the new sequence, or the same sequence if items is already an
ISequence
-
of
Returns an unmodifiable sequence containing the provideditem.If the item is
nulland empty sequence will be created.- Type Parameters:
T- the type of items contained in the sequence.- Parameters:
item- the item to add to the sequence- Returns:
- the new sequence
-
of
Returns an unmodifiable sequence containing the provideditems.- Type Parameters:
T- the type of items contained in the sequence.- Parameters:
items- the items to add to the sequence- Returns:
- the new sequence
-
of
Returns an unmodifiable sequence containing zero elements.- Type Parameters:
T- the item type- Returns:
- an empty
ISequence
-
of
Returns an unmodifiable sequence containing two items.- Type Parameters:
T- theISequence's item type- Parameters:
e1- the first iteme2- the second item- Returns:
- an
ISequencecontaining the specified items - Throws:
NullPointerException- if an item isnull
-
of
Returns an unmodifiable sequence containing three elements.- Type Parameters:
T- theISequence's item type- Parameters:
e1- the first iteme2- the second iteme3- the third item- Returns:
- an
ISequencecontaining the specified items - Throws:
NullPointerException- if an item isnull
-
of
Returns an unmodifiable sequence containing four items.- Type Parameters:
T- theISequence's item type- Parameters:
e1- the first iteme2- the second iteme3- the third iteme4- the fourth item- Returns:
- an
ISequencecontaining the specified items - Throws:
NullPointerException- if an item isnull
-
of
Returns an unmodifiable sequence containing five items.- Type Parameters:
T- theISequence's item type- Parameters:
e1- the first iteme2- the second iteme3- the third iteme4- the fourth iteme5- the fifth item- Returns:
- an
ISequencecontaining the specified items - Throws:
NullPointerException- if an item isnull
-
of
Returns an unmodifiable sequence containing six items.- Type Parameters:
T- theISequence's item type- Parameters:
e1- the first iteme2- the second iteme3- the third iteme4- the fourth iteme5- the fifth iteme6- the sixth item- Returns:
- an
ISequencecontaining the specified items - Throws:
NullPointerException- if an item isnull
-
of
Returns an unmodifiable sequence containing seven items.- Type Parameters:
T- theISequence's item type- Parameters:
e1- the first iteme2- the second iteme3- the third iteme4- the fourth iteme5- the fifth iteme6- the sixth iteme7- the seventh item- Returns:
- an
ISequencecontaining the specified items - Throws:
NullPointerException- if an item isnull
-
of
Returns an unmodifiable sequence containing eight items.- Type Parameters:
T- theISequence's item type- Parameters:
e1- the first iteme2- the second iteme3- the third iteme4- the fourth iteme5- the fifth iteme6- the sixth iteme7- the seventh iteme8- the eighth item- Returns:
- an
ISequencecontaining the specified items - Throws:
NullPointerException- if an item isnull
-
of
@NonNull static <T extends IItem> ISequence<T> of(T e1, T e2, T e3, T e4, T e5, T e6, T e7, T e8, T e9) Returns an unmodifiable sequence containing nine items.- Type Parameters:
T- theISequence's item type- Parameters:
e1- the first iteme2- the second iteme3- the third iteme4- the fourth iteme5- the fifth iteme6- the sixth iteme7- the seventh iteme8- the eighth iteme9- the ninth item- Returns:
- an
ISequencecontaining the specified items - Throws:
NullPointerException- if an item isnull
-
of
@NonNull static <T extends IItem> ISequence<T> of(T e1, T e2, T e3, T e4, T e5, T e6, T e7, T e8, T e9, T e10) Returns an unmodifiable sequence containing ten items.- Type Parameters:
T- theISequence's item type- Parameters:
e1- the first iteme2- the second iteme3- the third iteme4- the fourth iteme5- the fifth iteme6- the sixth iteme7- the seventh iteme8- the eighth iteme9- the ninth iteme10- the tenth item- Returns:
- an
IArrayItemcontaining the specified items - Throws:
NullPointerException- if an item isnull
-
of
Returns an unmodifiable sequence containing an arbitrary number of items.- Type Parameters:
T- theISequence's item type- Parameters:
items- the items to be contained in the list- Returns:
- an
ISequencecontaining the specified items - Throws:
NullPointerException- if an item isnullor if the array isnull
-
copyOf
Returns an unmodifiable sequence containing the items of the given Collection, in its iteration order. The given Collection must not be null, and it must not contain any null items. If the given Collection is subsequently modified, the returned array item will not reflect such modifications.- Type Parameters:
T- theISequence's item type- Parameters:
collection- aCollectionfrom which items are drawn, must be non-null- Returns:
- an
ISequencecontaining the items of the givenCollection - Throws:
NullPointerException- if collection is null, or if it contains any nulls- Since:
- 10
-
countTypes
@NonNull default <T extends IItem> Map<Class<? extends T>,Integer> countTypes(@NonNull Set<Class<? extends T>> classes) Count the occurrences of items in this sequence that are instances of the provided type classes.For each class in the provided set, this method counts how many items in the sequence are assignable to that class.
- Type Parameters:
T- the base type of the classes to count- Parameters:
classes- the set of classes to count occurrences for- Returns:
- a map from each class to the count of matching items
-
getItemTypes
Get a list of the Java class types for each item in this sequence.- Returns:
- a list of class types corresponding to each item in the sequence
-