Package org.eclipse.m2m.atl.emftvm.util
Class LazyCollection<E>
java.lang.Object
org.eclipse.m2m.atl.emftvm.util.LazyCollection<E>
- Type Parameters:
E- the collection element type
- All Implemented Interfaces:
Iterable<E>,Collection<E>
- Direct Known Subclasses:
LazyBag,LazyList,LazyOrderedSet,LazySet
Immutable
Collection that supports lazy evaluation.
Based on the OCL 2.2 specification (formal/2010-02-01).-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassIteratorthat appends an object to the underlying collection.classLazyCollection.ReadOnlyIteratorthat caches values of the underlying collection.classLazyCollection.ReadOnlyIteratorthat removes duplicate values from the underlying collection.static classLazyCollection.ReadOnlyIteratorthat collects the results of evaluating a function on each of the elements from the underlying collection.classLazyCollection.ReadOnlyIteratorthat excludes a given object.classLazyCollection.ReadOnlyIteratorthat filters elements from the underlying collection by evaluating a condition function on them.static classRecursively flattens any nestedIterables by iterating over their elements as well.static classRecursively flattens any nestedIterables by iterating over their elements as well.static classLazyCollection.ReadOnlyIteratorforIntegerranges.classLazyCollection.ReadOnlyIteratorthat returns only elements contained in both underlying collections.classConverts anIteratorto aListIterator.static classLazyCollection.ReadOnlyIteratorforLongranges.static classstatic classclassLazyCollection<E>.FilterIteratorthat rejects elements from the underlying collection by evaluation a condition function on them.classLazyCollection.ReadOnlyIteratorthat returns the values of the underlying collection in reverse order.classLazyCollection.ReadOnlyIteratorthat returns the values of the underlying collection in reverse order.classLazyCollection<E>.FilterIteratorthat selects elements from the underlying collection by evaluation a condition function on them.classclassclassLazyCollection.ReadOnlyIteratorthat returns elements contained in this underlying collection, but not in the other underlying collection.classIteratorthat returns first the elements of the underlying collection, then the elements of the other collection.classIteratorthat returns first the elements of the underlying collection, then the elements of the other collection, with all duplicates removed.classAbstractLazyCollection.ReadOnlyIteratorthat wraps around the underlying collection.classAbstractLazyCollection.ReadOnlyListIteratorthat wraps around the underlying collection. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Collection<E> Element cache.The inner data source for this collection.Cached element occurrence map. -
Constructor Summary
ConstructorsConstructorDescriptionCreates an emptyLazyCollection.LazyCollection(Iterable<E> dataSource) Creates aLazyCollectionarounddataSource. -
Method Summary
Modifier and TypeMethodDescriptionbooleanUnsupported.booleanaddAll(Collection<? extends E> c) Unsupported.Returns any element in the source collection for whichbodyevaluates totrue.protected StringBufferappendElements(StringBuffer buf, ExecEnv env) Appends the elements of this collection tobuf.asBag()Returns the Bag containing all the elements from self, including duplicates.Returns an OrderedSet that contains all the elements from self, in undefined order, with duplicates removed.Returns a Sequence that contains all the elements from self, in undefined order.asSet()Returns the Set containing all the elements from self, with duplicated removed.abstract StringEvaluates the collection as an OCL String.voidclear()Unsupported.booleanbooleancontainsAll(Collection<?> c) booleancontainsAny(Collection<?> c) Checks if this collection contains any of the elements in the specified collection.intReturns the number of times thatobjectoccurs in the collection self.protected voidCreates the cache collections.booleanReturnstrueifobjectis not an element of self,falseotherwise.booleanexcludesAll(Collection<?> c2) Does self contain none of the elements ofc2?abstract LazyCollection<E> Returns the collection containing all elements of self apart from all occurrences ofobject.abstract LazyCollection<E> excludingAll(Collection<?> coll) Returns the collection containing all elements of self minuscoll.booleanChecks ifconditionholds for at least one element in the underlying collection.booleanChecks ifconditionholds for at least one element pair in the cartesian product of the underlying collection.booleanChecks ifconditionholds for all elements in the underlying collection.booleanChecks ifconditionholds for all element pairs in the cartesian product of the underlying collection.booleanReturnstrueifobjectis an element of self,falseotherwise.booleanincludesAll(Collection<?> c2) Does self contain all the elements ofc2?abstract LazyCollection<E> Returns the collection containing all elements of self plusobject.abstract LazyCollection<E> Returns the collection containing all elements of self plusobject.abstract LazyCollection<E> includingAll(Collection<? extends E> coll) Returns the collection containing all elements of self pluscoll.abstract LazyCollection<E> includingAll(Collection<? extends E> coll, int index) Returns the collection containing all elements of self pluscoll.abstract LazyCollection<E> includingRange(E first, E last) Returns the collection containing all elements of self plus the collection offirstrunning tolast.booleanisEmpty()booleanResults intrueifbodyevaluates to a different value for each element in the source collection; otherwise, result isfalse.<T> TBuilds an accumulated value by calling theupdaterfunction for each element in the underlying collection and the previous accumulated value.iterator()Returns a Map indexed by the return value(s)xof the body expression, containing the Set of elements for which the body expression returnsx.mappedBySingle(CodeBlock body) Returns a Map indexed by the return value(s)xof the body expression, containing a single element for which the body expression returnsx.max()The element with the maximum value of all elements in self.min()The element with the minimum value of all elements in self.booleannotEmpty()Is self not the empty collection?booleanResults intrueif there is exactly one element in the source collection for whichbodyistrue.The cartesian product operation ofselfandc2.booleanUnsupported.booleanremoveAll(Collection<?> c) Unsupported.booleanretainAll(Collection<?> c) Unsupported.intsize()abstract LazyCollection<E> Results in the Collection containing all elements of the source collection.sum()The addition of all elements in self.Object[]toArray()<T> T[]toArray(T[] a) toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Field Details
-
dataSource
The inner data source for this collection. Is set tonullwhen cache is complete. -
cache
Element cache. -
occurrences
Cached element occurrence map.
-
-
Constructor Details
-
LazyCollection
Creates aLazyCollectionarounddataSource.- Parameters:
dataSource- the underlying collection
-
LazyCollection
public LazyCollection()Creates an emptyLazyCollection.
-
-
Method Details
-
createCache
protected void createCache()Creates the cache collections. -
add
Unsupported.- Specified by:
addin interfaceCollection<E>- Parameters:
o- the element to add- Returns:
- nothing
- Throws:
UnsupportedOperationException
-
addAll
Unsupported.- Specified by:
addAllin interfaceCollection<E>- Parameters:
c- the collection to add- Returns:
- nothing
- Throws:
UnsupportedOperationException
-
clear
public void clear()Unsupported.- Specified by:
clearin interfaceCollection<E>- Throws:
UnsupportedOperationException
-
contains
- Specified by:
containsin interfaceCollection<E>
-
containsAll
- Specified by:
containsAllin interfaceCollection<E>
-
containsAny
Checks if this collection contains any of the elements in the specified collection.- Parameters:
c- collection to be checked for containment in this collection.- Returns:
trueif this collection contains any of the elements in the specified collection.
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<E>
-
iterator
-
remove
Unsupported.- Specified by:
removein interfaceCollection<E>- Parameters:
o- the element to remove- Returns:
- nothing
- Throws:
UnsupportedOperationException
-
removeAll
Unsupported.- Specified by:
removeAllin interfaceCollection<E>- Parameters:
c- the collection to remove- Returns:
- nothing
- Throws:
UnsupportedOperationException
-
retainAll
Unsupported.- Specified by:
retainAllin interfaceCollection<E>- Parameters:
c- the collection to retain- Returns:
- nothing
- Throws:
UnsupportedOperationException
-
size
public int size()- Specified by:
sizein interfaceCollection<E>
-
toArray
- Specified by:
toArrayin interfaceCollection<E>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArrayin interfaceCollection<E>
-
toString
-
asString
Evaluates the collection as an OCL String.- Parameters:
env- the execution environment- Returns:
- the String representation of this
LazyCollection.
-
appendElements
Appends the elements of this collection tobuf.- Parameters:
buf- theStringBufferto add the elements' string representation toenv- the execution environment- Returns:
- buf
-
includes
Returnstrueifobjectis an element of self,falseotherwise.- Parameters:
object- the object to check for- Returns:
trueifobjectis an element of self,falseotherwise.
-
excludes
Returnstrueifobjectis not an element of self,falseotherwise.- Parameters:
object- the object to check for- Returns:
trueifobjectis not an element of self,falseotherwise.
-
count
Returns the number of times thatobjectoccurs in the collection self.- Parameters:
object- the object to check for- Returns:
- The number of times that
objectoccurs in the collection self.
-
includesAll
Does self contain all the elements ofc2?- Parameters:
c2- the collection to check- Returns:
trueiff self contains all elements ofc2.
-
excludesAll
Does self contain none of the elements ofc2?- Parameters:
c2- the collection to check- Returns:
trueiff self contains no elements ofc2.
-
notEmpty
public boolean notEmpty()Is self not the empty collection?- Returns:
falseiff self contains no elements.
-
max
The element with the maximum value of all elements in self. Elements must be of a type supporting the max operation. The max operation - supported by the elements - must take one parameter of typeEand be both associative and commutative. Integer and Real fulfill this condition.- Returns:
- The element with the maximum value of all elements in self.
-
min
The element with the minimum value of all elements in self. Elements must be of a type supporting the min operation. The min operation - supported by the elements - must take one parameter of type T and be both associative and commutative. Integer and Real fulfill this condition.- Returns:
- The element with the minimum value of all elements in self.
-
sum
The addition of all elements in self. Elements must be of a type supporting the + operation. The + operation must take one parameter of typeEand be both associative: (a+b)+c = a+(b+c), and commutative: a+b = b+a. Integer and Real fulfill this condition.- Returns:
self->iterate( elem; acc : E = 0 | acc + elem )
-
product
The cartesian product operation ofselfandc2.Lazy operation.
- Type Parameters:
T- the element type- Parameters:
c2- the other factor in the cartesian product- Returns:
self->iterate (e1; acc: Set(Tuple(first: T, second: T2)) = Set{} |
c2->iterate (e2; acc2: Set(Tuple(first: T, second: T2)) = acc |
acc2->including (Tuple{first = e1, second = e2}) ) )
-
asBag
Returns the Bag containing all the elements from self, including duplicates.Lazy operation.
- Returns:
- The Bag containing all the elements from self, including duplicates.
-
asSequence
Returns a Sequence that contains all the elements from self, in undefined order.Lazy operation.
- Returns:
- A Sequence that contains all the elements from self, in undefined order.
-
asSet
Returns the Set containing all the elements from self, with duplicated removed.Lazy operation.
- Returns:
- The Set containing all the elements from self, with duplicated removed.
-
asOrderedSet
Returns an OrderedSet that contains all the elements from self, in undefined order, with duplicates removed.Lazy operation.
- Returns:
- An OrderedSet that contains all the elements from self, in undefined order, with duplicates removed.
-
including
Returns the collection containing all elements of self plusobject.Lazy operation.
- Parameters:
object- the object to include- Returns:
- The collection containing all elements of self plus
object.
-
including
Returns the collection containing all elements of self plusobject.Lazy operation.
- Parameters:
object- the object to includeindex- the index at which to insertcoll(starting at 1)- Returns:
- The collection containing all elements of self plus
object.
-
includingAll
Returns the collection containing all elements of self pluscoll.Lazy operation.
- Parameters:
coll- the collection to include- Returns:
- The collection containing all elements of self plus
coll.
-
includingAll
Returns the collection containing all elements of self pluscoll.Lazy operation.
- Parameters:
coll- the collection to includeindex- the index at which to insertcoll(starting at 1)- Returns:
- The collection containing all elements of self plus
coll.
-
excluding
Returns the collection containing all elements of self apart from all occurrences ofobject.Lazy operation.
- Parameters:
object- the object to exclude- Returns:
- The collection containing all elements of self apart from all occurrences of
object.
-
excludingAll
Returns the collection containing all elements of self minuscoll.Lazy operation.
- Parameters:
coll- the collection to exclude- Returns:
- The collection containing all elements of self minus
coll.
-
includingRange
Returns the collection containing all elements of self plus the collection offirstrunning tolast.Lazy operation.
- Parameters:
first- the first object of the range to includelast- the last object of the range to include- Returns:
- The collection containing all elements of self plus the collection of
firstrunning tolast
-
forAll
Checks ifconditionholds for all elements in the underlying collection.- Parameters:
condition- the condition function- Returns:
trueiffconditionholds for all elements in the underlying collection.
-
forAll2
Checks ifconditionholds for all element pairs in the cartesian product of the underlying collection.- Parameters:
condition- the condition function- Returns:
trueiffconditionholds for all element pairs in the cartesian product of the underlying collection.
-
exists
Checks ifconditionholds for at least one element in the underlying collection.- Parameters:
condition- the condition function- Returns:
trueiffconditionholds for at least one element in the underlying collection.
-
exists2
Checks ifconditionholds for at least one element pair in the cartesian product of the underlying collection.- Parameters:
condition- the condition function- Returns:
trueiffconditionholds for at least one element pair in the cartesian product of the underlying collection.
-
iterate
Builds an accumulated value by calling theupdaterfunction for each element in the underlying collection and the previous accumulated value.- Type Parameters:
T- the element type- Parameters:
initialValue- the initial accumulated valueupdater- the updater function- Returns:
- The accumulated value
-
isUnique
Results intrueifbodyevaluates to a different value for each element in the source collection; otherwise, result isfalse.- Parameters:
body- the code to execute on each element- Returns:
trueifbodyevaluates to a different value for each element in the source collection.
-
any
Returns any element in the source collection for whichbodyevaluates totrue. If there is more than one element for whichbodyistrue, one of them is returned. There must be at least one element fulfillingbody.- Parameters:
body- the function to evaluate on each element- Returns:
- any element in the source collection for which body evaluates to
true. - Throws:
NoSuchElementException- if there is no element in the source collection for whichbodyistrue.
-
one
Results intrueif there is exactly one element in the source collection for whichbodyistrue.- Parameters:
body- the function to evaluate on each element- Returns:
trueif there is exactly one element in the source collection for whichbodyistrue.
-
sortedBy
Results in the Collection containing all elements of the source collection. The element for which body has the lowest value comes first, and so on. The type of the body expression must have the<operation defined. The<operation must return a Boolean value and must be transitive (i.e., ifa < bandb < cthena < c).- Parameters:
body- the function to evaluate on each element- Returns:
- the sorted collection
-
mappedBy
Returns a Map indexed by the return value(s)xof the body expression, containing the Set of elements for which the body expression returnsx.- Parameters:
body- the function to evaluate on each element- Returns:
- the Map
-
mappedBySingle
Returns a Map indexed by the return value(s)xof the body expression, containing a single element for which the body expression returnsx.- Parameters:
body- the function to evaluate on each element- Returns:
- the Map
-