A List which can be efficiently searched for occurrences of a given element, or for inclusions of a given sublist of elements. This interface provides operations for finding:

  • occurrences of a single value in the list, and
  • inclusions of a given sublist of values in the list.

Occurrences and inclusions are identified by a list index at which the value or sublist of values occurs in the list. In the case of an inclusion, it is the index of the first matching value from the sublist.

Inclusions may overlap. For example:

"yoyoyoyoyo".inclusions("yoy")

produces the stream { 0, 2, 4, 6 }.

An empty list is considered to be included at every index, including the index List.size at the very end of the list. Thus:

"hello".inclusions("")

produces the stream { 0, 1, 2, 3, 4, 5 }, with 6 inclusions in a string of length 5.

In particular:

  • "".inclusions("x") is the empty stream {}, but
  • "".inclusions("") is the stream { 0 }.
See also String, Array
Since 1.2.0

no type hierarchy

Inherited Attributes
Attributes inherited from: Object
Attributes inherited from: Collection<Element>
Attributes inherited from: Correspondence<Key,Item>
Attributes inherited from: Iterable<Element,Absent>
Attributes inherited from: List<Element>
Methods
firstInclusionSource Codeshared default Integer? firstInclusion(List<Element> sublist, Integer from = 0)

The first index in this list at which the given list occurs as a sublist, that is greater than or equal to the optional starting index.

Parameters:
  • from = 0

    The smallest index to consider.

firstOccurrenceSource Codeshared default Integer? firstOccurrence(Element element, Integer from = 0, Integer length = ...)

The first index in this list at which the given value occurs, that falls within the segment from:length defined by the optional starting index and length.

Parameters:
  • element

    The value. If null, it is considered to occur at any index in this list with a null element.

  • from = 0

    The smallest index to consider.

  • length = size-from

    The number of indexes to consider.

includesSource Codeshared default Boolean includes(List<Element> sublist, Integer from = 0)

Determine if the given list occurs as a sublist at some index in this list, at any index that is greater than or equal to the optional starting index.

Parameters:
  • from = 0

    The smallest index to consider.

includesAtSource Codeshared default Boolean includesAt(Integer index, List<Element> sublist)

Determine if the given list occurs as a sublist at the given index of this list.

Parameters:
  • index

    The index at which the sublist might occur.

inclusionsSource Codeshared default {Integer*} inclusions(List<Element> sublist, Integer from = 0)

The indexes in this list at which the given list occurs as a sublist, that are greater than or equal to the optional starting index.

Parameters:
  • from = 0

    The smallest index to consider.

lastInclusionSource Codeshared default Integer? lastInclusion(List<Element> sublist, Integer from = 0)

The last index in this list at which the given list occurs as a sublist, that falls within the range 0:size-from+1-sublist.size defined by the optional starting index, interpreted as a reverse index counting from the end of the list.

Parameters:
  • from = 0

    The smallest index to consider, interpreted as a reverse index counting from the end of the list, where 0 is the last element of the list, and size-1 is the first element of the list.

lastOccurrenceSource Codeshared default Integer? lastOccurrence(Element element, Integer from = 0, Integer length = ...)

The last index in this list at which the given value occurs, that falls within the range size-length-from:length defined by the optional starting index, interpreted as a reverse index counting from the end of the list, and length.

Parameters:
  • element

    The value. If null, it is considered to occur at any index in this list with a null element.

  • from = 0

    The smallest index to consider, interpreted as a reverse index counting from the end of the list, where 0 is the last element of the list, and size-1 is the first element of the list.

  • length = size-from

    The number of indexes to consider.

occurrencesSource Codeshared default {Integer*} occurrences(Element element, Integer from = 0, Integer length = ...)

The indexes in this list at which the given value occurs.

Parameters:
  • element

    The value. If null, it is considered to occur at any index in this list with a null element.

  • from = 0

    The smallest index to consider.

  • length = size-from

    The number of indexes to consider.

occursSource Codeshared default Boolean occurs(Element element, Integer from = 0, Integer length = ...)

Determines if the given value occurs as an element of this list, at any index that falls within the segment from:length defined by the optional starting index and length.

Parameters:
  • element

    The value. If null, it is considered to occur at any index in this list with a null element.

  • from = 0

    The smallest index to consider.

  • length = size-from

    The number of indexes to consider.

occursAtSource Codeshared default Boolean occursAt(Integer index, Element element)

Determines if the given value occurs at the given index in this list.

Parameters:
  • index

    The index at which the value might occur.

  • element

    The value. If null, it is considered to occur at any index in this list with a null element.

Inherited Methods
Methods inherited from: Object
Methods inherited from: Category<Element>
Methods inherited from: Collection<Element>
Methods inherited from: Correspondence<Key,Item>
Methods inherited from: Iterable<Element,Absent>
Methods inherited from: List<Element>
Methods inherited from: Ranged<Index,Element,Subrange>