org.eclipse.ocl.util
Class CollectionUtil

java.lang.Object
  extended by org.eclipse.ocl.util.CollectionUtil

public class CollectionUtil
extends java.lang.Object

Utility methods for working with OCL collection values.

Author:
Christian W. Damus (cdamus)

Method Summary
static
<E> java.util.Collection<E>
append(java.util.Collection<E> self, E object)
          Implementation of the OCL OrderedSet::append(object : T) : OrderedSet(T) Sequence::append(object : T) : Sequence(T) operations.
static
<E> Bag<E>
asBag(java.util.Collection<E> self)
          Implementation of the OCL Set::asBag() : Bag(T) Bag::asBag() : Bag(T) Sequence::asBag() : Bag(T) operations.
static
<E> java.util.LinkedHashSet<E>
asOrderedSet(java.util.Collection<E> self)
          Implementation of the OCL Set::asOrderedSet() : OrderedSet(T) Bag::asOrderedSet() : OrderedSet(T) Sequence::asOrderedSet() : OrderedSet(T) operations.
static
<E> java.util.List<E>
asSequence(java.util.Collection<E> self)
          Implementation of the OCL Set::asSequence() : Sequence(T) Bag::asSequence() : Sequence(T) Sequence::asSequence() : Sequence(T) operations.
static
<E> java.util.Set<E>
asSet(java.util.Collection<E> self)
          Implementation of the OCL Set::asSet() : Set(T) Bag::asSet() : Set(T) Sequence::asSet() : Set(T) operations.
static
<E> E
at(java.util.Collection<E> self, int index)
          Implementation of the OCL OrderedSet::at(index : Integer) : T Sequence::at(index : Integer) : T operations.
static int count(java.util.Collection<?> self, java.lang.Object object)
          Implementation of the OCL Collection::count(object : T) : Integer operation.
static
<E> Bag<E>
createNewBag()
          Creates a new OCL Bag.
static
<E> Bag<E>
createNewBag(java.util.Collection<? extends E> c)
          Creates a new OCL Bag with initial contents supplied.
static
<E> java.util.Collection<E>
createNewCollection(java.util.Collection<? extends E> c)
          Creates a new OCL collection of the same kind and contents as the specified prototype.
static
<E> java.util.Collection<E>
createNewCollection(CollectionKind kind)
          Creates a new OCL Collection of the specified kind.
static
<E> java.util.Collection<E>
createNewCollection(CollectionKind kind, java.util.Collection<E> c)
          Creates a new OCL Collection of the specified kind.
static
<E> java.util.Collection<E>
createNewCollectionOfSameKind(java.util.Collection<?> c)
          Creates a new, empty OCL collection of the same kind as the specified prototype.
static
<E> java.util.LinkedHashSet<E>
createNewOrderedSet()
          Creates a new OCL OrderedSet.
static
<E> java.util.LinkedHashSet<E>
createNewOrderedSet(java.util.Collection<? extends E> c)
          Creates a new OCL OrderedSet with initial contents supplied.
static
<E> java.util.List<E>
createNewSequence()
          Creates a new OCL Sequence.
static
<E> java.util.List<E>
createNewSequence(java.util.Collection<? extends E> c)
          Creates a new OCL Sequence with initial contents supplied.
static
<E> java.util.Set<E>
createNewSet()
          Creates a new OCL Set.
static
<E> java.util.Set<E>
createNewSet(java.util.Collection<? extends E> c)
          Creates a new OCL Set with initial contents supplied.
static boolean equals(java.util.Collection<?> self, java.util.Collection<?> c)
          Implementation of the OCL Set::=(set : Set(T)) : Boolean OrderedSet::=(set : OrderedSet(T)) : Boolean Bag::=(bag : Bag(T)) : Boolean Sequence::=(s : Sequence(T)) : Boolean operations.
static boolean excludes(java.util.Collection<?> self, java.lang.Object object)
          Implementation of the OCL Collection::excludes(object : T) : Boolean operation.
static boolean excludesAll(java.util.Collection<?> self, java.util.Collection<?> c)
          Implementation of the OCL Collection::excludesAll(c : Collection(T)) : Boolean operation.
static
<E> java.util.Collection<E>
excluding(java.util.Collection<E> self, java.lang.Object object)
          Implementation of the OCL Set::excluding(object : T) : Set(T) Bag::excluding(object : T) : Bag(T) Sequence::excluding(object : T) : Sequence(T) operations.
static
<E> E
first(java.util.Collection<E> self)
          Implementation of the OCL OrderedSet::first() : T Sequence::first() : T operations.
static java.util.Collection<?> flatten(java.util.Collection<?> self)
          Implementation of the OCL Set::flatten() : Set(T2) Bag::flatten() : Bag(T2) Sequence::flatten() : Sequence(T2) operations.
static
<C> C
getFlattenedElementType(CollectionType<C,?> type)
          Obtains the type of the flattened form of the specified collection type.
static int hashCode(java.util.Collection<?> c)
          Computes the hash of a collection, accounting for the similar hashing of primitive numeric values that OCL considers equal but Java does not.
static boolean includes(java.util.Collection<?> self, java.lang.Object object)
          Implementation of the OCL Collection::includes(object : T) : Boolean operation.
static boolean includesAll(java.util.Collection<?> self, java.util.Collection<?> c)
          Implementation of the OCL Collection::includesAll(c : Collection(T)) : Boolean operation.
static
<E> java.util.Collection<E>
including(java.util.Collection<E> self, E object)
          Implementation of the OCL Set::including(object : T) : Set(T) Bag::including(object : T) : Bag(T) Sequence::including(object : T) : Sequence(T) operations.
static
<E> java.lang.Integer
indexOf(java.util.Collection<? extends E> self, E object)
          Implementation of the OCL OrderedSet::indexOf(object : T) : Integer Sequence::indexOf(object : T) : Integer operations.
static
<E> java.util.Collection<E>
insertAt(java.util.Collection<E> self, int index, E object)
          Implementation of the OCL OrderedSet::insertAt(index : Integer, object : T) : OrderedSet(T) Sequence::insertAt(index : Integer, object : T) : Sequence(T) operations.
static
<E> java.util.Collection<E>
intersection(java.util.Collection<? extends E> self, java.util.Collection<? extends E> c)
          Implementation of the OCL Set::intersection(set : Set(T)) : Set(T) Set::intersection(bag : Bag(T)) : Set(T) Bag::intersection(set : Set(T)) : Set(T) Bag::intersection(bag : Bag(T)) : Set(T) operations.
static boolean isEmpty(java.util.Collection<?> self)
          Implementation of the OCL Collection::isEmpty() : Boolean operation.
static
<E> E
last(java.util.Collection<E> self)
          Implementation of the OCL OrderedSet::lset() : T Sequence::lset() : T operations.
static java.lang.Object max(java.util.Collection<?> self)
          Implementation of the OCL Collection::max() : T operation.
static java.lang.Object min(java.util.Collection<?> self)
          Implementation of the OCL Collection::min() : T operation.
static
<E> java.util.Set<E>
minus(java.util.Set<? extends E> self, java.util.Set<? extends E> set)
          Implementation of the OCL Set::-(set : Set(T)) : Set(T) operation.
static boolean notEmpty(java.util.Collection<?> self)
          Implementation of the OCL Collection::notEmpty() : Boolean operation.
static
<E> java.util.Collection<E>
prepend(java.util.Collection<E> self, E object)
          Implementation of the OCL OrderedSet::prepend(object : T) : OrderedSet(T) Sequence::prepend(object : T) : Sequence(T) operations.
static
<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
java.util.Set<Tuple<O,P>>
product(EvaluationEnvironment<C,O,P,CLS,E> evalEnv, Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env, java.util.Collection<?> self, java.util.Collection<?> c, C tupleType)
          Implementation of the OCL Collection::product(c : Collection(T2)) : Set(Tuple(first : T, second : T2)) operations.
static
<E> java.util.Collection<E>
subOrderedSet(java.util.Collection<E> self, int lower, int upper)
          Implementation of the OCL OrderedSet::subOrderedSet(lower : Integer, upper : Integer) : OrderedSet(T) operation.
static
<E> java.util.Collection<E>
subSequence(java.util.Collection<E> self, int lower, int upper)
          Implementation of the OCL Sequence::subSequence(lower : Integer, upper : Integer) : Sequence(T) operation.
static java.lang.Object sum(java.util.Collection<?> self)
          Implementation of the OCL Collection::sum() : T operation.
static
<E> java.util.Set<E>
symmetricDifference(java.util.Set<? extends E> self, java.util.Set<? extends E> set)
          Implementation of the OCL Set::symmetricDifference(set : Set(T)) : Set(T) operation.
static java.lang.String toString(java.util.Collection<?> c)
          Computes the string representation of a collection value using syntax like OCL's collection literals (e.g., OrderedSet{...}) instead of Java's default (i.e., [...]).
static
<E> java.util.Collection<E>
union(java.util.Collection<? extends E> self, java.util.Collection<? extends E> c)
          Implementation of the OCL Set::union(set : Set(T)) : Set(T) Set::union(bag : Bag(T)) : Bag(T) Bag::union(set : Set(T)) : Bag(T) Bag::union(bag : Bag(T)) : Bag(T) Sequence::union(s : Sequence(T)) : Sequence(T) operations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

includes

public static boolean includes(java.util.Collection<?> self,
                               java.lang.Object object)
Implementation of the OCL Collection::includes(object : T) : Boolean operation.

Parameters:
self - the source collection
object - an object
Returns:
whether the collection includes the object

excludes

public static boolean excludes(java.util.Collection<?> self,
                               java.lang.Object object)
Implementation of the OCL Collection::excludes(object : T) : Boolean operation.

Parameters:
self - the source collection
object - an object
Returns:
whether the collection does not include the object

count

public static int count(java.util.Collection<?> self,
                        java.lang.Object object)
Implementation of the OCL Collection::count(object : T) : Integer operation.

Parameters:
self - the source collection
object - an object
Returns:
the number of occurrences of the object in the collection

includesAll

public static boolean includesAll(java.util.Collection<?> self,
                                  java.util.Collection<?> c)
Implementation of the OCL Collection::includesAll(c : Collection(T)) : Boolean operation.

Parameters:
self - the source collection
c - another collection
Returns:
whether the source collection includes all of the elements of the other

excludesAll

public static boolean excludesAll(java.util.Collection<?> self,
                                  java.util.Collection<?> c)
Implementation of the OCL Collection::excludesAll(c : Collection(T)) : Boolean operation.

Parameters:
self - the source collection
c - another collection
Returns:
whether the source collection does not contain any of the elements of the other

isEmpty

public static boolean isEmpty(java.util.Collection<?> self)
Implementation of the OCL Collection::isEmpty() : Boolean operation.

Parameters:
self - the source collection
Returns:
whether the collection does not have any elements

max

public static java.lang.Object max(java.util.Collection<?> self)
Implementation of the OCL Collection::max() : T operation.

Parameters:
self - the source collection
Returns:
the largest of the collection's elements
Since:
3.2

min

public static java.lang.Object min(java.util.Collection<?> self)
Implementation of the OCL Collection::min() : T operation.

Parameters:
self - the source collection
Returns:
the smallest of the collection's elements
Since:
3.2

notEmpty

public static boolean notEmpty(java.util.Collection<?> self)
Implementation of the OCL Collection::notEmpty() : Boolean operation.

Parameters:
self - the source collection
Returns:
whether the collection has any elements

sum

public static java.lang.Object sum(java.util.Collection<?> self)
Implementation of the OCL Collection::sum() : T operation.

Parameters:
self - the source collection
Returns:
the sum of the collection's elements

equals

public static boolean equals(java.util.Collection<?> self,
                             java.util.Collection<?> c)
Implementation of the OCL operations.

Parameters:
self - the source collection
c - another collection of the same kind
Returns:
whether collections are equal

hashCode

public static int hashCode(java.util.Collection<?> c)
Computes the hash of a collection, accounting for the similar hashing of primitive numeric values that OCL considers equal but Java does not.

Parameters:
c - a collection
Returns:
its hash

intersection

public static <E> java.util.Collection<E> intersection(java.util.Collection<? extends E> self,
                                                       java.util.Collection<? extends E> c)
Implementation of the OCL operations.

Parameters:
self - the source set or bag
c - another set or bag
Returns:
the intersection of the source set or bag with the other set or bag

union

public static <E> java.util.Collection<E> union(java.util.Collection<? extends E> self,
                                                java.util.Collection<? extends E> c)
Implementation of the OCL operations.

Parameters:
self - the source collection
c - another collection
Returns:
the union of the source collection with the other

flatten

public static java.util.Collection<?> flatten(java.util.Collection<?> self)
Implementation of the OCL operations.

Parameters:
self - the source collection
Returns:
the flattened collection

getFlattenedElementType

public static <C> C getFlattenedElementType(CollectionType<C,?> type)
Obtains the type of the flattened form of the specified collection type.

Parameters:
type - a collection type
Returns:
the flattened collection type
Since:
1.2

minus

public static <E> java.util.Set<E> minus(java.util.Set<? extends E> self,
                                         java.util.Set<? extends E> set)
Implementation of the OCL Set::-(set : Set(T)) : Set(T) operation.

Parameters:
self - the source set
set - another set
Returns:
the subtraction of the other set from the source set

excluding

public static <E> java.util.Collection<E> excluding(java.util.Collection<E> self,
                                                    java.lang.Object object)
Implementation of the OCL operations.

Parameters:
self - the source collection
object - an object
Returns:
the source collection without any occurences of the object

symmetricDifference

public static <E> java.util.Set<E> symmetricDifference(java.util.Set<? extends E> self,
                                                       java.util.Set<? extends E> set)
Implementation of the OCL Set::symmetricDifference(set : Set(T)) : Set(T) operation.

Parameters:
self - the source set
set - another set
Returns:
the set of elements in either the source or the other set but not in both

including

public static <E> java.util.Collection<E> including(java.util.Collection<E> self,
                                                    E object)
Implementation of the OCL operations.

Parameters:
self - the source collection
object - an object
Returns:
the source collection with the object added

asSet

public static <E> java.util.Set<E> asSet(java.util.Collection<E> self)
Implementation of the OCL operations.

Parameters:
self - the source collection
Returns:
the source collection as a set

asBag

public static <E> Bag<E> asBag(java.util.Collection<E> self)
Implementation of the OCL operations.

Parameters:
self - the source collection
Returns:
the source collection as a bag

asSequence

public static <E> java.util.List<E> asSequence(java.util.Collection<E> self)
Implementation of the OCL operations.

Parameters:
self - the source collection
Returns:
the source collection as a sequence

asOrderedSet

public static <E> java.util.LinkedHashSet<E> asOrderedSet(java.util.Collection<E> self)
Implementation of the OCL operations.

Parameters:
self - the source collection
Returns:
the source collection as an ordered set

product

public static <PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> java.util.Set<Tuple<O,P>> product(EvaluationEnvironment<C,O,P,CLS,E> evalEnv,
                                                                                    Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env,
                                                                                    java.util.Collection<?> self,
                                                                                    java.util.Collection<?> c,
                                                                                    C tupleType)
Implementation of the OCL Collection::product(c : Collection(T2)) : Set(Tuple(first : T, second : T2)) operations.

Parameters:
evalEnv - the current evaluation environment (for construction of tuples)
env - the current OCL environment (for introspection of the tuple type)
self - the source collection
c - another collection
Returns:
the product of the collections

append

public static <E> java.util.Collection<E> append(java.util.Collection<E> self,
                                                 E object)
Implementation of the OCL operations.

Parameters:
self - the source collection
object - an object
Returns:
the source collection with the object appended

prepend

public static <E> java.util.Collection<E> prepend(java.util.Collection<E> self,
                                                  E object)
Implementation of the OCL operations.

Parameters:
self - the source collection
object - an object
Returns:
the source collection with the object prepended

insertAt

public static <E> java.util.Collection<E> insertAt(java.util.Collection<E> self,
                                                   int index,
                                                   E object)
Implementation of the OCL operations.

Parameters:
self - the source collection
index - the 1-based (in OCL fashion) index
object - an object
Returns:
the source collection with the object inserted at the index
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of bounds

subOrderedSet

public static <E> java.util.Collection<E> subOrderedSet(java.util.Collection<E> self,
                                                        int lower,
                                                        int upper)
Implementation of the OCL OrderedSet::subOrderedSet(lower : Integer, upper : Integer) : OrderedSet(T) operation.

Parameters:
self - the source set
lower - the 1-based (in OCL fashion) inclusive lower bound
upper - the 1-based (in OCL fashion) inclusive upper bound
Returns:
the slice of the source set
Throws:
java.lang.IndexOutOfBoundsException - if an index is out of bounds
java.lang.IllegalArgumentException - if the lower bound is greater than the upper

subSequence

public static <E> java.util.Collection<E> subSequence(java.util.Collection<E> self,
                                                      int lower,
                                                      int upper)
Implementation of the OCL Sequence::subSequence(lower : Integer, upper : Integer) : Sequence(T) operation.

Parameters:
self - the source sequence
lower - the 1-based (in OCL fashion) inclusive lower bound
upper - the 1-based (in OCL fashion) inclusive upper bound
Returns:
the source collection with the object inserted at the index
Throws:
java.lang.IndexOutOfBoundsException - if an index is out of bounds
java.lang.IllegalArgumentException - if the lower bound is greater than the upper

at

public static <E> E at(java.util.Collection<E> self,
                       int index)
Implementation of the OCL operations.

Parameters:
self - the source collection
index - the 1-based (in OCL fashion) index
Returns:
the object at the specified index of the source collection
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of bounds

first

public static <E> E first(java.util.Collection<E> self)
Implementation of the OCL operations.

Parameters:
self - the source collection
Returns:
the first object of the source collection

last

public static <E> E last(java.util.Collection<E> self)
Implementation of the OCL operations.

Parameters:
self - the source collection
Returns:
the last object in the source collection

indexOf

public static <E> java.lang.Integer indexOf(java.util.Collection<? extends E> self,
                                            E object)
Implementation of the OCL operations.

Parameters:
self - the source collection
object - an object
Returns:
the index of the object in the source collection

createNewSet

public static <E> java.util.Set<E> createNewSet()
Creates a new OCL Set.


createNewSet

public static <E> java.util.Set<E> createNewSet(java.util.Collection<? extends E> c)
Creates a new OCL Set with initial contents supplied.


createNewBag

public static <E> Bag<E> createNewBag()
Creates a new OCL Bag.


createNewBag

public static <E> Bag<E> createNewBag(java.util.Collection<? extends E> c)
Creates a new OCL Bag with initial contents supplied.


createNewOrderedSet

public static <E> java.util.LinkedHashSet<E> createNewOrderedSet()
Creates a new OCL OrderedSet.


createNewOrderedSet

public static <E> java.util.LinkedHashSet<E> createNewOrderedSet(java.util.Collection<? extends E> c)
Creates a new OCL OrderedSet with initial contents supplied.


createNewSequence

public static <E> java.util.List<E> createNewSequence()
Creates a new OCL Sequence.


createNewSequence

public static <E> java.util.List<E> createNewSequence(java.util.Collection<? extends E> c)
Creates a new OCL Sequence with initial contents supplied.


createNewCollectionOfSameKind

public static <E> java.util.Collection<E> createNewCollectionOfSameKind(java.util.Collection<?> c)
Creates a new, empty OCL collection of the same kind as the specified prototype.

Parameters:
c - a collection
Returns:
a new, empty collection of the same kind as c

createNewCollection

public static <E> java.util.Collection<E> createNewCollection(java.util.Collection<? extends E> c)
Creates a new OCL collection of the same kind and contents as the specified prototype.

Parameters:
c - a collection
Returns:
a copy of c

createNewCollection

public static <E> java.util.Collection<E> createNewCollection(CollectionKind kind)
Creates a new OCL Collection of the specified kind.

Parameters:
kind - the OCL collection kind
Returns:
the new collection

createNewCollection

public static <E> java.util.Collection<E> createNewCollection(CollectionKind kind,
                                                              java.util.Collection<E> c)
Creates a new OCL Collection of the specified kind.

Parameters:
kind - the OCL collection kind
c - the contents of the new collection
Returns:
the new collection of the specified kind, containing the same elements as c

toString

public static java.lang.String toString(java.util.Collection<?> c)
Computes the string representation of a collection value using syntax like OCL's collection literals (e.g., OrderedSet{...}) instead of Java's default (i.e., [...]).

Parameters:
c - a collection (not null)
Returns:
the string representation of the specified collection
Since:
1.2