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

## Class LazyBag<E>

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

Type Parameters:
  `E` -

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

Direct Known Subclasses:
  `LazyBag.IncludingBag`, `LazyBag.IntegerRangeBag`, `LazyBag.LongRangeBag`, `LazyBag.UnionBag`, `LazyBagOnCollection`

    public class LazyBag<E>
    extends LazyCollection<E>

Immutable `Collection` that supports lazy evaluation.

### Nested Class Summary

Nested Classes
`class` `LazyBag.BagIntersectionIterator` `LazyCollection.ReadOnlyIterator` that returns only elements contained in both underlying collections, where the element occurs as often as in the collection with the least occurrences of the element.
`static class` `LazyBag.IncludingBag<E>` `LazyBag` that implements the "including" operation.
`static class` `LazyBag.IntegerRangeBag` `LazyBag` that represents a range running from a first to last `Integer`.
`static class` `LazyBag.LongRangeBag` `LazyBag` that represents a range running from a first to last `Long`.
`static class` `LazyBag.UnionBag<E>` `LazyBag` that implements the "union" operation.

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

### Method Summary

All Methods Instance Methods Concrete Methods
`LazyBag<E>` `asBag()` Returns a Bag 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.
`protected void` `createCache()` Creates the cache collections.
`boolean` `equals​(java.lang.Object o)`
`LazyBag<E>` `excluding​(java.lang.Object object)` Returns the bag containing all elements of self apart from all occurrences of `object`.
`LazyBag<E>` `excludingAll​(java.util.Collection<?> coll)` Returns the collection containing all elements of self minus `coll`.
`LazyBag<?>` `flatten()` If the element type is not a collection type this results in the same self.
`int` `hashCode()`
`LazyBag<E>` `including​(E object)` Returns the bag containing all elements of self plus `object`.
`LazyBag<E>` `including​(E object, int index)` Returns the collection containing all elements of self plus `object`.
`LazyBag<E>` `includingAll​(java.util.Collection<? extends E> coll)` Returns the collection containing all elements of self plus `coll`.
`LazyBag<E>` `includingAll​(java.util.Collection<? extends E> coll, int index)` Returns the collection containing all elements of self plus `coll`.
`LazyBag<E>` `includingRange​(E first, E last)` Returns the bag containing all elements of self plus the bag of `first` running to `last`.
`LazyBag<E>` `intersection​(LazyBag<E> bag)` Returns the intersection of self and `bag` (i.e, the bag of all elements that are in both self and `s`, where the element occurs as often as in the bag with the least element occurrences).
`LazySet<E>` `intersection​(LazySet<E> set)` Returns the intersection of self and `set`.
`LazyBag<E>` `reject​(CodeBlock condition)` Rejects all elements from this collection for which the `condition` evaluates to `true`.
`LazyBag<E>` `select​(CodeBlock condition)` Selects all elements from this collection for which the `condition` evaluates to `true`.
`LazyList<E>` `sortedBy​(CodeBlock body)` Results in the Collection containing all elements of the source collection.
`LazyBag<E>` `union​(LazyBag<? extends E> bag)` Returns the union of self and `bag`.
`LazyBag<E>` `union​(LazySet<E> set)` Returns the union of self and `set`.

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

`add, addAll, any, appendElements, asOrderedSet, asSequence, 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, spliterator, stream, toArray`

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

`forEach`

### Constructor Detail

#### LazyBag

    public LazyBag()

Creates an empty `LazyBag`.

#### LazyBag

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

Creates a `LazyBag` around `dataSource`.

Parameters:
  `dataSource` - the underlying collection

### Method Detail

#### createCache

    protected void createCache()

Creates the cache collections.

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

#### equals

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

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

#### hashCode

    public int hashCode()

Specified by:
  `hashCode` in interface `java.util.Collection<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`.

#### union

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

Returns the union of self and `bag`.

Lazy operation.

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

#### union

    public LazyBag<E> union​(LazySet<E> set)

Returns the union of self and `set`.

Lazy operation.

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

#### intersection

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

Returns the intersection of self and `bag` (i.e, the bag of all elements that are in both self and `s`, where the element occurs as often as in the bag with the least element occurrences).

Lazy operation.

Parameters:
  `bag` - the collection to intersect with this
Returns:
  The intersection of self and `bag`.

#### intersection

    public LazySet<E> intersection​(LazySet<E> set)

Returns the intersection of self and `set`.

Lazy operation.

Parameters:
  `set` - the collection to intersect with this
Returns:
  The intersection of self and `set`.

#### including

    public LazyBag<E> including​(E object)

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

Lazy operation.

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

#### including

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

Returns the bag 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 bag containing all elements of self apart from all occurrences of `object`.

#### excludingAll

    public LazyBag<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`.

#### flatten

    public LazyBag<?> 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 : Bag() = Bag{} |
  acc->union(c->asBag() ) )
  else
  self
  endif

#### asBag

    public LazyBag<E> asBag()

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

Lazy operation.

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

#### includingRange

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

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

#### select

    public LazyBag<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 bag with only the selected elements.

#### reject

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