Package org.eclipse.m2m.atl.emftvm.util

## Class LazyOrderedSet<E>

- java.lang.Object
- - org.eclipse.m2m.atl.emftvm.util.LazyCollection<E>
  - - org.eclipse.m2m.atl.emftvm.util.LazyOrderedSet<E>

Type Parameters:
  `E` -

All Implemented Interfaces:
  `java.lang.Iterable<E>`, `java.util.Collection<E>`, `java.util.List<E>`, `java.util.Set<E>`

Direct Known Subclasses:
  `LazyOrderedSet.IntegerRangeOrderedSet`, `LazyOrderedSet.LongRangeOrderedSet`, `LazyOrderedSet.NonCachingOrderedSet`

    public class LazyOrderedSet<E>
    extends LazyCollection<E>
    implements java.util.Set<E>, java.util.List<E>

Immutable `Set` and `List` that supports lazy evaluation.

### Nested Class Summary

Nested Classes
`static class` `LazyOrderedSet.AppendOrderedSet<E>` `LazyOrderedSet` that appends an element to the underlying `LazyOrderedSet`, except when it already occurs in the underlying `LazyOrderedSet`.
`static class` `LazyOrderedSet.ExcludingOrderedSet<E>` `LazyOrderedSet` that excludes an element from the underlying `LazyOrderedSet`.
`static class` `LazyOrderedSet.InsertAtOrderedSet<E>` `LazyOrderedSet` that inserts an object into the underlying `LazyOrderedSet`, except when it already occurs in the underlying `LazyOrderedSet`.
`static class` `LazyOrderedSet.IntegerRangeOrderedSet` `LazyOrderedSet` that represents a range running from a first to last `Integer`.
`static class` `LazyOrderedSet.LongRangeOrderedSet` `LazyOrderedSet` that represents a range running from a first to last `Long`.
`static class` `LazyOrderedSet.NonCachingOrderedSet<E>` `LazyOrderedSet` that disables caching of the underlying `LazyOrderedSet`.
`static class` `LazyOrderedSet.PrependOrderedSet<E>` `LazyOrderedSet` that prepends an element to the underlying `LazyOrderedSet`, except when it already occurs in the underlying `LazyOrderedSet`.
`static class` `LazyOrderedSet.ReverseOrderedSet<E>` `LazyOrderedSet` in reverse order.
`static class` `LazyOrderedSet.SubOrderedSet<E>` `LazyOrderedSet` that represents a sub-range of the underlying `LazyOrderedSet`.

### 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
`LazyOrderedSet()` Creates an empty `LazyOrderedSet`.
`LazyOrderedSet​(java.lang.Iterable<E> dataSource)` Creates a `LazyOrderedSet` around `dataSource`.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `add​(int index, E element)` Unsupported.
`boolean` `addAll​(int index, java.util.Collection<? extends E> c)` Unsupported.
`LazyOrderedSet<E>` `append​(E object)` Returns the set of elements, consisting of all elements of self, followed by `object`.
`LazyOrderedSet<E>` `asOrderedSet()` Returns an OrderedSet identical to self.
`java.lang.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.
`int` `count​(java.lang.Object o)` Returns the number of occurrences of `object` in self. `post: result <= 1`
`protected void` `createCache()` Creates the cache collections.
`boolean` `equals​(java.lang.Object o)`
`LazyOrderedSet<E>` `excluding​(java.lang.Object object)` Returns the set containing all elements of self without `object`.
`LazyOrderedSet<E>` `excludingAll​(java.util.Collection<?> coll)` Returns the collection containing all elements of self minus `coll`.
`E` `first()` Returns the first element in self.
`LazyOrderedSet<?>` `flatten()` If the element type is not a collection type this results in the same self.
`E` `get​(int index)`
`int` `hashCode()`
`LazyOrderedSet<E>` `including​(E object)` Returns the set containing all elements of self plus `object`.
`LazyOrderedSet<E>` `including​(E object, int index)` Returns the collection containing all elements of self plus `object`.
`LazyOrderedSet<E>` `includingAll​(java.util.Collection<? extends E> coll)` Returns the collection containing all elements of self plus `coll`.
`LazyOrderedSet<E>` `includingAll​(java.util.Collection<? extends E> coll, int index)` Returns the collection containing all elements of self plus `coll`.
`LazyOrderedSet<E>` `includingRange​(E first, E last)` Returns the OrderedSet containing all elements of self plus the OrderedSet of `first` running to `last` added as the last elements.
`int` `indexOf​(java.lang.Object o)`
`int` `indexOf2​(java.lang.Object obj)` Returns the index of object `obj` in the sequence.
`LazyOrderedSet<E>` `insertAt​(int index, E object)` Returns the OrderedSet consisting of self with `object` inserted at position `index`.
`LazyOrderedSet<E>` `intersection​(LazyBag<E> s)` Returns the intersection of self and `s` (i.e, the set of all elements that are in both self and `s`).
`LazyOrderedSet<E>` `intersection​(LazyOrderedSet<E> s)` Returns the intersection of self and `s` (i.e, the set of all elements that are in both self and `s`).
`LazyOrderedSet<E>` `intersection​(LazySet<E> s)` Returns the intersection of self and `s` (i.e, the set of all elements that are in both self and `s`).
`java.util.Iterator<E>` `iterator()`
`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 object `obj` in the sequence.
`java.util.ListIterator<E>` `listIterator()`
`java.util.ListIterator<E>` `listIterator​(int index)`
`LazyOrderedSet<E>` `prepend​(E object)` Returns the OrderedSet consisting of `object`, followed by all elements in self.
`LazyOrderedSet<E>` `reject​(CodeBlock condition)` Rejects all elements from this collection for which the `condition` evaluates to `true`.
`E` `remove​(int index)` Unsupported.
`LazyOrderedSet<E>` `reverse()` Returns the ordered set of elements with same elements but with the opposite order.
`LazyOrderedSet<E>` `select​(CodeBlock condition)` Selects all elements from this collection for which the `condition` evaluates to `true`.
`E` `set​(int index, E element)` Unsupported.
`LazyOrderedSet<E>` `sortedBy​(CodeBlock body)` Results in the Collection containing all elements of the source collection.
`LazyOrderedSet<E>` `subList​(int fromIndex, int toIndex)` Lazy implementation of `List.subList(int, int)`.
`LazyOrderedSet<E>` `subSequence​(int lower, int upper)` Returns the sub-set of self starting at number `lower`, up to and including element number `upper`.
`LazyOrderedSet<E>` `subtract​(LazyOrderedSet<E> s)` Returns the elements of self, which are not in `s`.
`LazyOrderedSet<E>` `subtract​(LazySet<E> s)` Returns the elements of self, which are not in `s`.
`LazyOrderedSet<E>` `symmetricDifference​(LazyOrderedSet<E> s)` Returns the set containing all the elements that are in self or `s`, but not in both.
`LazyBag<E>` `union​(LazyBag<E> bag)` Returns the union of self and `bag`.
`LazyOrderedSet<E>` `union​(LazyOrderedSet<? extends E> s)` Returns the union of self and `s`, where elements of self are returned before elements of s.
`LazyOrderedSet<E>` `union​(LazyOrderedSet<? extends E> s, int index)` Returns the ordered set consisting of all elements in self, with all elements in `s` inserted at `index`.
`LazySet<E>` `union​(LazySet<E> s)` Returns the union of self and `s`.

### Methods inherited from class org.eclipse.m2m.atl.emftvm.util.LazyCollection

`add, addAll, any, appendElements, asBag, asSequence, asSet, clear, contains, containsAll, containsAny, excludes, excludesAll, exists, exists2, forAll, forAll2, includes, includesAll, isEmpty, isUnique, iterate, 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, clear, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, size, sort, spliterator, toArray, toArray`

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

`add, addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, size, spliterator, toArray, toArray`

### Constructor Detail

#### LazyOrderedSet

    public LazyOrderedSet()

Creates an empty `LazyOrderedSet`.

#### LazyOrderedSet

    public LazyOrderedSet​(java.lang.Iterable<E> dataSource)

Creates a `LazyOrderedSet` around `dataSource`.

Parameters:
  `dataSource` - the underlying collection

### Method Detail

#### createCache

    protected void createCache()

Creates the cache collections.

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

#### iterator

    public java.util.Iterator<E> iterator()

Specified by:
  `iterator` in interface `java.util.Collection<E>`
Specified by:
  `iterator` in interface `java.lang.Iterable<E>`
Specified by:
  `iterator` in interface `java.util.List<E>`
Specified by:
  `iterator` in interface `java.util.Set<E>`
Overrides:
  `iterator` in class `LazyCollection<E>`

#### add

    public void add​(int index,
                    E element)

Unsupported.

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

#### addAll

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

Unsupported.

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

#### get

    public E get​(int index)

Specified by:
  `get` in interface `java.util.List<E>`

#### indexOf

    public int indexOf​(java.lang.Object o)

Specified by:
  `indexOf` in interface `java.util.List<E>`

#### lastIndexOf

    public int lastIndexOf​(java.lang.Object o)

Specified by:
  `lastIndexOf` in interface `java.util.List<E>`

#### listIterator

    public java.util.ListIterator<E> listIterator()

Specified by:
  `listIterator` in interface `java.util.List<E>`

#### listIterator

    public java.util.ListIterator<E> listIterator​(int index)

Specified by:
  `listIterator` in interface `java.util.List<E>`

#### remove

    public E remove​(int index)

Unsupported.

Specified by:
  `remove` in interface `java.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 interface `java.util.List<E>`
Parameters:
  `index` - the index at which to set
  `element` - the element to set
Returns:
  nothing
Throws:
  `java.lang.UnsupportedOperationException`

#### subList

    public LazyOrderedSet<E> subList​(int fromIndex,
                                     int toIndex)

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

Specified by:
  `subList` in interface `java.util.List<E>`

#### equals

    public boolean equals​(java.lang.Object o)

Specified by:
  `equals` in interface `java.util.Collection<E>`
Specified by:
  `equals` in interface `java.util.List<E>`
Specified by:
  `equals` in interface `java.util.Set<E>`
Overrides:
  `equals` in class `java.lang.Object`

#### hashCode

    public int hashCode()

Specified by:
  `hashCode` in interface `java.util.Collection<E>`
Specified by:
  `hashCode` in interface `java.util.List<E>`
Specified by:
  `hashCode` in interface `java.util.Set<E>`
Overrides:
  `hashCode` in class `java.lang.Object`

#### asString

    public java.lang.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`.

#### count

    public int count​(java.lang.Object o)

Returns the number of occurrences of `object` in self.
`post: result <= 1`

Overrides:
  `count` in class `LazyCollection<E>`
Parameters:
  `o` - the object to count
Returns:
  The number of occurrences of `object` in self.

#### 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​(java.lang.Object obj)
                 throws java.lang.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
Returns:
  The index of object `obj` in the sequence.
Throws:
  `java.lang.IndexOutOfBoundsException` - if `obj` is not contained in this list.

#### lastIndexOf2

    public int lastIndexOf2​(java.lang.Object obj)
                     throws java.lang.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
Returns:
  The last index of object `obj` in the sequence.
Throws:
  `java.lang.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 LazyOrderedSet<E> union​(LazyOrderedSet<? extends E> s)

Returns the union of self and `s`, where elements of self are returned before elements of s.

Lazy operation.

Parameters:
  `s` - the collection to union with self
Returns:
  The union of self and `s`.

#### union

    public LazyOrderedSet<E> union​(LazyOrderedSet<? extends E> s,
                                   int index)

Returns the ordered set consisting of all elements in self, with all elements in `s` inserted at `index`.

Lazy operation.

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

#### union

    public LazySet<E> union​(LazySet<E> s)

Returns the union of self and `s`.

Lazy operation.

Parameters:
  `s` - the collection to union with self
Returns:
  The union of self and `s`.

#### union

    public LazyBag<E> union​(LazyBag<E> bag)

Returns the union of self and `bag`.

Lazy operation.

Parameters:
  `bag` - the collection to union with self
Returns:
  The union of self and `bag`.

#### intersection

    public LazyOrderedSet<E> intersection​(LazyOrderedSet<E> s)

Returns the intersection of self and `s` (i.e, the set of all elements that are in both self and `s`).

Lazy operation.

Parameters:
  `s` - the collection to intersect with self
Returns:
  The intersection of self and `s` (i.e, the set of all elements that are in both self and `s`).

#### intersection

    public LazyOrderedSet<E> intersection​(LazySet<E> s)

Returns the intersection of self and `s` (i.e, the set of all elements that are in both self and `s`).

Lazy operation.

Parameters:
  `s` - the collection to intersect with self
Returns:
  The intersection of self and `s` (i.e, the set of all elements that are in both self and `s`).

#### intersection

    public LazyOrderedSet<E> intersection​(LazyBag<E> s)

Returns the intersection of self and `s` (i.e, the set of all elements that are in both self and `s`).

Lazy operation.

Parameters:
  `s` - the collection to intersect with self
Returns:
  The intersection of self and `s` (i.e, the set of all elements that are in both self and `s`).

#### subtract

    public LazyOrderedSet<E> subtract​(LazyOrderedSet<E> s)

Returns the elements of self, which are not in `s`.

Lazy operation.

Parameters:
  `s` - the collection to subtract from self
Returns:
  The elements of self, which are not in `s`.

#### subtract

    public LazyOrderedSet<E> subtract​(LazySet<E> s)

Returns the elements of self, which are not in `s`.

Lazy operation.

Parameters:
  `s` - the collection to subtract from self
Returns:
  The elements of self, which are not in `s`.

#### including

    public LazyOrderedSet<E> including​(E object)

Returns the set containing all elements of self plus `object`.

Lazy operation.

Specified by:
  `including` in class `LazyCollection<E>`
Parameters:
  `object` - the element to include
Returns:
  The set containing all elements of self plus `object`

#### including

    public LazyOrderedSet<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 LazyOrderedSet<E> includingAll​(java.util.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 LazyOrderedSet<E> includingAll​(java.util.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 LazyOrderedSet<E> excluding​(java.lang.Object object)

Returns the set containing all elements of self without `object`.

Lazy operation.

Specified by:
  `excluding` in class `LazyCollection<E>`
Parameters:
  `object` - the element to exclude
Returns:
  The set containing all elements of self without `object`.

#### excludingAll

    public LazyOrderedSet<E> excludingAll​(java.util.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`.

#### symmetricDifference

    public LazyOrderedSet<E> symmetricDifference​(LazyOrderedSet<E> s)

Returns the set containing all the elements that are in self or `s`, but not in both.

Lazy operation.

Parameters:
  `s` - the collection to perform the symmetric difference with
Returns:
  The set containing all the elements that are in self or `s`, but not in both.

#### flatten

    public LazyOrderedSet<?> 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 set containing all the elements of all the elements of self.

Lazy operation.

Returns:
  if self.type.elementType.oclIsKindOf(CollectionType) then
  self->iterate(c; acc : OrderedSet() = OrderedSet{} |
  acc->union(c->asOrderedSet() ) )
  else
  self
  endif

#### append

    public LazyOrderedSet<E> append​(E object)

Returns the set of elements, consisting of all elements of self, followed by `object`.

Lazy operation.

Parameters:
  `object` - the element to append
Returns:
  The set of elements, consisting of all elements of self, followed by `object`.

#### prepend

    public LazyOrderedSet<E> prepend​(E object)

Returns the OrderedSet consisting of `object`, followed by all elements in self.

Lazy operation.

Parameters:
  `object` - the element to prepend
Returns:
  The OrderedSet consisting of `object`, followed by all elements in self.

#### insertAt

    public LazyOrderedSet<E> insertAt​(int index,
                                      E object)

Returns the OrderedSet 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 element to insert
Returns:
  The OrderedSet consisting of self with `object` inserted at position `index`.

#### subSequence

    public LazyOrderedSet<E> subSequence​(int lower,
                                         int upper)

Returns the sub-set of self starting at number `lower`, up to and including element number `upper`. List index starts at 1.

Lazy operation.

Parameters:
  `lower` - the sub-range lower bound, inclusive
  `upper` - the sub-range upper bound, inclusive
Returns:
  The sub-set of self starting at number `lower`, up to and including element number `upper`.

#### reverse

    public LazyOrderedSet<E> reverse()

Returns the ordered set of elements with same elements but with the opposite order.

Returns:
  The ordered set of elements with same elements but with the opposite order.

#### asOrderedSet

    public LazyOrderedSet<E> asOrderedSet()

Returns an OrderedSet identical to self. This operation exists for convenience reasons.

Lazy operation.

Overrides:
  `asOrderedSet` in class `LazyCollection<E>`
Returns:
  An OrderedSet identical to self. This operation exists for convenience reasons.

#### includingRange

    public LazyOrderedSet<E> includingRange​(E first,
                                            E last)

Returns the OrderedSet containing all elements of self plus the OrderedSet 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 OrderedSet containing all elements of self plus the OrderedSet of `first` running to `last` added as the last elements

#### select

    public LazyOrderedSet<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 ordered set with only the selected elements.

#### reject

    public LazyOrderedSet<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 ordered set 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 LazyOrderedSet<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