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>
ImmutableEList
that supports lazy evaluation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LazyList.AppendList<E>
static class
LazyList.CollectList<E>
LazyList
that implements thecollect(CodeBlock)
function.static class
LazyList.InsertAtList<E>
LazyList
that inserts an element it a given index in the underlying collection.static class
LazyList.IntegerRangeList
LazyList
that represents a range running from a first to lastInteger
.static class
LazyList.LongRangeList
LazyList
that represents a range running from a first to lastLong
.static class
LazyList.NonCachingList<E>
static class
LazyList.PrependList<E>
static class
LazyList.ReverseList<E>
LazyList
that reverses the order of the underlying list.static class
LazyList.SubList<E>
LazyList
that presents a sub-range of the underlying list.static class
LazyList.UnionList<E>
class
LazyList.UnionListIterator
ListIterator
that 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 void
add(int index, E element)
Unsupported.boolean
addAll(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.String
asString(ExecEnv env)
Evaluates the collection as an OCL String.E
at(int i)
Returns thei
-th element of this list.<T> LazyList<T>
collect(CodeBlock function)
Collects the return values offunction
for each of the elements of this collection.protected void
createCache()
Creates the cache collections.boolean
equals(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
.E
first()
Returns the first element in self.LazyList<?>
flatten()
If the element type is not a collection type this results in the same self.E
get(int index)
int
hashCode()
LazyList<E>
including(E object)
Returns the sequence containing all elements of self plusobject
added 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 offirst
running tolast
added as the last elements.int
indexOf(java.lang.Object o)
int
indexOf2(java.lang.Object obj)
Returns the index of objectobj
in the sequence.LazyList<E>
insertAt(int index, E object)
Returns the sequence consisting of self withobject
inserted at positionindex
.E
last()
Returns the last element in self.int
lastIndexOf(java.lang.Object o)
int
lastIndexOf2(java.lang.Object obj)
Returns the last index of objectobj
in the sequence.java.util.ListIterator<E>
listIterator()
java.util.ListIterator<E>
listIterator(int index)
E
move(int newPosition, int oldPosition)
Unsupported in this implementation.void
move(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 thecondition
evaluates totrue
.E
remove(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 thecondition
evaluates totrue
.E
set(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 ins
inserted 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:
createCache
in classLazyCollection<E>
-
add
public void add(int index, E element)
Unsupported.- Specified by:
add
in 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:
addAll
in 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:
indexOf
in interfacejava.util.List<E>
-
lastIndexOf
public int lastIndexOf(java.lang.Object o)
- Specified by:
lastIndexOf
in interfacejava.util.List<E>
-
listIterator
public java.util.ListIterator<E> listIterator()
- Specified by:
listIterator
in interfacejava.util.List<E>
-
listIterator
public java.util.ListIterator<E> listIterator(int index)
- Specified by:
listIterator
in interfacejava.util.List<E>
-
remove
public E remove(int index)
Unsupported.- Specified by:
remove
in 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:
set
in 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:
subList
in interfacejava.util.List<E>
-
move
public void move(int newPosition, E object)
Unsupported in this implementation.- Specified by:
move
in 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:
move
in 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:
asString
in 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.IndexOutOfBoundsException
Returns the index of objectobj
in 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
obj
in the sequence. - Throws:
java.lang.IndexOutOfBoundsException
- ifobj
is not contained in this list.
-
lastIndexOf2
public int lastIndexOf2(java.lang.Object obj) throws java.lang.IndexOutOfBoundsException
Returns the last index of objectobj
in 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
obj
in the sequence. - Throws:
java.lang.IndexOutOfBoundsException
- ifobj
is 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 ins
inserted 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
s
inserted 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 withobject
inserted 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
object
inserted 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 plusobject
added as the last element.Lazy operation.
- Specified by:
including
in classLazyCollection<E>
- Parameters:
object
- the object to include- Returns:
- The sequence containing all elements of self plus
object
added 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:
including
in 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:
includingAll
in 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:
includingAll
in 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:
excluding
in 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:
excludingAll
in 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:
asSequence
in 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 offirst
running tolast
added as the last elements.Lazy operation.
- Specified by:
includingRange
in 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
first
running tolast
added as the last elements
-
select
public LazyList<E> select(CodeBlock condition)
Selects all elements from this collection for which thecondition
evaluates 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 thecondition
evaluates 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 offunction
for 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
function
return 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 < b
andb < c
thena < c
).- Specified by:
sortedBy
in classLazyCollection<E>
- Parameters:
body
- the function to evaluate on each element- Returns:
- the sorted collection
-
-