Class ComparisonUtils.Sequence<U>

  • Type Parameters:
    U - the type of elements in this sequence
    Enclosing class:
    ComparisonUtils

    public static class ComparisonUtils.Sequence<U>
    extends Object
    The sequence of elements. Allows to get subsequences from this sequence quickly.
    • Constructor Detail

      • Sequence

        public Sequence​(List<U> originalSequence)
        Creates a new instance. The start and end indexes will be taken as zero and the original sequence size.
        Parameters:
        originalSequence - the original sequence, cannot be null
      • Sequence

        public Sequence​(List<U> originalSequence,
                        int startIndex,
                        int endIndex)
        Creates a new instance.
        Parameters:
        originalSequence - the original sequence, cannot be null
        startIndex - the start index (inclusive)
        endIndex - the end index (exclusive)
    • Method Detail

      • get

        public U get​(int index)
        Returns the element at the specified position in this sequence.
        Parameters:
        index - the index of the element to return
        Returns:
        the element at the specified position in this sequence
        Throws:
        IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
      • size

        public int size()
        Returns the number of elements in this sequence.
        Returns:
        the number of elements in this sequence
      • isEmpty

        public boolean isEmpty()
        Returns true if this sequence contains no elements.
        Returns:
        true if this sequence contains no elements, false otherwise
      • contains

        public boolean contains​(U element,
                                BiFunction<U,​U,​Boolean> equalityFunction)
        Returns true if this sequence contains the specified element.
        Parameters:
        element - the element whose presence in this sequence is to be tested
        equalityFunction - the function of equality of elements, cannot be null
        Returns:
        true if this sequence contains the specified element, false otherwise
      • subSequence

        public ComparisonUtils.Sequence<U> subSequence​(int fromIndex,
                                                       int toIndex)
        Returns a view of the portion of this sequence between the specified fromIndex (inclusive) and toIndex (exclusive).
        Parameters:
        fromIndex - the low endpoint (inclusive) of the subSequence
        toIndex - the high endpoint (exclusive) of the subSequence
        Returns:
        a view of the specified range within this sequence, never null
      • toList

        public List<U> toList()
        Returns this sequnce as list.
        Returns:
        this sequnce as list, never null
      • reverse

        public ComparisonUtils.Sequence<U> reverse()
        Reverses the order of the elements in this sequnce.
        Returns:
        the sequence obtained from this sequnce by reversing the order of the elements, never null