Class SequenceOperations
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.vilTypes.SequenceOperations
-
public class SequenceOperations extends java.lang.ObjectCommon operations for sequences.- Author:
- Holger Eichelberger
-
-
Constructor Summary
Constructors Constructor Description SequenceOperations()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static <T> voidaddAll(java.util.List<T> list, Sequence<T> seq)Adds all elements fromseqtolist.private static <T> voidaddAll(java.util.List<T> list, Sequence<T> seq, int lower, int upper)Adds all elements fromseqtolist.static <T> java.util.List<T>append(Sequence<T> seq, T object)Returns the combined sequence ofobjectappended beforeseq.private static <T> booleanequals(T elt1, T elt2)Compares two elements for equality using values for decision variables.static <T> booleanhasDuplicates(Sequence<T> seq)Returns whether at least one of the elements insethas a duplicate.static <T> java.util.List<T>insertAt(Sequence<T> seq, int index, T object)Returns the sequence havingobjectinserted at positionindexintoseq.static <T> booleanisSubsequenceOf(Sequence<T> s1, Sequence<T> s2)Returns whether operand is a subsequence (considering the sequence and including equality) ofother.static <T> java.lang.Stringjoinfields(Sequence<T> sequence, java.lang.String separator, java.lang.String begin, java.lang.String end)Returns a concatenation of the string representation of elements, withbeginas lead in,sepas separator between the elements andendas lead out.static <T> Map<T,T>mapAny(Sequence<T> seq1, Sequence<T> seq2)Maps the elements ofseq1to the elements ofseq2and 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 ofseq1to the elements ofseq2and returns the mapping pairs (based on the equals operation) in the given sequence.static <T> booleanoverlaps(Sequence<T> s1, Sequence<T> s2)Returns the sequence in thats1ands2have in common.static <T> java.util.List<T>prepend(Sequence<T> seq, T object)Returns the combined sequence ofobjectprepended beforeseq.static <T> java.util.List<T>subSequence(Sequence<T> seq, int lower, int upper)Returns the sub-sequence ofseq.static <T> java.util.List<T>union(Sequence<T> seq1, Sequence<T> seq2)Returns the concatenated sequence ofseq1andseq2.
-
-
-
Method Detail
-
mapSequence
public static <T> Map<T,T> mapSequence(Sequence<T> seq1, Sequence<T> seq2)
Maps the elements ofseq1to the elements ofseq2and 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 mapseq2- 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 comparedelt2- the second element to be compared- Returns:
trueifelt1andelt2are considered to be equal,falseelse
-
mapAny
public static <T> Map<T,T> mapAny(Sequence<T> seq1, Sequence<T> seq2)
Maps the elements ofseq1to the elements ofseq2and 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 mapseq2- 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 fromseqtolist. Valid indexes are assumed. No check happens- Type Parameters:
T- the element type- Parameters:
list- the list to add all elements toseq- the sequence to take the elements fromlower- the lower 0-based index where to start addingupper- 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 fromseqtolist.- Type Parameters:
T- the element type- Parameters:
list- the list to add all elements toseq- 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 ofseq1andseq2.- Type Parameters:
T- the element type- Parameters:
seq1- the first sequenceseq2- 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 ofobjectappended beforeseq.- Type Parameters:
T- the element type- Parameters:
seq- the sequenceobject- 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 ofobjectprepended beforeseq.- Type Parameters:
T- the element type- Parameters:
seq- the sequenceobject- 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 havingobjectinserted at positionindexintoseq.- Type Parameters:
T- the element type- Parameters:
seq- the sequenceindex- the index to insert atobject- 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 ofseq.- Type Parameters:
T- the element type- Parameters:
seq- the sequence to derive the sub-sequence fromlower- the lower index where the sub-sequence shall startupper- 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 insethas a duplicate.- Type Parameters:
T- the element type- Parameters:
seq- the sequence- Returns:
truefor duplicates,falseelse
-
overlaps
public static <T> boolean overlaps(Sequence<T> s1, Sequence<T> s2)
Returns the sequence in thats1ands2have in common.- Type Parameters:
T- the element type- Parameters:
s1- the first sequences2- the second sequence- Returns:
truefor overlaps,falseelse
-
isSubsequenceOf
public static <T> boolean isSubsequenceOf(Sequence<T> s1, Sequence<T> s2)
Returns whether operand is a subsequence (considering the sequence and including equality) ofother.- Type Parameters:
T- the element type- Parameters:
s1- the first sequences2- the second sequence- Returns:
truefor subsequence,falseelse
-
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, withbeginas lead in,sepas separator between the elements andendas lead out. (QVT)- Type Parameters:
T- the sequence element type- Parameters:
sequence- the sequence to operate onseparator- the separatorbegin- the lead inend- the lead out- Returns:
- the concatenated result
-
-