Class SequenceOperations


  • public class SequenceOperations
    extends java.lang.Object
    Common operations for sequences.
    Author:
    Holger Eichelberger
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static <T> void addAll​(java.util.List<T> list, Sequence<T> seq)
      Adds all elements from seq to list.
      private static <T> void addAll​(java.util.List<T> list, Sequence<T> seq, int lower, int upper)
      Adds all elements from seq to list.
      static <T> java.util.List<T> append​(Sequence<T> seq, T object)
      Returns the combined sequence of object appended before seq.
      private static <T> boolean equals​(T elt1, T elt2)
      Compares two elements for equality using values for decision variables.
      static <T> boolean hasDuplicates​(Sequence<T> seq)
      Returns whether at least one of the elements in set has a duplicate.
      static <T> java.util.List<T> insertAt​(Sequence<T> seq, int index, T object)
      Returns the sequence having object inserted at position index into seq.
      static <T> boolean isSubsequenceOf​(Sequence<T> s1, Sequence<T> s2)
      Returns whether operand is a subsequence (considering the sequence and including equality) of other.
      static <T> java.lang.String joinfields​(Sequence<T> sequence, 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.
      static <T> Map<T,​T> mapAny​(Sequence<T> seq1, Sequence<T> seq2)
      Maps the elements of seq1 to the elements of seq2 and returns the mapping pairs (based on the equals operation) regardless of their sequence.
      static <T> Map<T,​T> mapSequence​(Sequence<T> seq1, Sequence<T> seq2)
      Maps the elements of seq1 to the elements of seq2 and returns the mapping pairs (based on the equals operation) in the given sequence.
      static <T> boolean overlaps​(Sequence<T> s1, Sequence<T> s2)
      Returns the sequence in that s1 and s2 have in common.
      static <T> java.util.List<T> prepend​(Sequence<T> seq, T object)
      Returns the combined sequence of object prepended before seq.
      static <T> java.util.List<T> subSequence​(Sequence<T> seq, int lower, int upper)
      Returns the sub-sequence of seq.
      static <T> java.util.List<T> union​(Sequence<T> seq1, Sequence<T> seq2)
      Returns the concatenated sequence of seq1 and seq2.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SequenceOperations

        public SequenceOperations()
    • Method Detail

      • mapSequence

        public static <T> Map<T,​T> mapSequence​(Sequence<T> seq1,
                                                     Sequence<T> seq2)
        Maps the elements of seq1 to the elements of seq2 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.
        Type Parameters:
        T - the element type
        Parameters:
        seq1 - the first sequence to map
        seq2 - the second sequence to map against
        Returns:
        the mapping (key is taken from this sequence, value from other)
      • equals

        private static <T> boolean equals​(T elt1,
                                          T elt2)
        Compares two elements for equality using values for decision variables.
        Type Parameters:
        T - the element type
        Parameters:
        elt1 - the first element to be compared
        elt2 - the second element to be compared
        Returns:
        true if elt1 and elt2 are considered to be equal, false else
      • mapAny

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

        private static <T> void addAll​(java.util.List<T> list,
                                       Sequence<T> seq,
                                       int lower,
                                       int upper)
        Adds all elements from seq to list. Valid indexes are assumed. No check happens
        Type Parameters:
        T - the element type
        Parameters:
        list - the list to add all elements to
        seq - the sequence to take the elements from
        lower - the lower 0-based index where to start adding
        upper - the upper 0-based index where to end adding (including)
      • addAll

        private static <T> void addAll​(java.util.List<T> list,
                                       Sequence<T> seq)
        Adds all elements from seq to list.
        Type Parameters:
        T - the element type
        Parameters:
        list - the list to add all elements to
        seq - the sequence to take the elements from
      • union

        public static <T> java.util.List<T> union​(Sequence<T> seq1,
                                                  Sequence<T> seq2)
        Returns the concatenated sequence of seq1 and seq2.
        Type Parameters:
        T - the element type
        Parameters:
        seq1 - the first sequence
        seq2 - the second sequence
        Returns:
        the concatenated sequence
      • append

        public static <T> java.util.List<T> append​(Sequence<T> seq,
                                                   T object)
        Returns the combined sequence of object appended before seq.
        Type Parameters:
        T - the element type
        Parameters:
        seq - the sequence
        object - the object to prepend
        Returns:
        the combined sequence
      • prepend

        public static <T> java.util.List<T> prepend​(Sequence<T> seq,
                                                    T object)
        Returns the combined sequence of object prepended before seq.
        Type Parameters:
        T - the element type
        Parameters:
        seq - the sequence
        object - the object to prepend
        Returns:
        the combined sequence
      • insertAt

        public static <T> java.util.List<T> insertAt​(Sequence<T> seq,
                                                     int index,
                                                     T object)
        Returns the sequence having object inserted at position index into seq.
        Type Parameters:
        T - the element type
        Parameters:
        seq - the sequence
        index - the index to insert at
        object - the object to insert
        Returns:
        the combined sequence
      • subSequence

        public static <T> java.util.List<T> subSequence​(Sequence<T> seq,
                                                        int lower,
                                                        int upper)
        Returns the sub-sequence of seq.
        Type Parameters:
        T - the element type
        Parameters:
        seq - the sequence to derive the sub-sequence from
        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

        public static <T> boolean hasDuplicates​(Sequence<T> seq)
        Returns whether at least one of the elements in set has a duplicate.
        Type Parameters:
        T - the element type
        Parameters:
        seq - the sequence
        Returns:
        true for duplicates, false else
      • overlaps

        public static <T> boolean overlaps​(Sequence<T> s1,
                                           Sequence<T> s2)
        Returns the sequence in that s1 and s2 have in common.
        Type Parameters:
        T - the element type
        Parameters:
        s1 - the first sequence
        s2 - the second sequence
        Returns:
        true for overlaps, false else
      • isSubsequenceOf

        public static <T> boolean isSubsequenceOf​(Sequence<T> s1,
                                                  Sequence<T> s2)
        Returns whether operand is a subsequence (considering the sequence and including equality) of other.
        Type Parameters:
        T - the element type
        Parameters:
        s1 - the first sequence
        s2 - the second sequence
        Returns:
        true for subsequence, false else
      • joinfields

        public static <T> java.lang.String joinfields​(Sequence<T> sequence,
                                                      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)
        Type Parameters:
        T - the sequence element type
        Parameters:
        sequence - the sequence to operate on
        separator - the separator
        begin - the lead in
        end - the lead out
        Returns:
        the concatenated result