Class ListSequence<T>
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.vilTypes.AbstractCollectionWrapper<T>
-
- net.ssehub.easy.instantiation.core.model.vilTypes.AbstractListWrapper<T>
-
- net.ssehub.easy.instantiation.core.model.vilTypes.ListSequence<T>
-
- Type Parameters:
T- the element type
- All Implemented Interfaces:
java.lang.Iterable<T>,Collection<T>,IStringValueProvider,IVilGenericType,IVilType,Sequence<T>
- Direct Known Subclasses:
FixedListSequence
public class ListSequence<T> extends AbstractListWrapper<T> implements Sequence<T>
Implements an array wrapper for the VIL sequence type.- 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 inherited from class net.ssehub.easy.instantiation.core.model.vilTypes.AbstractCollectionWrapper
NUMBER_COMPARATOR
-
-
Constructor Summary
Constructors Constructor Description ListSequence(java.util.List<T> list, java.lang.Class<?> param)Creates a new array collection wrapper using the default type registry.ListSequence(java.util.List<T> list, TypeDescriptor<?>... params)Creates a new array collection wrapper using the default type registry.ListSequence(java.util.List<T> list, TypeRegistry registry, java.lang.Class<?> param)Creates a new array collection wrapper.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Tadd(T element)Adds an element to the end of this sequence.booleanallowSequenceAdjustment()Returns whether aIStringValueProvidermay reorder the sequence of this collection for (test) output.Sequence<T>append(Collection<T> sequence)Append the elements inset.Sequence<T>append(T object)Returns the combined sequence ofseqandobjectappended.java.lang.Objectapply(ExpressionEvaluator evaluator)Processes elements in this set by applying to given expression.Sequence<T>asSequence()Turns this collection into a sequence.Set<T>asSet()Turns this collection into a set.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.static <T> Sequence<T>empty(TypeDescriptor<?> param)Returns an empty sequence for one type parameter.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.booleanisEquals(Collection<?> elements)Returns whether this collection is equal toelements.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.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 class net.ssehub.easy.instantiation.core.model.vilTypes.AbstractListWrapper
clear, equals, getGenericParameter, getGenericParameterCount, getGenericParameterType, getList, getStringValue, getType, hashCode, iterator, removeDuplicates, size, toMappedList, toMappedSet, toString
-
Methods inherited from class net.ssehub.easy.instantiation.core.model.vilTypes.AbstractCollectionWrapper
aggregate, any, any, append, apply, avg, closure, collect, collect, constructType, containsAll, count, equals, excludes, excludesAll, excluding, exists, exists, flatten, forAll, forAll, getFlattenedParams, includes, includesAll, including, intersection, isAcyclic, isAcyclic, isEmpty, isNotEmpty, isUnique, isUnique, max, min, one, one, product, revertImpl, sameElements, select, select, selectByType, selectByType, sortAlphaImpl, sortImpl, sortImpl, sum, union
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.ssehub.easy.instantiation.core.model.vilTypes.Collection
any, avg, clear, count, excludes, excludesAll, exists, forAll, getGenericParameterCount, getGenericParameterType, includes, includesAll, isAcyclic, isEmpty, 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
-
Methods inherited from interface net.ssehub.easy.instantiation.core.model.vilTypes.Sequence
toMappedList
-
-
-
-
Constructor Detail
-
ListSequence
public ListSequence(java.util.List<T> list, java.lang.Class<?> param)
Creates a new array collection wrapper using the default type registry.- Parameters:
list- the wrapped listparam- the only type parameter characterizing
-
ListSequence
public ListSequence(java.util.List<T> list, TypeRegistry registry, java.lang.Class<?> param)
Creates a new array collection wrapper.- Parameters:
list- the wrapped listregistry- the registry to convertparamparam- the only type parameter characterizing
-
ListSequence
public ListSequence(java.util.List<T> list, TypeDescriptor<?>... params)
Creates a new array collection wrapper using the default type registry.- Parameters:
list- the wrapped listparams- the type parameter characterizing
-
-
Method Detail
-
at
public T at(int index)
Description copied from interface:SequenceReturns a specific element from the collection.- Specified by:
atin interfaceSequence<T>- 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
public T get(int index)
Description copied from interface:SequenceReturns a specific element from the collection.- Specified by:
getin interfaceSequence<T>- 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()
-
empty
public static final <T> Sequence<T> empty(TypeDescriptor<?> param)
Returns an empty sequence for one type parameter.- Type Parameters:
T- the element type- Parameters:
param- the type parameter characterizing- Returns:
- an empty sequence
-
selectByType
public Sequence<T> selectByType(TypeDescriptor<?> type)
Description copied from interface:CollectionDoes type selection of elements (only the same type).- Specified by:
selectByTypein interfaceCollection<T>- Specified by:
selectByTypein interfaceSequence<T>- Parameters:
type- the target type- Returns:
- the selected elements (the type will be adjusted to the actual
type for
type)
-
selectByKind
public Sequence<T> selectByKind(TypeDescriptor<?> type)
Description copied from interface:CollectionDoes type selection of elements (including subtypes).- Specified by:
selectByKindin interfaceCollection<T>- Specified by:
selectByKindin interfaceSequence<T>- Parameters:
type- the target type- Returns:
- the selected elements (the type will be adjusted to the actual
type for
type)
-
typeReject
public 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>- Specified by:
typeRejectin interfaceSequence<T>- Parameters:
type- the target type- Returns:
- the selected elements (the type will be adjusted to the actual
type for
type)
-
excluding
public Sequence<T> excluding(Collection<T> sequence)
Description copied from interface:SequenceExclude the elements insequence.
-
append
public Sequence<T> append(Collection<T> sequence)
Description copied from interface:SequenceAppend the elements inset.
-
flatten
public Sequence<?> flatten() throws VilException
Description copied from interface:CollectionFlattens this collection if needed, i.e., flatten sub-collections.- Specified by:
flattenin interfaceCollection<T>- Specified by:
flattenin interfaceSequence<T>- Returns:
- the flattened collection
- Throws:
VilException- in case of type incompatibilities
-
select
public 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>- Specified by:
selectin interfaceSequence<T>- Parameters:
evaluator- the evaluator (results must evaluate to Boolean)- Returns:
- the selected elements
- Throws:
VilException- in case that evaluation fails
-
reject
public 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>- Specified by:
rejectin interfaceSequence<T>- Parameters:
evaluator- the evaluator (results must evaluate to Boolean)- Returns:
- the rejected elements
- Throws:
VilException- in case that evaluation fails
-
collect
public 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>- Specified by:
collectin interfaceSequence<T>- Parameters:
evaluator- the evaluator (results must evaluate to Boolean)- Returns:
- the application results
- Throws:
VilException- in case that evaluation fails
-
collectNested
public 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>- Specified by:
collectNestedin interfaceSequence<T>- Parameters:
evaluator- the evaluator (results must evaluate to Boolean)- Returns:
- the application results
- Throws:
VilException- in case that evaluation fails
-
closure
public 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>- Specified by:
closurein interfaceSequence<T>- Parameters:
evaluator- the evaluator providing the links/collections to follow- Returns:
- the closure
- Throws:
VilException- in case that evaluation fails
-
apply
public java.lang.Object apply(ExpressionEvaluator evaluator) throws VilException
Description copied from interface:CollectionProcesses elements in this set by applying to given expression.- Specified by:
applyin interfaceCollection<T>- Parameters:
evaluator- the evaluator holding the iterator / expression to apply- Returns:
- the aggregated value, null in case of no aggregation
- Throws:
VilException- in case that selection fails
-
isEquals
public boolean isEquals(Collection<?> elements)
Description copied from interface:CollectionReturns whether this collection is equal toelements. Please note that the actual semantics, i.e., whether the elements must also be in the same sequence, depends on the actual semantics of the collection.- Specified by:
isEqualsin interfaceCollection<T>- Parameters:
elements- the collection to be tested- Returns:
trueif both collections are considered to be equal,falseelse
-
toSet
public Set<T> toSet()
Description copied from interface:SequenceTurns this sequence into a set.
-
asSet
public Set<T> asSet()
Description copied from interface:CollectionTurns this collection into a set.- Specified by:
asSetin interfaceCollection<T>- Returns:
- the set containing the elements of this collection (excluding duplicates)
-
asSequence
public Sequence<T> asSequence()
Description copied from interface:CollectionTurns this collection into a sequence.- Specified by:
asSequencein interfaceCollection<T>- Returns:
- the set containing the elements of this collection
-
sortAlpha
public Sequence<T> sortAlpha()
Description copied from interface:SequenceReturns an alphabetically sorted sequence. Elements are considered using their (internal) string representations and sorted.
-
sortedBy
public Sequence<T> sortedBy(ExpressionEvaluator evaluator) throws VilException
Description copied from interface:SequenceSorts the elements in this sequence according to the given expression in ascending order.- Specified by:
sortedByin interfaceCollection<T>- Specified by:
sortedByin interfaceSequence<T>- Parameters:
evaluator- the evaluator- Returns:
- the selected elements
- Throws:
VilException- in case that selection fails
-
revert
public Sequence<T> revert()
Description copied from interface:SequenceReverts this sequence.
-
indexOf
public int indexOf(T element)
Description copied from interface:SequenceReturns the index ofelementin this sequence.
-
add
public T add(T element)
Description copied from interface:SequenceAdds an element to the end of this sequence.
-
remove
public boolean remove(T element)
Description copied from interface:SequenceRemoves the first occurrence of the given element from this sequence.
-
mapSequence
public Map<T,T> mapSequence(Sequence<T> other)
Description copied from interface:SequenceMaps 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.- Specified by:
mapSequencein interfaceSequence<T>- Parameters:
other- the second sequence to map against- Returns:
- the mapping (key is taken from this sequence, value from
other)
-
mapAny
public Map<T,T> mapAny(Sequence<T> other)
Description copied from interface:SequenceMaps 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.
-
union
public Sequence<T> union(Sequence<T> seq)
Description copied from interface:SequenceAppend the elements inseq.
-
append
public Sequence<T> append(T object)
Description copied from interface:SequenceReturns the combined sequence ofseqandobjectappended.
-
prepend
public Sequence<T> prepend(T object)
Description copied from interface:SequenceReturns the combined sequence ofobjectprepended before this sequence.
-
insertAt
public Sequence<T> insertAt(int index, T object)
Description copied from interface:SequenceReturns the sequence havingobjectinserted at positionindex.
-
subSequence
public Sequence<T> subSequence(int lower, int upper)
Description copied from interface:SequenceReturns the sub-sequence of this sequence.- Specified by:
subSequencein interfaceSequence<T>- Parameters:
lower- the lower index where the sub-sequence shall startupper- the end index where the sub-sequence shall end- Returns:
- the sub-sequence
-
allowSequenceAdjustment
public boolean allowSequenceAdjustment()
Description copied from interface:CollectionReturns whether aIStringValueProvidermay reorder the sequence of this collection for (test) output.- Specified by:
allowSequenceAdjustmentin interfaceCollection<T>- Overrides:
allowSequenceAdjustmentin classAbstractListWrapper<T>- Returns:
trueif a value provider may reorder the sequence,falseelse
-
hasDuplicates
public boolean hasDuplicates()
Description copied from interface:SequenceReturns whether at least one of the elements in operand has a duplicate.- Specified by:
hasDuplicatesin interfaceSequence<T>- Returns:
truefor duplicates,falseelse
-
overlaps
public boolean overlaps(Sequence<T> other)
Description copied from interface:SequenceReturns the sequence in that this sequence andotherhave in common.
-
isSubsequenceOf
public boolean isSubsequenceOf(Sequence<T> other)
Description copied from interface:SequenceReturns whether operand is a subsequence (considering the sequence and including equality) ofother.- Specified by:
isSubsequenceOfin interfaceSequence<T>- Parameters:
other- the other sequence- Returns:
truefor subsequence,falseelse
-
joinfields
public java.lang.String joinfields(java.lang.String separator, java.lang.String begin, java.lang.String end)Description copied from interface:SequenceReturns a concatenation of the string representation of elements, withbeginas lead in,sepas separator between the elements andendas lead out. (QVT)- Specified by:
joinfieldsin interfaceSequence<T>- Parameters:
separator- the separatorbegin- the lead inend- the lead out- Returns:
- the concatenated result
-
removeAll
public void removeAll(T element)
Description copied from interface:SequenceRemoves all elements equal toelement. (QVT)
-
removeAt
public T removeAt(int index)
Description copied from interface:SequenceRemoves the element atindex. (QVT)
-
removeFirst
public T removeFirst()
Description copied from interface:SequenceRemoves the first element. (QVT)- Specified by:
removeFirstin interfaceSequence<T>- Returns:
- the removed element, undefined if there is no first element
-
removeLast
public T removeLast()
Description copied from interface:SequenceRemoves the last element. (QVT)- Specified by:
removeLastin interfaceSequence<T>- Returns:
- the removed element, undefined if there is no last element
-
cloneCollection
public Sequence<T> cloneCollection()
Description copied from interface:CollectionClones this collection. (QVT)- Specified by:
cloneCollectionin interfaceCollection<T>- Specified by:
cloneCollectionin interfaceSequence<T>- Returns:
- a clone of this collection
-
-