Class UnmodifiableSet<T>
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.vilTypes.UnmodifiableSet<T>
-
- Type Parameters:
T- the parameter type
- All Implemented Interfaces:
java.lang.Iterable<T>,Collection<T>,IStringValueProvider,IVilGenericType,IVilType,Set<T>
public class UnmodifiableSet<T> extends java.lang.Object implements Set<T>
Implements an unmodifiable set wrapper. 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 UnmodifiableSet(Set<T> set)Creates an unmodifiable set wrapper.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tadd(T element)Adds an element to this set.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.Set<T>cloneCollection()Clones this collection.Set<?>closure(ExpressionEvaluator evaluator)Calculates a transitive closure over elements provided by this collection andevaluator.Set<?>collect(ExpressionEvaluator evaluator)Collects the application ofevaluatorto each individual element and flattens nested structures.Set<?>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.Set<T>difference(Set<T> set)Calculates the difference between this and the given set.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.Set<T>excluding(Collection<T> set)Exclude the elements inset.java.lang.Booleanexists(ExpressionEvaluator evaluator)Returns whether there exists on element in the collection for which theevaluatorreturnstrue.Set<?>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.java.lang.StringgetStringValue(IStringValueProvider.StringComparator comparator)Returns the string value of this object.TypeDescriptor<?>getType()Returns the actual type including generics.inthashCode()booleanincludes(T element)Returns whether this collection contains a certain element.booleanincludesAll(Collection<?> elements)Returns whether this collection contains all elements inelements.Set<T>including(Collection<T> set)Include the elements inset.Set<T>intersection(Set<T> set)Returns the intersection of this set withset.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().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.TprojectSingle()In case that the sequence has exactly one element, this will be returned.Set<T>reject(ExpressionEvaluator evaluator)Rejects elements in this collection according to the given expression.booleanremove(T element)Removes the given element from this sequence.Set<T>select(ExpressionEvaluator evaluator)Selects elements in this collection according to the given expression.Set<T>selectByKind(TypeDescriptor<?> type)Does type selection of elements (including subtypes).Set<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.Set<T>symmetricDifference(Set<T> set)Calculates the symmetric difference between this and the given set.java.util.Set<T>toMappedSet()Converts back to a set for utilizing this with external classes.Sequence<T>toSequence()Turns this set into a sequence.java.lang.StringtoString()Set<T>typeReject(TypeDescriptor<?> type)Does type selection of elements not having the same type (including subtypes).Set<T>union(Set<T> set)Compute the union of this set andset(without duplicates).
-
-
-
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
-
selectByKind
public Set<T> selectByKind(TypeDescriptor<?> type)
Description copied from interface:CollectionDoes type selection of elements (including subtypes).- Specified by:
selectByKindin interfaceCollection<T>- Specified by:
selectByKindin interfaceSet<T>- Parameters:
type- the target type- Returns:
- the selected elements (the type will be adjusted to the actual
type for
type)
-
selectByType
public Set<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 interfaceSet<T>- Parameters:
type- the target type- Returns:
- the selected elements (the type will be adjusted to the actual
type for
type)
-
typeReject
public Set<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 interfaceSet<T>- Parameters:
type- the target type- Returns:
- the selected elements (the type will be adjusted to the actual
type for
type)
-
excluding
public Set<T> excluding(Collection<T> set)
Description copied from interface:SetExclude the elements inset.
-
including
public Set<T> including(Collection<T> set)
Description copied from interface:SetInclude the elements inset. Duplicates will not be included.
-
remove
public boolean remove(T element)
Description copied from interface:SetRemoves the given element from this sequence.
-
flatten
public Set<?> 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 interfaceSet<T>- Returns:
- the flattened collection
- Throws:
VilException- in case of type incompatibilities
-
select
public Set<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 interfaceSet<T>- Parameters:
evaluator- the evaluator (results must evaluate to Boolean)- Returns:
- the selected elements
- Throws:
VilException- in case that evaluation fails
-
reject
public Set<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 interfaceSet<T>- Parameters:
evaluator- the evaluator (results must evaluate to Boolean)- Returns:
- the rejected elements
- Throws:
VilException- in case that evaluation fails
-
collect
public Set<?> 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 interfaceSet<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
-
toSequence
public Sequence<T> toSequence()
Description copied from interface:SetTurns this set into a sequence.- Specified by:
toSequencein interfaceSet<T>- Returns:
- the set containing the elements of this set
-
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
-
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)
-
projectSingle
public T projectSingle()
Description copied from interface:SetIn case that the sequence has exactly one element, this will be returned.- Specified by:
projectSinglein interfaceSet<T>- Returns:
- the only element or null
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toMappedSet
public java.util.Set<T> toMappedSet()
Description copied from interface:SetConverts back to a set for utilizing this with external classes.- Specified by:
toMappedSetin interfaceSet<T>- Returns:
- the internal map
-
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
-
intersection
public Set<T> intersection(Set<T> set)
Returns the intersection of this set withset.- Specified by:
intersectionin interfaceSet<T>- Parameters:
set- the elements to be unified with this set- Returns:
- the union of this set and
set
-
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
-
sortedBy
public Collection<T> sortedBy(ExpressionEvaluator evaluator) throws VilException
Description copied from interface:CollectionSorts the elements in this collection 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
-
difference
public Set<T> difference(Set<T> set)
Description copied from interface:SetCalculates the difference between this and the given set.- Specified by:
differencein interfaceSet<T>- Parameters:
set- the set to calculate the difference for- Returns:
- the set difference
-
symmetricDifference
public Set<T> symmetricDifference(Set<T> set)
Description copied from interface:SetCalculates the symmetric difference between this and the given set.- Specified by:
symmetricDifferencein interfaceSet<T>- Parameters:
set- the set to calculate the difference for- Returns:
- the symmetric set difference
-
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 interfaceSet<T>- Parameters:
evaluator- the evaluator providing the links/collections to follow- Returns:
- the closure
- Throws:
VilException- in case that evaluation fails
-
collectNested
public Set<?> 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 interfaceSet<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
-
cloneCollection
public Set<T> cloneCollection()
Description copied from interface:CollectionClones this collection. (QVT)- Specified by:
cloneCollectionin interfaceCollection<T>- Specified by:
cloneCollectionin interfaceSet<T>- Returns:
- a clone of this collection
-
-