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 theTypeRegistry. 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 andSequenceshall not be applied together in one class!- Author:
- Holger Eichelberger
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.ssehub.easy.instantiation.core.model.vilTypes.IStringValueProvider
IStringValueProvider.StringComparator
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.List<?>DEFAULT
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Tadd(T element)Adds an element to the end of this sequence.Sequence<T>append(Collection<T> set)Append the elements inset.Sequence<T>append(T object)Returns the combined sequence ofseqandobjectappended.Tat(int index)Returns a specific element from the collection.Sequence<T>cloneCollection()Clones this collection.Set<?>closure(ExpressionEvaluator evaluator)Calculates a transitive closure over elements provided by this collection andevaluator.Sequence<?>collect(ExpressionEvaluator evaluator)Collects the application ofevaluatorto each individual element and flattens nested structures.Sequence<?>collectNested(ExpressionEvaluator evaluator)Collects the application ofevaluatorto each individual element and keeps nested structures.Sequence<T>excluding(Collection<T> sequence)Exclude the elements insequence.Tfirst()Returns the first element.Sequence<?>flatten()Flattens this collection if needed, i.e., flatten sub-collections.Tget(int index)Returns a specific element from the collection.booleanhasDuplicates()Returns whether at least one of the elements in operand has a duplicate.intindexOf(T element)Returns the index ofelementin this sequence.Sequence<T>insertAt(int index, T object)Returns the sequence havingobjectinserted at positionindex.booleanisSubsequenceOf(Sequence<T> other)Returns whether operand is a subsequence (considering the sequence and including equality) ofother.java.lang.Stringjoinfields(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.Tlast()Returns the last element.Map<T,T>mapAny(Sequence<T> other)Maps the elements of this sequence to the elements ofotherand returns the mapping pairs (based on the equals operation) regardless of the sequence.Map<T,T>mapSequence(Sequence<T> other)Maps the elements of this sequence to the elements ofotherand returns the mapping pairs (based on the equals operation) in the given sequence.booleanoverlaps(Sequence<T> other)Returns the sequence in that this sequence andotherhave in common.Sequence<T>prepend(T object)Returns the combined sequence ofobjectprepended before this sequence.Sequence<T>reject(ExpressionEvaluator evaluator)Rejects elements in this collection according to the given expression.booleanremove(T element)Removes the first occurrence of the given element from this sequence.voidremoveAll(T element)Removes all elements equal toelement.TremoveAt(int index)Removes the element atindex.TremoveFirst()Removes the first element.TremoveLast()Removes the last element.Sequence<T>revert()Reverts this sequence.Sequence<T>select(ExpressionEvaluator evaluator)Selects elements in this collection according to the given expression.Sequence<T>selectByKind(TypeDescriptor<?> type)Does type selection of elements (including subtypes).Sequence<T>selectByType(TypeDescriptor<?> type)Does type selection of elements (only the same type).Sequence<T>sortAlpha()Returns an alphabetically sorted sequence.Sequence<T>sortedBy(ExpressionEvaluator evaluator)Sorts the elements in this sequence according to the given expression in ascending order.Sequence<T>subSequence(int lower, int upper)Returns the sub-sequence of this sequence.java.util.List<T>toMappedList()Converts back to a list for utilizing this with external classes.Set<T>toSet()Turns this sequence into a set.Sequence<T>typeReject(TypeDescriptor<?> type)Does type selection of elements not having the same type (including subtypes).Sequence<T>union(Sequence<T> seq)Append the elements inseq.-
Methods inherited from interface net.ssehub.easy.instantiation.core.model.vilTypes.Collection
allowSequenceAdjustment, any, apply, asSequence, asSet, avg, clear, count, excludes, excludesAll, exists, forAll, getGenericParameterCount, getGenericParameterType, includes, includesAll, isAcyclic, isEmpty, isEquals, isNotEmpty, isUnique, iterator, max, min, one, product, size, sum
-
Methods inherited from interface net.ssehub.easy.instantiation.core.model.vilTypes.IStringValueProvider
getStringValue
-
Methods inherited from interface net.ssehub.easy.instantiation.core.model.vilTypes.IVilGenericType
getType
-
-
-
-
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:CollectionDoes type selection of elements (only the same type).- Specified by:
selectByTypein interfaceCollection<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:CollectionDoes type selection of elements (including subtypes).- Specified by:
selectByKindin interfaceCollection<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:CollectionDoes type selection of elements not having the same type (including subtypes).- Specified by:
typeRejectin interfaceCollection<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 insequence.- 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 inset.- 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 inseq.- 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:
trueof the element was removed,falseelse
-
select
Sequence<T> select(ExpressionEvaluator evaluator) throws VilException
Description copied from interface:CollectionSelects elements in this collection according to the given expression.- Specified by:
selectin interfaceCollection<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:CollectionRejects elements in this collection according to the given expression.- Specified by:
rejectin interfaceCollection<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:CollectionCalculates a transitive closure over elements provided by this collection andevaluator.- Specified by:
closurein interfaceCollection<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:CollectionCollects the application ofevaluatorto each individual element and flattens nested structures.- Specified by:
collectin interfaceCollection<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:CollectionCollects the application ofevaluatorto each individual element and keeps nested structures.- Specified by:
collectNestedin interfaceCollection<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
-
sortedBy
Sequence<T> sortedBy(ExpressionEvaluator evaluator) throws VilException
Sorts the elements in this sequence according to the given expression in ascending order.- Specified by:
sortedByin interfaceCollection<T>- Parameters:
evaluator- the evaluator- Returns:
- the selected elements
- Throws:
VilException- in case that selection fails
-
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 ofelementin this sequence.- Parameters:
element- the element to return the index for- Returns:
- the 0-based index of
elementin this sequence,-1if not found
-
mapSequence
Map<T,T> mapSequence(Sequence<T> other)
Maps the elements of this sequence to the elements ofotherand 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 ofotherand 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:CollectionFlattens this collection if needed, i.e., flatten sub-collections.- Specified by:
flattenin interfaceCollection<T>- Returns:
- the flattened collection
- Throws:
VilException- in case of type incompatibilities
-
append
Sequence<T> append(T object)
Returns the combined sequence ofseqandobjectappended.- Parameters:
object- the object to append- Returns:
- the combined sequence
-
prepend
Sequence<T> prepend(T object)
Returns the combined sequence ofobjectprepended before this sequence.- Parameters:
object- the object to prepend- Returns:
- the combined sequence
-
insertAt
Sequence<T> insertAt(int index, T object)
Returns the sequence havingobjectinserted at positionindex.- Parameters:
index- the index to insert atobject- 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 startupper- 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:
truefor duplicates,falseelse
-
overlaps
boolean overlaps(Sequence<T> other)
Returns the sequence in that this sequence andotherhave in common.- Parameters:
other- the other sequence- Returns:
truefor overlaps,falseelse
-
isSubsequenceOf
boolean isSubsequenceOf(Sequence<T> other)
Returns whether operand is a subsequence (considering the sequence and including equality) ofother.- Parameters:
other- the other sequence- Returns:
truefor subsequence,falseelse
-
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, withbeginas lead in,sepas separator between the elements andendas lead out. (QVT)- Parameters:
separator- the separatorbegin- the lead inend- the lead out- Returns:
- the concatenated result
-
removeAll
void removeAll(T element)
Removes all elements equal toelement. (QVT)- Parameters:
element- the element to remove all copies for
-
removeAt
T removeAt(int index)
Removes the element atindex. (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
-
cloneCollection
Sequence<T> cloneCollection()
Description copied from interface:CollectionClones this collection. (QVT)- Specified by:
cloneCollectionin interfaceCollection<T>- Returns:
- a clone of this collection
-
-