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:
  `Iterable<E>`, `Collection<E>`, `List<E>`, `SequencedCollection<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>
Immutable `EList` that supports lazy evaluation.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static class`
`LazyList.AppendList<E>`
`LazyList` that appends an element to the underlying `LazyList`.
`static class`
`LazyList.CollectList<E>`
`LazyList` that implements the `collect(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 last `Integer`.
`static class`
`LazyList.LongRangeList`
`LazyList` that represents a range running from a first to last `Long`.
`static class`
`LazyList.NonCachingList<E>`
Abstract `LazyList` that disables caching of the underlying `LazyList`.
`static class`
`LazyList.PrependList<E>`
`LazyList` that prepends an element to the underlying `LazyList`.
`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>`
`LazyList` that represents a union of the underlying `LazyList` and the added `LazyList`.
`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`

## Constructor Summary

Constructors
Constructor
Description
`LazyList()`
Creates an empty `LazyList`.
`LazyList(Iterable<E> dataSource)`
Creates a `LazyList` around `dataSource`.

## Method Summary

Modifier and Type
Method
Description
`void`
`add(int index, E element)`
Unsupported.
`boolean`
`addAll(int index, Collection<? extends E> c)`
Unsupported.
`LazyList<E>`
`append(E object)`
Returns the sequence of elements, consisting of all elements of self, followed by `object`.
`LazyList<E>`
`asSequence()`
Returns the Sequence identical to the object itself.
`String`
`asString(ExecEnv env)`
Evaluates the collection as an OCL String.
`E`
`at(int i)`
Returns the `i`-th element of this list.
`<T> LazyList<T>`
`collect(CodeBlock function)`
Collects the return values of `function` for each of the elements of this collection.
`protected void`
`createCache()`
Creates the cache collections.
`boolean`
`equals(Object o)`
`LazyList<E>`
`excluding(Object object)`
Returns the sequence containing all elements of self apart from all occurrences of `object`.
`LazyList<E>`
`excludingAll(Collection<?> coll)`
Returns the collection containing all elements of self minus `coll`.
`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 plus `object` added as the last element.
`LazyList<E>`
`including(E object, int index)`
Returns the collection containing all elements of self plus `object`.
`LazyList<E>`
`includingAll(Collection<? extends E> coll)`
Returns the collection containing all elements of self plus `coll`.
`LazyList<E>`
`includingAll(Collection<? extends E> coll, int index)`
Returns the collection containing all elements of self plus `coll`.
`LazyList<E>`
`includingRange(E first, E last)`
Returns the sequence containing all elements of self plus the sequence of `first` running to `last` added as the last elements.
`int`
`indexOf(Object o)`
`int`
`indexOf2(Object obj)`
Returns the index of object `obj` in the sequence.
`LazyList<E>`
`insertAt(int index, E object)`
Returns the sequence consisting of self with `object` inserted at position `index`.
`E`
`last()`
Returns the last element in self.
`int`
`lastIndexOf(Object o)`
`int`
`lastIndexOf2(Object obj)`
Returns the last index of object `obj` in the sequence.
`ListIterator<E>`
`listIterator()`
`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 of `object`, followed by all elements in self.
`LazyList<E>`
`reject(CodeBlock condition)`
Rejects all elements from this collection for which the `condition` evaluates to `true`.
`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 the `condition` evaluates to `true`.
`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 of `List.subList(int, int)`.
`LazyList<E>`
`subSequence(int lower, int upper)`
Returns the sub-list of this list starting at number `lower`, up to and including element number `upper`.
`LazyList<E>`
`union(LazyList<? extends E> s)`
Returns the sequence consisting of all elements in self, followed by all elements in `s`.
`LazyList<E>`
`union(LazyList<? extends E> s, int index)`
Returns the sequence consisting of all elements in self, with all elements in `s` inserted at `index`.

### 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`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface java.util.Collection

`parallelStream, removeIf, stream, toArray`

### Methods inherited from interface java.lang.Iterable

`forEach`

### Methods inherited from interface java.util.List

`add, addAll, addFirst, addLast, clear, contains, containsAll, getFirst, getLast, isEmpty, iterator, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, size, sort, spliterator, toArray, toArray`

## Constructor Details

### LazyList

public LazyList(Iterable<E> dataSource)
Creates a `LazyList` around `dataSource`.

Parameters:
  `dataSource` - the underlying collection

### LazyList

public LazyList()
Creates an empty `LazyList`.

## Method Details

### createCache

protected void createCache()
Creates the cache collections.

Overrides:
  `createCache` in class `LazyCollection<E>`

### add

public void add(int index, E element)
Unsupported.

Specified by:
  `add` in interface `List<E>`
Parameters:
  `index` - the index at which to add
  `element` - the element to add
Throws:
  `UnsupportedOperationException`

### addAll

public boolean addAll(int index, Collection<? extends E> c)
Unsupported.

Specified by:
  `addAll` in interface `List<E>`
Parameters:
  `index` - the index at which to add
  `c` - the collection to add
Returns:
  nothing
Throws:
  `UnsupportedOperationException`

### get

public E get(int index)

Specified by:
  `get` in interface `List<E>`

### indexOf

public int indexOf(Object o)

Specified by:
  `indexOf` in interface `List<E>`

### lastIndexOf

public int lastIndexOf(Object o)

Specified by:
  `lastIndexOf` in interface `List<E>`

### listIterator

public ListIterator<E> listIterator()

Specified by:
  `listIterator` in interface `List<E>`

### listIterator

public ListIterator<E> listIterator(int index)

Specified by:
  `listIterator` in interface `List<E>`

### remove

public E remove(int index)
Unsupported.

Specified by:
  `remove` in interface `List<E>`
Parameters:
  `index` - the index at which to remove
Returns:
  nothing
Throws:
  `UnsupportedOperationException`

### set

public E set(int index, E element)
Unsupported.

Specified by:
  `set` in interface `List<E>`
Parameters:
  `index` - the index at which to set
  `element` - the element to set
Returns:
  nothing
Throws:
  `UnsupportedOperationException`

### subList

public LazyList<E> subList(int fromIndex, int toIndex)

Lazy implementation of `List.subList(int, int)`.

Specified by:
  `subList` in interface `List<E>`

### move

public void move(int newPosition, E object)
Unsupported in this implementation.

Specified by:
  `move` in interface `org.eclipse.emf.common.util.EList<E>`
Throws:
  `UnsupportedOperationException`

### move

public E move(int newPosition, int oldPosition)
Unsupported in this implementation.

Specified by:
  `move` in interface `org.eclipse.emf.common.util.EList<E>`
Throws:
  `UnsupportedOperationException`

### equals

public boolean equals(Object o)

Specified by:
  `equals` in interface `Collection<E>`
Specified by:
  `equals` in interface `List<E>`
Overrides:
  `equals` in class `Object`

### hashCode

public int hashCode()

Specified by:
  `hashCode` in interface `Collection<E>`
Specified by:
  `hashCode` in interface `List<E>`
Overrides:
  `hashCode` in class `Object`

### asString

public String asString(ExecEnv env)
Evaluates the collection as an OCL String.

Specified by:
  `asString` in class `LazyCollection<E>`
Parameters:
  `env` - the execution environment
Returns:
  the String representation of this `LazyCollection`.

### at

public E at(int i)
Returns the `i`-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(Object obj) throws IndexOutOfBoundsException
Returns the index of object `obj` 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:
  `IndexOutOfBoundsException` - if `obj` is not contained in this list.

### lastIndexOf2

public int lastIndexOf2(Object obj) throws IndexOutOfBoundsException
Returns the last index of object `obj` 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:
  `IndexOutOfBoundsException` - if `obj` 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 in `s`.

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 in `s` inserted at `index`.

Lazy operation.

Parameters:
  `s` - the list to union with this
  `index` - the insertion index (starting at 1)
Returns:
  The sequence consisting of all elements in self, with all elements in `s` inserted at `index`

### 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 by `object`.

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 of `object`, 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 with `object` inserted at position `index`. List index starts at 1.

Lazy operation.

Parameters:
  `index` - the index at which to insert
  `object` - the object to insert
Returns:
  The sequence consisting of self with `object` inserted at position `index`.

### subSequence

public LazyList<E> subSequence(int lower, int upper)
Returns the sub-list of this list starting at number `lower`, up to and including element number `upper`. List index starts at 1.

Lazy operation.

Parameters:
  `lower` - the sub-list lower bound, inclusive
  `upper` - 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 plus `object` added as the last element.

Lazy operation.

Specified by:
  `including` in class `LazyCollection<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 plus `object`.

Lazy operation.

Specified by:
  `including` in class `LazyCollection<E>`
Parameters:
  `object` - the object to include
  `index` - the index at which to insert `coll` (starting at 1)
Returns:
  The collection containing all elements of self plus `object`.

### includingAll

public LazyList<E> includingAll(Collection<? extends E> coll)
Returns the collection containing all elements of self plus `coll`.

Lazy operation.

Specified by:
  `includingAll` in class `LazyCollection<E>`
Parameters:
  `coll` - the collection to include
Returns:
  The collection containing all elements of self plus `coll`.

### includingAll

public LazyList<E> includingAll(Collection<? extends E> coll, int index)
Returns the collection containing all elements of self plus `coll`.

Lazy operation.

Specified by:
  `includingAll` in class `LazyCollection<E>`
Parameters:
  `coll` - the collection to include
  `index` - the index at which to insert `coll` (starting at 1)
Returns:
  The collection containing all elements of self plus `coll`.

### excluding

public LazyList<E> excluding(Object object)
Returns the sequence containing all elements of self apart from all occurrences of `object`.

Lazy operation.

Specified by:
  `excluding` in class `LazyCollection<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(Collection<?> coll)
Returns the collection containing all elements of self minus `coll`.

Lazy operation.

Specified by:
  `excludingAll` in class `LazyCollection<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 class `LazyCollection<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 of `first` running to `last` added as the last elements.

Lazy operation.

Specified by:
  `includingRange` in class `LazyCollection<E>`
Parameters:
  `first` - the first object of the range to include
  `last` - the last object of the range to include
Returns:
  The sequence containing all elements of self plus the sequence of `first` running to `last` added as the last elements

### select

public LazyList<E> select(CodeBlock condition)
Selects all elements from this collection for which the `condition` evaluates to `true`.

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 the `condition` evaluates to `true`.

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 of `function` 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., if `a < b` and `b < c` then `a < c`).

Specified by:
  `sortedBy` in class `LazyCollection<E>`
Parameters:
  `body` - the function to evaluate on each element
Returns:
  the sorted collection