Interface Sequence<T>

  • Type Parameters:
    T - the element type
    All Superinterfaces:
    Collection<T>, IStringValueProvider, java.lang.Iterable<T>, IVilGenericType, IVilType
    All Known Implementing Classes:
    ArraySequence, FixedListSequence, ListSequence, UnmodifiableSequence

    public interface Sequence<T>
    extends Collection<T>
    Defines the interface representing a sequence. The iterator is an internal type which is not registered in the TypeRegistry. Please note that iterator with one type parameter will be represented by the iterator itself, iterators over multiple types by an iterator over an object array of instances which can be cast into the given types. This interface and Sequence shall not be applied together in one class!
    Author:
    Holger Eichelberger
    • Field Detail

      • DEFAULT

        static final java.util.List<?> DEFAULT
    • Method Detail

      • at

        T at​(int index)
        Returns a specific element from the collection.
        Parameters:
        index - the index of the element to be returned
        Returns:
        the element or null in case of non-existing data or if index < 0 || index >= Collection.size()
      • get

        T get​(int index)
        Returns a specific element from the collection.
        Parameters:
        index - the index of the element to be returned
        Returns:
        the element or null in case of non-existing data or if index < 0 || index >= Collection.size()
      • selectByType

        Sequence<T> selectByType​(TypeDescriptor<?> type)
        Description copied from interface: Collection
        Does type selection of elements (only the same type).
        Specified by:
        selectByType in interface Collection<T>
        Parameters:
        type - the target type
        Returns:
        the selected elements (the type will be adjusted to the actual type for type)
      • selectByKind

        Sequence<T> selectByKind​(TypeDescriptor<?> type)
        Description copied from interface: Collection
        Does type selection of elements (including subtypes).
        Specified by:
        selectByKind in interface Collection<T>
        Parameters:
        type - the target type
        Returns:
        the selected elements (the type will be adjusted to the actual type for type)
      • typeReject

        Sequence<T> typeReject​(TypeDescriptor<?> type)
        Description copied from interface: Collection
        Does type selection of elements not having the same type (including subtypes).
        Specified by:
        typeReject in interface Collection<T>
        Parameters:
        type - the target type
        Returns:
        the selected elements (the type will be adjusted to the actual type for type)
      • excluding

        Sequence<T> excluding​(Collection<T> sequence)
        Exclude the elements in sequence.
        Parameters:
        sequence - the elements to be excluded
        Returns:
        this set without the elements in set
      • append

        Sequence<T> append​(Collection<T> set)
        Append the elements in set.
        Parameters:
        set - the elements to be appended
        Returns:
        this set including the elements in set
      • union

        Sequence<T> union​(Sequence<T> seq)
        Append the elements in seq.
        Parameters:
        seq - the elements to be appended
        Returns:
        this set including the elements in seq
      • add

        T add​(T element)
        Adds an element to the end of this sequence.
        Parameters:
        element - the element to be added
        Returns:
        element
      • remove

        boolean remove​(T element)
        Removes the first occurrence of the given element from this sequence.
        Parameters:
        element - the element to be removed
        Returns:
        true of the element was removed, false else
      • select

        Sequence<T> select​(ExpressionEvaluator evaluator)
                    throws VilException
        Description copied from interface: Collection
        Selects elements in this collection according to the given expression.
        Specified by:
        select in interface Collection<T>
        Parameters:
        evaluator - the evaluator (results must evaluate to Boolean)
        Returns:
        the selected elements
        Throws:
        VilException - in case that evaluation fails
      • reject

        Sequence<T> reject​(ExpressionEvaluator evaluator)
                    throws VilException
        Description copied from interface: Collection
        Rejects elements in this collection according to the given expression.
        Specified by:
        reject in interface Collection<T>
        Parameters:
        evaluator - the evaluator (results must evaluate to Boolean)
        Returns:
        the rejected elements
        Throws:
        VilException - in case that evaluation fails
      • closure

        Set<?> closure​(ExpressionEvaluator evaluator)
                throws VilException
        Description copied from interface: Collection
        Calculates a transitive closure over elements provided by this collection and evaluator.
        Specified by:
        closure in interface Collection<T>
        Parameters:
        evaluator - the evaluator providing the links/collections to follow
        Returns:
        the closure
        Throws:
        VilException - in case that evaluation fails
      • collect

        Sequence<?> collect​(ExpressionEvaluator evaluator)
                     throws VilException
        Description copied from interface: Collection
        Collects the application of evaluator to each individual element and flattens nested structures.
        Specified by:
        collect in interface Collection<T>
        Parameters:
        evaluator - the evaluator (results must evaluate to Boolean)
        Returns:
        the application results
        Throws:
        VilException - in case that evaluation fails
      • collectNested

        Sequence<?> collectNested​(ExpressionEvaluator evaluator)
                           throws VilException
        Description copied from interface: Collection
        Collects the application of evaluator to each individual element and keeps nested structures.
        Specified by:
        collectNested in interface Collection<T>
        Parameters:
        evaluator - the evaluator (results must evaluate to Boolean)
        Returns:
        the application results
        Throws:
        VilException - in case that evaluation fails
      • toSet

        Set<T> toSet()
        Turns this sequence into a set.
        Returns:
        the set containing the elements of this sequence (excluding duplicates)
      • sortAlpha

        Sequence<T> sortAlpha()
        Returns an alphabetically sorted sequence. Elements are considered using their (internal) string representations and sorted.
        Returns:
        the sorted sequence
      • revert

        Sequence<T> revert()
        Reverts this sequence.
        Returns:
        the reverted sequence
      • first

        T first()
        Returns the first element.
        Returns:
        the first element
      • last

        T last()
        Returns the last element.
        Returns:
        the last element
      • indexOf

        int indexOf​(T element)
        Returns the index of element in this sequence.
        Parameters:
        element - the element to return the index for
        Returns:
        the 0-based index of element in this sequence, -1 if not found
      • mapSequence

        Map<T,​T> mapSequence​(Sequence<T> other)
        Maps the elements of this sequence to the elements of other and returns the mapping pairs (based on the equals operation) in the given sequence. Please note that both sequences must have exactly one type parameter.
        Parameters:
        other - the second sequence to map against
        Returns:
        the mapping (key is taken from this sequence, value from other)
      • mapAny

        Map<T,​T> mapAny​(Sequence<T> other)
        Maps the elements of this sequence to the elements of other and returns the mapping pairs (based on the equals operation) regardless of the sequence. Please note that both sequences must have exactly one type parameter.
        Parameters:
        other - the second sequence to map against
        Returns:
        the mapping (key is taken from this sequence, value from other)
      • toMappedList

        java.util.List<T> toMappedList()
        Converts back to a list for utilizing this with external classes.
        Returns:
        the internal map
      • flatten

        Sequence<?> flatten()
                     throws VilException
        Description copied from interface: Collection
        Flattens this collection if needed, i.e., flatten sub-collections.
        Specified by:
        flatten in interface Collection<T>
        Returns:
        the flattened collection
        Throws:
        VilException - in case of type incompatibilities
      • append

        Sequence<T> append​(T object)
        Returns the combined sequence of seq and objectappended.
        Parameters:
        object - the object to append
        Returns:
        the combined sequence
      • prepend

        Sequence<T> prepend​(T object)
        Returns the combined sequence of object prepended before this sequence.
        Parameters:
        object - the object to prepend
        Returns:
        the combined sequence
      • insertAt

        Sequence<T> insertAt​(int index,
                             T object)
        Returns the sequence having object inserted at position index.
        Parameters:
        index - the index to insert at
        object - the object to insert
        Returns:
        the combined sequence
      • subSequence

        Sequence<T> subSequence​(int lower,
                                int upper)
        Returns the sub-sequence of this sequence.
        Parameters:
        lower - the lower index where the sub-sequence shall start
        upper - the end index where the sub-sequence shall end
        Returns:
        the sub-sequence
      • hasDuplicates

        boolean hasDuplicates()
        Returns whether at least one of the elements in operand has a duplicate.
        Returns:
        true for duplicates, false else
      • overlaps

        boolean overlaps​(Sequence<T> other)
        Returns the sequence in that this sequence and other have in common.
        Parameters:
        other - the other sequence
        Returns:
        true for overlaps, false else
      • isSubsequenceOf

        boolean isSubsequenceOf​(Sequence<T> other)
        Returns whether operand is a subsequence (considering the sequence and including equality) of other.
        Parameters:
        other - the other sequence
        Returns:
        true for subsequence, false else
      • joinfields

        java.lang.String joinfields​(java.lang.String separator,
                                    java.lang.String begin,
                                    java.lang.String end)
        Returns a concatenation of the string representation of elements, with begin as lead in, sep as separator between the elements and end as lead out. (QVT)
        Parameters:
        separator - the separator
        begin - the lead in
        end - the lead out
        Returns:
        the concatenated result
      • removeAll

        void removeAll​(T element)
        Removes all elements equal to element. (QVT)
        Parameters:
        element - the element to remove all copies for
      • removeAt

        T removeAt​(int index)
        Removes the element at index. (QVT)
        Parameters:
        index - the index of the element to remove
        Returns:
        the removed index, undefined if index is not valid
      • removeFirst

        T removeFirst()
        Removes the first element. (QVT)
        Returns:
        the removed element, undefined if there is no first element
      • removeLast

        T removeLast()
        Removes the last element. (QVT)
        Returns:
        the removed element, undefined if there is no last element