Class LazyOrderedSet<E>

    • 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

      • 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