Interface Collection<T>
-
- Type Parameters:
T- the element type
- All Superinterfaces:
IStringValueProvider,java.lang.Iterable<T>,IVilGenericType,IVilType
- All Known Implementing Classes:
AbstractArrayWrapper,AbstractCollectionWrapper,AbstractListWrapper,ArraySequence,ArraySet,FixedListSequence,FixedListSet,ListSequence,ListSet,OtherProjects,SetSet,UnmodifiableSequence,UnmodifiableSet
public interface Collection<T> extends java.lang.Iterable<T>, IVilGenericType, IStringValueProvider
Defines the basic VIL collection type to be used with maps and joins. 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.- Author:
- Holger Eichelberger
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.ssehub.easy.instantiation.core.model.vilTypes.IStringValueProvider
IStringValueProvider.StringComparator
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanallowSequenceAdjustment()Returns whether aIStringValueProvidermay reorder the sequence of this collection for (test) output.Tany(ExpressionEvaluator evaluator)Returns any element complying with theevaluator.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.java.lang.Objectavg()Returns the average of all elements.voidclear()Clears this collection.Collection<T>cloneCollection()Clones this collection.Collection<?>closure(ExpressionEvaluator evaluator)Calculates a transitive closure over elements provided by this collection andevaluator.Collection<?>collect(ExpressionEvaluator evaluator)Collects the application ofevaluatorto each individual element and flattens nested structures.Collection<?>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.booleanexcludes(T element)Returns whether this collection does not contain a certain element.booleanexcludesAll(Collection<?> elements)Returns whether this collection contains no elements fromelements.java.lang.Booleanexists(ExpressionEvaluator evaluator)Returns whether there exists on element in the collection for which theevaluatorreturnstrue.Collection<?>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.intgetGenericParameterCount()Returns the number of generic parameters ofT.TypeDescriptor<?>getGenericParameterType(int index)Returns the type of the specified generic parameter ofT.booleanincludes(T element)Returns whether this collection contains a certain element.booleanincludesAll(Collection<?> elements)Returns whether this collection contains all elements inelements.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 ofisEmpty().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.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.Tproduct()Returns the product of all elements.Collection<T>reject(ExpressionEvaluator evaluator)Rejects elements in this collection according to the given expression.Collection<T>select(ExpressionEvaluator evaluator)Selects elements in this collection according to the given expression.Collection<T>selectByKind(TypeDescriptor<?> type)Does type selection of elements (including subtypes).Collection<T>selectByType(TypeDescriptor<?> type)Does type selection of elements (only the same type).intsize()Returns the number of elements in the underlying collection.Collection<T>sortedBy(ExpressionEvaluator evaluator)Sorts the elements in this collection according to the given expression in ascending order.Tsum()Returns the sum of all elements.Collection<T>typeReject(TypeDescriptor<?> type)Does type selection of elements not having the same type (including subtypes).-
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
-
getGenericParameterCount
int getGenericParameterCount()
Returns the number of generic parameters ofT.- Returns:
- the number of generic parameter
-
getGenericParameterType
TypeDescriptor<?> getGenericParameterType(int index)
Returns the type of the specified generic parameter ofT.- Parameters:
index- the 0-based index of the generic parameter- Returns:
- the actual type of the generic parameter
-
size
int size()
Returns the number of elements in the underlying collection.- Returns:
- the number of elements
-
allowSequenceAdjustment
boolean allowSequenceAdjustment()
Returns whether aIStringValueProvidermay reorder the sequence of this collection for (test) output.- Returns:
trueif a value provider may reorder the sequence,falseelse
-
isEmpty
boolean isEmpty()
Returns whether the collection is empty.- Returns:
trueif it is empty,falseelse
-
isNotEmpty
boolean isNotEmpty()
Returns whether the collection is not empty (inverse ofisEmpty().- Returns:
falseif it is empty,trueelse
-
includes
boolean includes(T element)
Returns whether this collection contains a certain element.- Parameters:
element- the element to look for- Returns:
trueif this collection containselement,falseelse
-
excludes
boolean excludes(T element)
Returns whether this collection does not contain a certain element.- Parameters:
element- the element to look for- Returns:
trueif this collection does not containelement,trueelse
-
count
int count(T element)
Returns the number of elements in this collection which are equal toelement.- Parameters:
element- the element to look for- Returns:
- the number of equal elements in this collection
-
iterator
java.util.Iterator<T> iterator()
Returns an iterator on the individual elements of this collection.- Specified by:
iteratorin interfacejava.lang.Iterable<T>- Returns:
- the iterator
-
isEquals
boolean isEquals(Collection<?> elements)
Returns 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.- Parameters:
elements- the collection to be tested- Returns:
trueif both collections are considered to be equal,falseelse
-
clear
void clear()
Clears this collection.
-
select
Collection<T> select(ExpressionEvaluator evaluator) throws VilException
Selects elements in this collection according to the given expression.- Parameters:
evaluator- the evaluator (results must evaluate to Boolean)- Returns:
- the selected elements
- Throws:
VilException- in case that evaluation fails
-
reject
Collection<T> reject(ExpressionEvaluator evaluator) throws VilException
Rejects elements in this collection according to the given expression.- Parameters:
evaluator- the evaluator (results must evaluate to Boolean)- Returns:
- the rejected elements
- Throws:
VilException- in case that evaluation fails
-
closure
Collection<?> closure(ExpressionEvaluator evaluator) throws VilException
Calculates a transitive closure over elements provided by this collection andevaluator.- Parameters:
evaluator- the evaluator providing the links/collections to follow- Returns:
- the closure
- Throws:
VilException- in case that evaluation fails
-
isAcyclic
boolean isAcyclic(ExpressionEvaluator evaluator) throws VilException
Returns whether the transitive closure over elements provided by this collection andevaluatordoes not contain a cycle.- Parameters:
evaluator- the evaluator providing the links/collections to follow- Returns:
truefor cycle,falseelse- Throws:
VilException- in case that evaluation fails
-
collect
Collection<?> collect(ExpressionEvaluator evaluator) throws VilException
Collects the application ofevaluatorto each individual element and flattens nested structures.- Parameters:
evaluator- the evaluator (results must evaluate to Boolean)- Returns:
- the application results
- Throws:
VilException- in case that evaluation fails
-
collectNested
Collection<?> collectNested(ExpressionEvaluator evaluator) throws VilException
Collects the application ofevaluatorto each individual element and keeps nested structures.- Parameters:
evaluator- the evaluator (results must evaluate to Boolean)- Returns:
- the application results
- Throws:
VilException- in case that evaluation fails
-
any
T any(ExpressionEvaluator evaluator) throws VilException
Returns any element complying with theevaluator.- Parameters:
evaluator- the evaluator (results must evaluate to Boolean)- Returns:
- one element complying with
evaluator - Throws:
VilException- in case that application fails
-
one
T one(ExpressionEvaluator evaluator) throws VilException
Returns the element complying with theevaluatorif there is exactly one.- Parameters:
evaluator- the evaluator (results must evaluate to Boolean)- Returns:
- the element complying with
evaluator - Throws:
VilException- in case that evaluation fails
-
exists
java.lang.Boolean exists(ExpressionEvaluator evaluator) throws VilException
Returns whether there exists on element in the collection for which theevaluatorreturnstrue.- Parameters:
evaluator- the evaluator- Returns:
truefor the exists one,falseelse- Throws:
VilException- in case that evaluation fails
-
forAll
java.lang.Boolean forAll(ExpressionEvaluator evaluator) throws VilException
Returns whether all elements in the collection for which theevaluatorreturnstrue.- Parameters:
evaluator- the evaluator- Returns:
truefor the exists one,falseelse- Throws:
VilException- in case that evaluation fails
-
isUnique
java.lang.Boolean isUnique(ExpressionEvaluator evaluator) throws VilException
Returns whether the evaluator returns a different result for all elements in the collection.- Parameters:
evaluator- the evaluator- Returns:
trueif all results are different,falseelse- Throws:
VilException- in case that evaluation fails
-
selectByType
Collection<T> selectByType(TypeDescriptor<?> type)
Does type selection of elements (only the same type).- Parameters:
type- the target type- Returns:
- the selected elements (the type will be adjusted to the actual
type for
type)
-
selectByKind
Collection<T> selectByKind(TypeDescriptor<?> type)
Does type selection of elements (including subtypes).- Parameters:
type- the target type- Returns:
- the selected elements (the type will be adjusted to the actual
type for
type)
-
typeReject
Collection<T> typeReject(TypeDescriptor<?> type)
Does type selection of elements not having the same type (including subtypes).- Parameters:
type- the target type- Returns:
- the selected elements (the type will be adjusted to the actual
type for
type)
-
sum
T sum()
Returns the sum of all elements.- Returns:
- the sum of all elements or null if the elements do not define addition
-
avg
java.lang.Object avg()
Returns the average of all elements.- Returns:
- the average of all elements or null if the elements do not define addition or division
-
product
T product()
Returns the product of all elements.- Returns:
- the product of all elements or null if the elements do not define multiplication
-
min
T min()
Returns the minimum of all elements.- Returns:
- the minimum of all elements or null if the elements do not define the minimum operation
-
max
T max()
Returns the maximum of all elements.- Returns:
- the maximum of all elements or null if the elements do not define the maximum operation
-
includesAll
boolean includesAll(Collection<?> elements)
Returns whether this collection contains all elements inelements.- Parameters:
elements- the elements to look for- Returns:
trueif this collection contains allelements,falseelse
-
excludesAll
boolean excludesAll(Collection<?> elements)
Returns whether this collection contains no elements fromelements.- Parameters:
elements- the elements to look for- Returns:
trueif this collection contains none fromelements,falseelse
-
asSequence
Sequence<T> asSequence()
Turns this collection into a sequence.- Returns:
- the set containing the elements of this collection
-
asSet
Set<T> asSet()
Turns this collection into a set.- Returns:
- the set containing the elements of this collection (excluding duplicates)
-
flatten
Collection<?> flatten() throws VilException
Flattens this collection if needed, i.e., flatten sub-collections.- Returns:
- the flattened collection
- Throws:
VilException- in case of type incompatibilities
-
sortedBy
Collection<T> sortedBy(ExpressionEvaluator evaluator) throws VilException
Sorts the elements in this collection according to the given expression in ascending order.- Parameters:
evaluator- the evaluator- Returns:
- the selected elements
- Throws:
VilException- in case that selection fails
-
apply
java.lang.Object apply(ExpressionEvaluator evaluator) throws VilException
Processes elements in this set by applying to given expression.- 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
-
cloneCollection
Collection<T> cloneCollection()
Clones this collection. (QVT)- Returns:
- a clone of this collection
-
-