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:
Iterable<E>, Collection<E>, List<E>, Set<E>
Direct Known Subclasses:
LazyOrderedSet.IntegerRangeOrderedSet, LazyOrderedSet.LongRangeOrderedSet, LazyOrderedSet.NonCachingOrderedSet

public class LazyOrderedSet<E> extends LazyCollection<E> implements Set<E>, List<E>
Immutable Set and List that supports lazy evaluation.
  • Constructor Details

    • LazyOrderedSet

      public LazyOrderedSet()
      Creates an empty LazyOrderedSet.
    • LazyOrderedSet

      public LazyOrderedSet(Iterable<E> dataSource)
      Creates a LazyOrderedSet around dataSource.
      Parameters:
      dataSource - the underlying collection
  • Method Details

    • createCache

      protected void createCache()
      Creates the cache collections.
      Overrides:
      createCache in class LazyCollection<E>
    • iterator

      public Iterator<E> iterator()
      Specified by:
      iterator in interface Collection<E>
      Specified by:
      iterator in interface Iterable<E>
      Specified by:
      iterator in interface List<E>
      Specified by:
      iterator in interface Set<E>
      Overrides:
      iterator 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 object 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 LazyOrderedSet<E> subList(int fromIndex, int toIndex)

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

      Specified by:
      subList in interface List<E>
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface Collection<E>
      Specified by:
      equals in interface List<E>
      Specified by:
      equals in interface Set<E>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Collection<E>
      Specified by:
      hashCode in interface List<E>
      Specified by:
      hashCode in interface Set<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.
    • count

      public int count(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(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
      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
      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 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(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(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(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(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
    • spliterator

      public Spliterator<E> spliterator()
      Specified by:
      spliterator in interface Collection<E>
      Specified by:
      spliterator in interface Iterable<E>
      Specified by:
      spliterator in interface List<E>
      Specified by:
      spliterator in interface Set<E>