Package org.eclipse.m2m.atl.emftvm.util
Class LazyList<E>
- java.lang.Object
-
- org.eclipse.m2m.atl.emftvm.util.LazyCollection<E>
-
- org.eclipse.m2m.atl.emftvm.util.LazyList<E>
-
- Type Parameters:
E- the collection element type
- All Implemented Interfaces:
java.lang.Iterable<E>,java.util.Collection<E>,java.util.List<E>,org.eclipse.emf.common.util.EList<E>
- Direct Known Subclasses:
EnumConversionList,LazyList.CollectList,LazyList.IntegerRangeList,LazyList.LongRangeList,LazyList.NonCachingList,LazyListOnCollection,ModelImpl.InstanceOfList,OCLOperations.ResolveList
public class LazyList<E> extends LazyCollection<E> implements org.eclipse.emf.common.util.EList<E>
ImmutableEListthat supports lazy evaluation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLazyList.AppendList<E>static classLazyList.CollectList<E>LazyListthat implements thecollect(CodeBlock)function.static classLazyList.InsertAtList<E>LazyListthat inserts an element it a given index in the underlying collection.static classLazyList.IntegerRangeListLazyListthat represents a range running from a first to lastInteger.static classLazyList.LongRangeListLazyListthat represents a range running from a first to lastLong.static classLazyList.NonCachingList<E>static classLazyList.PrependList<E>static classLazyList.ReverseList<E>LazyListthat reverses the order of the underlying list.static classLazyList.SubList<E>LazyListthat presents a sub-range of the underlying list.static classLazyList.UnionList<E>classLazyList.UnionListIteratorListIteratorthat returns first the elements of the underlying collection, then the elements of the other collection.-
Nested classes/interfaces inherited from class org.eclipse.m2m.atl.emftvm.util.LazyCollection
LazyCollection.AppendIterator, LazyCollection.CachingIterator, LazyCollection.CachingSetIterator, LazyCollection.CollectIterator<T>, LazyCollection.ExcludingIterator, LazyCollection.FilterIterator, LazyCollection.FlattenIterator, LazyCollection.FlattenSetIterator, LazyCollection.IntegerRangeListIterator, LazyCollection.IntersectionIterator, LazyCollection.IteratorToListIterator, LazyCollection.LongRangeListIterator, LazyCollection.ReadOnlyIterator<E>, LazyCollection.ReadOnlyListIterator<E>, LazyCollection.RejectIterator, LazyCollection.ReverseIterator, LazyCollection.ReverseListIterator, LazyCollection.SelectIterator, LazyCollection.SubListIterator, LazyCollection.SubListListIterator, LazyCollection.SubtractionIterator, LazyCollection.UnionIterator, LazyCollection.UnionSetIterator, LazyCollection.WrappedIterator, LazyCollection.WrappedListIterator
-
-
Field Summary
-
Fields inherited from class org.eclipse.m2m.atl.emftvm.util.LazyCollection
cache, dataSource, occurrences
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, E element)Unsupported.booleanaddAll(int index, java.util.Collection<? extends E> c)Unsupported.LazyList<E>append(E object)Returns the sequence of elements, consisting of all elements of self, followed byobject.LazyList<E>asSequence()Returns the Sequence identical to the object itself.java.lang.StringasString(ExecEnv env)Evaluates the collection as an OCL String.Eat(int i)Returns thei-th element of this list.<T> LazyList<T>collect(CodeBlock function)Collects the return values offunctionfor each of the elements of this collection.protected voidcreateCache()Creates the cache collections.booleanequals(java.lang.Object o)LazyList<E>excluding(java.lang.Object object)Returns the sequence containing all elements of self apart from all occurrences ofobject.LazyList<E>excludingAll(java.util.Collection<?> coll)Returns the collection containing all elements of self minuscoll.Efirst()Returns the first element in self.LazyList<?>flatten()If the element type is not a collection type this results in the same self.Eget(int index)inthashCode()LazyList<E>including(E object)Returns the sequence containing all elements of self plusobjectadded as the last element.LazyList<E>including(E object, int index)Returns the collection containing all elements of self plusobject.LazyList<E>includingAll(java.util.Collection<? extends E> coll)Returns the collection containing all elements of self pluscoll.LazyList<E>includingAll(java.util.Collection<? extends E> coll, int index)Returns the collection containing all elements of self pluscoll.LazyList<E>includingRange(E first, E last)Returns the sequence containing all elements of self plus the sequence offirstrunning tolastadded as the last elements.intindexOf(java.lang.Object o)intindexOf2(java.lang.Object obj)Returns the index of objectobjin the sequence.LazyList<E>insertAt(int index, E object)Returns the sequence consisting of self withobjectinserted at positionindex.Elast()Returns the last element in self.intlastIndexOf(java.lang.Object o)intlastIndexOf2(java.lang.Object obj)Returns the last index of objectobjin the sequence.java.util.ListIterator<E>listIterator()java.util.ListIterator<E>listIterator(int index)Emove(int newPosition, int oldPosition)Unsupported in this implementation.voidmove(int newPosition, E object)Unsupported in this implementation.LazyList<E>prepend(E object)Returns the sequence consisting ofobject, followed by all elements in self.LazyList<E>reject(CodeBlock condition)Rejects all elements from this collection for which theconditionevaluates totrue.Eremove(int index)Unsupported.LazyList<E>reverse()Returns the sequence containing the same elements but with the opposite order.LazyList<E>select(CodeBlock condition)Selects all elements from this collection for which theconditionevaluates totrue.Eset(int index, E element)Unsupported.LazyList<E>sortedBy(CodeBlock body)Results in the Collection containing all elements of the source collection.LazyList<E>subList(int fromIndex, int toIndex)Lazy implementation ofList.subList(int, int).LazyList<E>subSequence(int lower, int upper)Returns the sub-list of this list starting at numberlower, up to and including element numberupper.LazyList<E>union(LazyList<? extends E> s)Returns the sequence consisting of all elements in self, followed by all elements ins.LazyList<E>union(LazyList<? extends E> s, int index)Returns the sequence consisting of all elements in self, with all elements insinserted atindex.-
Methods inherited from class org.eclipse.m2m.atl.emftvm.util.LazyCollection
add, addAll, any, appendElements, asBag, asOrderedSet, asSet, clear, contains, containsAll, containsAny, count, excludes, excludesAll, exists, exists2, forAll, forAll2, includes, includesAll, isEmpty, isUnique, iterate, iterator, mappedBy, mappedBySingle, max, min, notEmpty, one, product, remove, removeAll, retainAll, size, sum, toArray, toArray, toString
-
-
-
-
Method Detail
-
createCache
protected void createCache()
Creates the cache collections.- Overrides:
createCachein classLazyCollection<E>
-
add
public void add(int index, E element)Unsupported.- Specified by:
addin interfacejava.util.List<E>- Parameters:
index- the index at which to addelement- the element to add- Throws:
java.lang.UnsupportedOperationException
-
addAll
public boolean addAll(int index, java.util.Collection<? extends E> c)Unsupported.- Specified by:
addAllin interfacejava.util.List<E>- Parameters:
index- the index at which to addc- the collection to add- Returns:
- nothing
- Throws:
java.lang.UnsupportedOperationException
-
indexOf
public int indexOf(java.lang.Object o)
- Specified by:
indexOfin interfacejava.util.List<E>
-
lastIndexOf
public int lastIndexOf(java.lang.Object o)
- Specified by:
lastIndexOfin interfacejava.util.List<E>
-
listIterator
public java.util.ListIterator<E> listIterator()
- Specified by:
listIteratorin interfacejava.util.List<E>
-
listIterator
public java.util.ListIterator<E> listIterator(int index)
- Specified by:
listIteratorin interfacejava.util.List<E>
-
remove
public E remove(int index)
Unsupported.- Specified by:
removein interfacejava.util.List<E>- Parameters:
index- the index at which to remove- Returns:
- nothing
- Throws:
java.lang.UnsupportedOperationException
-
set
public E set(int index, E element)
Unsupported.- Specified by:
setin interfacejava.util.List<E>- Parameters:
index- the index at which to setelement- the element to set- Returns:
- nothing
- Throws:
java.lang.UnsupportedOperationException
-
subList
public LazyList<E> subList(int fromIndex, int toIndex)
Lazy implementation of
List.subList(int, int).- Specified by:
subListin interfacejava.util.List<E>
-
move
public void move(int newPosition, E object)Unsupported in this implementation.- Specified by:
movein interfaceorg.eclipse.emf.common.util.EList<E>- Throws:
java.lang.UnsupportedOperationException
-
move
public E move(int newPosition, int oldPosition)
Unsupported in this implementation.- Specified by:
movein interfaceorg.eclipse.emf.common.util.EList<E>- Throws:
java.lang.UnsupportedOperationException
-
equals
public boolean equals(java.lang.Object o)
-
hashCode
public int hashCode()
-
asString
public java.lang.String asString(ExecEnv env)
Evaluates the collection as an OCL String.- Specified by:
asStringin classLazyCollection<E>- Parameters:
env- the execution environment- Returns:
- the String representation of this
LazyCollection.
-
at
public E at(int i)
Returns thei-th element of this list. List index starts at 1.- Parameters:
i- the element index- Returns:
- The
i-th element of this list.
-
indexOf2
public int indexOf2(java.lang.Object obj) throws java.lang.IndexOutOfBoundsExceptionReturns the index of objectobjin the sequence. List index starts at 1.
pre :self->includes(obj)
post :self->at(i) = obj- Parameters:
obj- the object to look for- Returns:
- The index of object
objin the sequence. - Throws:
java.lang.IndexOutOfBoundsException- ifobjis not contained in this list.
-
lastIndexOf2
public int lastIndexOf2(java.lang.Object obj) throws java.lang.IndexOutOfBoundsExceptionReturns the last index of objectobjin the sequence. List index starts at 1.
pre :self->includes(obj)
post :self->at(i) = obj- Parameters:
obj- the object to look for- Returns:
- The last index of object
objin the sequence. - Throws:
java.lang.IndexOutOfBoundsException- ifobjis not contained in this list.
-
first
public E first()
Returns the first element in self.- Returns:
- The first element in self.
-
last
public E last()
Returns the last element in self.- Returns:
- The last element in self.
-
union
public LazyList<E> union(LazyList<? extends E> s)
Returns the sequence consisting of all elements in self, followed by all elements ins.Lazy operation.
- Parameters:
s- the list to union with this- Returns:
- The sequence consisting of all elements in self, followed by all elements in
s.
-
union
public LazyList<E> union(LazyList<? extends E> s, int index)
Returns the sequence consisting of all elements in self, with all elements insinserted atindex.Lazy operation.
- Parameters:
s- the list to union with thisindex- the insertion index (starting at 1)- Returns:
- The sequence consisting of all elements in self, with all elements in
sinserted atindex
-
flatten
public LazyList<?> flatten()
If the element type is not a collection type this results in the same self. If the element type is a collection type, the result is the sequence containing all the elements of all the elements of self. The order of the elements is partial.Lazy operation.
- Returns:
- if self.type.elementType.oclIsKindOf(CollectionType) then
self->iterate(c; acc : Sequence() = Sequence{} |
acc->union(c->asSequence() ) )
else
self
endif
-
append
public LazyList<E> append(E object)
Returns the sequence of elements, consisting of all elements of self, followed byobject.Lazy operation.
- Parameters:
object- the object to append- Returns:
- The sequence of elements, consisting of all elements of self, followed by
object.
-
prepend
public LazyList<E> prepend(E object)
Returns the sequence consisting ofobject, followed by all elements in self.Lazy operation.
- Parameters:
object- the object to prepend- Returns:
- The sequence consisting of
object, followed by all elements in self.
-
insertAt
public LazyList<E> insertAt(int index, E object)
Returns the sequence consisting of self withobjectinserted at positionindex. List index starts at 1.Lazy operation.
- Parameters:
index- the index at which to insertobject- the object to insert- Returns:
- The sequence consisting of self with
objectinserted at positionindex.
-
subSequence
public LazyList<E> subSequence(int lower, int upper)
Returns the sub-list of this list starting at numberlower, up to and including element numberupper. List index starts at 1.Lazy operation.
- Parameters:
lower- the sub-list lower bound, inclusiveupper- the sub-list upper bound, inclusive- Returns:
- the sub-list of this list.
-
including
public LazyList<E> including(E object)
Returns the sequence containing all elements of self plusobjectadded as the last element.Lazy operation.
- Specified by:
includingin classLazyCollection<E>- Parameters:
object- the object to include- Returns:
- The sequence containing all elements of self plus
objectadded as the last element.
-
including
public LazyList<E> including(E object, int index)
Returns the collection containing all elements of self plusobject.Lazy operation.
- Specified by:
includingin classLazyCollection<E>- 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
public LazyList<E> includingAll(java.util.Collection<? extends E> coll)
Returns the collection containing all elements of self pluscoll.Lazy operation.
- Specified by:
includingAllin classLazyCollection<E>- Parameters:
coll- the collection to include- Returns:
- The collection containing all elements of self plus
coll.
-
includingAll
public LazyList<E> includingAll(java.util.Collection<? extends E> coll, int index)
Returns the collection containing all elements of self pluscoll.Lazy operation.
- Specified by:
includingAllin classLazyCollection<E>- 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
public LazyList<E> excluding(java.lang.Object object)
Returns the sequence containing all elements of self apart from all occurrences ofobject.Lazy operation.
- Specified by:
excludingin classLazyCollection<E>- Parameters:
object- the object to exclude- Returns:
- The sequence containing all elements of self apart from all occurrences of
object.
-
excludingAll
public LazyList<E> excludingAll(java.util.Collection<?> coll)
Returns the collection containing all elements of self minuscoll.Lazy operation.
- Specified by:
excludingAllin classLazyCollection<E>- Parameters:
coll- the collection to exclude- Returns:
- The collection containing all elements of self minus
coll.
-
reverse
public LazyList<E> reverse()
Returns the sequence containing the same elements but with the opposite order.Lazy operation.
- Returns:
- The sequence containing the same elements but with the opposite order.
-
asSequence
public LazyList<E> asSequence()
Returns the Sequence identical to the object itself. This operation exists for convenience reasons.Lazy operation.
- Overrides:
asSequencein classLazyCollection<E>- Returns:
- The Sequence identical to the object itself. This operation exists for convenience reasons.
-
includingRange
public LazyList<E> includingRange(E first, E last)
Returns the sequence containing all elements of self plus the sequence offirstrunning tolastadded as the last elements.Lazy operation.
- Specified by:
includingRangein classLazyCollection<E>- Parameters:
first- the first object of the range to includelast- the last object of the range to include- Returns:
- The sequence containing all elements of self plus the sequence of
firstrunning tolastadded as the last elements
-
select
public LazyList<E> select(CodeBlock condition)
Selects all elements from this collection for which theconditionevaluates totrue.- Parameters:
condition- the condition function- Returns:
- a new lazy list with only the selected elements.
-
reject
public LazyList<E> reject(CodeBlock condition)
Rejects all elements from this collection for which theconditionevaluates totrue.- Parameters:
condition- the condition function- Returns:
- a new lazy list without the rejected elements.
-
collect
public <T> LazyList<T> collect(CodeBlock function)
Collects the return values offunctionfor each of the elements of this collection.- Type Parameters:
T- the element type- Parameters:
function- the return value function- Returns:
- a new lazy list with the
functionreturn values.
-
sortedBy
public LazyList<E> sortedBy(CodeBlock body)
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).- Specified by:
sortedByin classLazyCollection<E>- Parameters:
body- the function to evaluate on each element- Returns:
- the sorted collection
-
-