Class UnmodifiableSequence<T>
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.vilTypes.UnmodifiableSequence<T>
-
- Type Parameters:
T- the element type
- All Implemented Interfaces:
java.lang.Iterable<T>,Collection<T>,IStringValueProvider,IVilGenericType,IVilType,Sequence<T>
public class UnmodifiableSequence<T> extends java.lang.Object implements Sequence<T>
Implements an unmodifiable wrapper for sequences. This is just a runtime type.- Author:
- Holger Eichelberger
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.ssehub.easy.instantiation.core.model.vilTypes.IStringValueProvider
IStringValueProvider.StringComparator
-
-
Constructor Summary
Constructors Constructor Description UnmodifiableSequence(Sequence<T> sequence)Creates a new unmodifiable sequence.
-
Method Summary
All 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.Tany(ExpressionEvaluator evaluator)Returns any element complying with theevaluator.Sequence<T>append(Collection<T> set)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.java.lang.Objectavg()Returns the average of all elements.voidclear()Clears this 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.intcount(T element)Returns the number of elements in this collection which are equal toelement.booleanequals(java.lang.Object object)booleanexcludes(T element)Returns whether this collection does not contain a certain element.booleanexcludesAll(Collection<?> elements)Returns whether this collection contains no elements fromelements.Sequence<T>excluding(Collection<T> sequence)Exclude the elements insequence.java.lang.Booleanexists(ExpressionEvaluator evaluator)Returns whether there exists on element in the collection for which theevaluatorreturnstrue.Tfirst()Returns the first element.Sequence<?>flatten()Flattens this collection if needed, i.e., flatten sub-collections.java.lang.BooleanforAll(ExpressionEvaluator evaluator)Returns whether all elements in the collection for which theevaluatorreturnstrue.Tget(int index)Returns a specific element from the collection.intgetGenericParameterCount()Returns the number of generic parameters ofT.TypeDescriptor<?>getGenericParameterType(int index)Returns the type of the specified generic parameter ofT.java.lang.StringgetStringValue(IStringValueProvider.StringComparator comparator)Returns the string value of this object.TypeDescriptor<?>getType()Returns the actual type including generics.booleanhasDuplicates()Returns whether at least one of the elements in operand has a duplicate.inthashCode()booleanincludes(T element)Returns whether this collection contains a certain element.booleanincludesAll(Collection<?> elements)Returns whether this collection contains all elements inelements.intindexOf(T element)Returns the index ofelementin this sequence.Sequence<T>insertAt(int index, T object)Returns the sequence havingobjectinserted at positionindex.booleanisAcyclic(ExpressionEvaluator evaluator)Returns whether the transitive closure over elements provided by this collection andevaluatordoes not contain a cycle.booleanisEmpty()Returns whether the collection is empty.booleanisEquals(Collection<?> elements)Returns whether this collection is equal toelements.booleanisNotEmpty()Returns whether the collection is not empty (inverse ofCollection.isEmpty().booleanisSubsequenceOf(Sequence<T> other)Returns whether operand is a subsequence (considering the sequence and including equality) ofother.java.lang.BooleanisUnique(ExpressionEvaluator evaluator)Returns whether the evaluator returns a different result for all elements in the collection.java.util.Iterator<T>iterator()Returns an iterator on the individual elements of this collection.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.Tmax()Returns the maximum of all elements.Tmin()Returns the minimum of all elements.Tone(ExpressionEvaluator evaluator)Returns the element complying with theevaluatorif there is exactly one.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.Tproduct()Returns the product of all elements.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).intsize()Returns the number of elements in the underlying collection.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.Tsum()Returns the sum of all elements.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.java.lang.StringtoString()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.
-
-
-
Method Detail
-
getGenericParameterCount
public int getGenericParameterCount()
Description copied from interface:CollectionReturns the number of generic parameters ofT.- Specified by:
getGenericParameterCountin interfaceCollection<T>- Returns:
- the number of generic parameter
-
getGenericParameterType
public TypeDescriptor<?> getGenericParameterType(int index)
Description copied from interface:CollectionReturns the type of the specified generic parameter ofT.- Specified by:
getGenericParameterTypein interfaceCollection<T>- Parameters:
index- the 0-based index of the generic parameter- Returns:
- the actual type of the generic parameter
-
size
public int size()
Description copied from interface:CollectionReturns the number of elements in the underlying collection.- Specified by:
sizein interfaceCollection<T>- Returns:
- the number of elements
-
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>- Returns:
trueif a value provider may reorder the sequence,falseelse
-
isEmpty
public boolean isEmpty()
Description copied from interface:CollectionReturns whether the collection is empty.- Specified by:
isEmptyin interfaceCollection<T>- Returns:
trueif it is empty,falseelse
-
isNotEmpty
public boolean isNotEmpty()
Description copied from interface:CollectionReturns whether the collection is not empty (inverse ofCollection.isEmpty().- Specified by:
isNotEmptyin interfaceCollection<T>- Returns:
falseif it is empty,trueelse
-
includes
public boolean includes(T element)
Description copied from interface:CollectionReturns whether this collection contains a certain element.- Specified by:
includesin interfaceCollection<T>- Parameters:
element- the element to look for- Returns:
trueif this collection containselement,falseelse
-
excludes
public boolean excludes(T element)
Description copied from interface:CollectionReturns whether this collection does not contain a certain element.- Specified by:
excludesin interfaceCollection<T>- Parameters:
element- the element to look for- Returns:
trueif this collection does not containelement,trueelse
-
count
public int count(T element)
Description copied from interface:CollectionReturns the number of elements in this collection which are equal toelement.- Specified by:
countin interfaceCollection<T>- Parameters:
element- the element to look for- Returns:
- the number of equal elements in this collection
-
iterator
public java.util.Iterator<T> iterator()
Description copied from interface:CollectionReturns an iterator on the individual elements of this collection.- Specified by:
iteratorin interfaceCollection<T>- Specified by:
iteratorin interfacejava.lang.Iterable<T>- Returns:
- the iterator
-
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
-
getStringValue
public java.lang.String getStringValue(IStringValueProvider.StringComparator comparator)
Description copied from interface:IStringValueProviderReturns the string value of this object.- Specified by:
getStringValuein interfaceIStringValueProvider- Parameters:
comparator- if the sequence of elements, e.g., in case of collections, shall be ordered according to the comparator, null if the original sequence shall be returned- Returns:
- the string value
-
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()
-
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> set)
Description copied from interface:SequenceAppend the elements inset.
-
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.
-
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
-
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
-
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
-
indexOf
public int indexOf(T element)
Description copied from interface:SequenceReturns the index ofelementin 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.
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toMappedList
public java.util.List<T> toMappedList()
Description copied from interface:SequenceConverts back to a list for utilizing this with external classes.- Specified by:
toMappedListin interfaceSequence<T>- Returns:
- the internal map
-
revert
public Sequence<T> revert()
Description copied from interface:SequenceReverts this sequence.
-
getType
public TypeDescriptor<?> getType()
Description copied from interface:IVilGenericTypeReturns the actual type including generics. "Overrides"PseudoAny.getType(Object).- Specified by:
getTypein interfaceIVilGenericType- Returns:
- the actual type
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
clear
public void clear()
Description copied from interface:CollectionClears this collection.- Specified by:
clearin interfaceCollection<T>
-
sum
public T sum()
Description copied from interface:CollectionReturns the sum of all elements.- Specified by:
sumin interfaceCollection<T>- Returns:
- the sum of all elements or null if the elements do not define addition
-
avg
public java.lang.Object avg()
Description copied from interface:CollectionReturns the average of all elements.- Specified by:
avgin interfaceCollection<T>- Returns:
- the average of all elements or null if the elements do not define addition or division
-
product
public T product()
Description copied from interface:CollectionReturns the product of all elements.- Specified by:
productin interfaceCollection<T>- Returns:
- the product of all elements or null if the elements do not define multiplication
-
min
public T min()
Description copied from interface:CollectionReturns the minimum of all elements.- Specified by:
minin interfaceCollection<T>- Returns:
- the minimum of all elements or null if the elements do not define the minimum operation
-
max
public T max()
Description copied from interface:CollectionReturns the maximum of all elements.- Specified by:
maxin interfaceCollection<T>- Returns:
- the maximum of all elements or null if the elements do not define the maximum operation
-
includesAll
public boolean includesAll(Collection<?> elements)
Description copied from interface:CollectionReturns whether this collection contains all elements inelements.- Specified by:
includesAllin interfaceCollection<T>- Parameters:
elements- the elements to look for- Returns:
trueif this collection contains allelements,falseelse
-
excludesAll
public boolean excludesAll(Collection<?> elements)
Description copied from interface:CollectionReturns whether this collection contains no elements fromelements.- Specified by:
excludesAllin interfaceCollection<T>- Parameters:
elements- the elements to look for- Returns:
trueif this collection contains none fromelements,falseelse
-
any
public T any(ExpressionEvaluator evaluator) throws VilException
Description copied from interface:CollectionReturns any element complying with theevaluator.- Specified by:
anyin interfaceCollection<T>- Parameters:
evaluator- the evaluator (results must evaluate to Boolean)- Returns:
- one element complying with
evaluator - Throws:
VilException- in case that application fails
-
one
public T one(ExpressionEvaluator evaluator) throws VilException
Description copied from interface:CollectionReturns the element complying with theevaluatorif there is exactly one.- Specified by:
onein interfaceCollection<T>- Parameters:
evaluator- the evaluator (results must evaluate to Boolean)- Returns:
- the element complying with
evaluator - Throws:
VilException- in case that evaluation fails
-
exists
public java.lang.Boolean exists(ExpressionEvaluator evaluator) throws VilException
Description copied from interface:CollectionReturns whether there exists on element in the collection for which theevaluatorreturnstrue.- Specified by:
existsin interfaceCollection<T>- Parameters:
evaluator- the evaluator- Returns:
truefor the exists one,falseelse- Throws:
VilException- in case that evaluation fails
-
forAll
public java.lang.Boolean forAll(ExpressionEvaluator evaluator) throws VilException
Description copied from interface:CollectionReturns whether all elements in the collection for which theevaluatorreturnstrue.- Specified by:
forAllin interfaceCollection<T>- Parameters:
evaluator- the evaluator- Returns:
truefor the exists one,falseelse- Throws:
VilException- in case that evaluation fails
-
isUnique
public java.lang.Boolean isUnique(ExpressionEvaluator evaluator) throws VilException
Description copied from interface:CollectionReturns whether the evaluator returns a different result for all elements in the collection.- Specified by:
isUniquein interfaceCollection<T>- Parameters:
evaluator- the evaluator- Returns:
trueif all results are different,falseelse- Throws:
VilException- in case that evaluation fails
-
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
-
union
public Sequence<T> union(Sequence<T> seq)
Description copied from interface:SequenceAppend the elements inseq.
-
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
-
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
-
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
-
isAcyclic
public boolean isAcyclic(ExpressionEvaluator evaluator) throws VilException
Description copied from interface:CollectionReturns whether the transitive closure over elements provided by this collection andevaluatordoes not contain a cycle.- Specified by:
isAcyclicin interfaceCollection<T>- Parameters:
evaluator- the evaluator providing the links/collections to follow- Returns:
truefor cycle,falseelse- Throws:
VilException- in case that evaluation fails
-
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
-
-