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

## Class LazySet<E>

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

Type Parameters:
  `E` - the collection element type

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

Direct Known Subclasses:
  `EnumConversionSetOnSet`, `LazySet.IntegerRangeSet`, `LazySet.LongRangeSet`, `LazySet.NonCachingSet`, `LazySetOnSet`

    public class LazySet<E>
    extends LazyCollection<E>
    implements java.util.Set<E>

Immutable `Set` that supports lazy evaluation.

### Nested Class Summary

Nested Classes
`static class` `LazySet.ExcludingSet<E>` `LazySet` that excludes an element from the underlying `LazySet`.
`static class` `LazySet.IncludingSet<E>` `LazySet` that includes an element into the underlying `LazySet`, except if the element already occurs in the underlying `LazySet`.
`static class` `LazySet.IntegerRangeSet` `LazySet` that represents a range running from a first to last `Integer`.
`static class` `LazySet.LongRangeSet` `LazySet` that represents a range running from a first to last `Long`.
`static class` `LazySet.NonCachingSet<E>` Abstract `LazySet` that disables caching of the underlying `LazySet`.

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

### Method Summary

All Methods Instance Methods Concrete Methods
`LazySet<E>` `asSet()` Returns a Set identical to self.
`java.lang.String` `asString​(ExecEnv env)` Evaluates the collection as an OCL String.
`<T> LazyBag<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)`
`LazySet<E>` `excluding​(java.lang.Object object)` Returns the set containing all elements of self without `object`.
`LazySet<E>` `excludingAll​(java.util.Collection<?> coll)` Returns the collection containing all elements of self minus `coll`.
`LazySet<?>` `flatten()` If the element type is not a collection type this results in the same self.
`int` `hashCode()`
`LazySet<E>` `including​(E object)` Returns the set containing all elements of self plus `object`.
`LazySet<E>` `including​(E object, int index)` Returns the collection containing all elements of self plus `object`.
`LazySet<E>` `includingAll​(java.util.Collection<? extends E> coll)` Returns the collection containing all elements of self plus `coll`.
`LazySet<E>` `includingAll​(java.util.Collection<? extends E> coll, int index)` Returns the collection containing all elements of self plus `coll`.
`LazySet<E>` `includingRange​(E first, E last)` Returns the Set containing all elements of self plus the Set of `first` running to `last`.
`LazySet<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`).
`LazySet<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()`
`LazySet<E>` `reject​(CodeBlock condition)` Rejects all elements from this collection for which the `condition` evaluates to `true`.
`LazySet<E>` `select​(CodeBlock condition)` Selects all elements from this collection for which the `condition` evaluates to `true`.
`LazyOrderedSet<E>` `sortedBy​(CodeBlock body)` Results in the Collection containing all elements of the source collection.
`LazySet<E>` `subtract​(LazySet<E> s)` Returns the elements of self, which are not in `s`.
`LazySet<E>` `symmetricDifference​(LazySet<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`.
`LazySet<E>` `union​(LazySet<? extends 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, asOrderedSet, asSequence, 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.Set

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

### Constructor Detail

#### LazySet

    public LazySet()

Creates an empty `LazySet`.

#### LazySet

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

Creates a `LazySet` 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.Set<E>`
Overrides:
  `iterator` in class `LazyCollection<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.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.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.

#### union

    public LazySet<E> union​(LazySet<? extends 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 LazySet<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 LazySet<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 LazySet<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 LazySet<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 object to include
Returns:
  The set containing all elements of self plus `object`

#### including

    public LazySet<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 LazySet<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 LazySet<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`.
Throws:
  `java.lang.UnsupportedOperationException`

#### excluding

    public LazySet<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 object to exclude
Returns:
  The set containing all elements of self without `object`.

#### excludingAll

    public LazySet<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 LazySet<E> symmetricDifference​(LazySet<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 LazySet<?> 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 : Set() = Set{} |
  acc->union(c->asSet() ) )
  else
  self
  endif

#### asSet

    public LazySet<E> asSet()

Returns a Set identical to self. This operation exists for convenience reasons.

Lazy operation.

Overrides:
  `asSet` in class `LazyCollection<E>`
Returns:
  A Set identical to self. This operation exists for convenience reasons.

#### includingRange

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

Returns the Set containing all elements of self plus the Set of `first` running to `last`.

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

#### select

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

#### reject

    public LazySet<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 set without the rejected elements.

#### collect

    public <T> LazyBag<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 bag 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