de.tuberlin.cs.cis.ocl.eval.instance
Class CollectionInstance

java.lang.Object
  |
  +--de.tuberlin.cs.cis.ocl.eval.instance.PredefinedInstance
        |
        +--de.tuberlin.cs.cis.ocl.eval.instance.CollectionInstance
All Implemented Interfaces:
java.lang.Cloneable, Instance, OclCollection
Direct Known Subclasses:
BagInstance, SequenceInstance, SetInstance

public class CollectionInstance
extends PredefinedInstance
implements OclCollection, java.lang.Cloneable

Represents an instance of the OCL type Collection.

Author:
fchabar

Constructor Summary
CollectionInstance(Type type, java.util.Collection representation)
          Constructs an instance of the OCL type Collection via a Java Collection.
 
Method Summary
 java.lang.Object any(OclExpression expr)
          Returns any element in this collection for which expr evaluates to True.
 java.lang.Object clone()
           
static java.util.Collection collectionValue(OclCollection c2)
          Determines the Java Collection representation of an OclCollection value.
 OclInteger count(OclAny object)
          The number of times that object occurs in this collection.
 boolean equals(java.lang.Object o)
           
 OclBoolean excludes(OclAny object)
          True if object is not an element of collection, False otherwise.
 OclBoolean excludesAll(OclCollection c2)
          Does this collection contains none of the elements of c2 ?
 OclBoolean exists(OclExpression expr)
          Results in True if expr evaluates to True for at least one element in this collection.
 OclBoolean forAll(OclExpression expr)
          Results in True if expr evaluates to True for each element in this collection; otherwise, result is False.
 Type getElementType()
          Returns the element type of this collection's runtime type.
 OclBoolean includes(OclAny object)
          Results in True if object is an element of this collection, False otherwise.
 OclBoolean includesAll(OclCollection c2)
          Does this collection contains all the elements of c2 ?
 OclBoolean isEmpty()
          Is this collection the empty collection?
 OclBoolean isUnique(OclExpression expr)
          Results in True if expr evaluates to a different value for each element in this collection; otherwise, result is False.
 java.lang.Object iterate(OclExpression expr)
          Iterates over the collection.
 OclBoolean notEmpty()
          Is this collection not the empty collection?
 OclBoolean one(OclExpression expr)
          Results in True if there is exactly one element in this collection for which expr is True.
 OclInteger size()
          Results in the number of elements in this collection.
 OclSequence sortedBy(OclExpression expression)
          Results in the Sequence containing all elements of this collection.
 java.lang.Object sum()
          The addition of all elements in this collection.
 java.lang.String toString()
           
 
Methods inherited from class de.tuberlin.cs.cis.ocl.eval.instance.PredefinedInstance
getRepresentation, getRuntimeType, getValue, hashCode, invoke, navigate
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CollectionInstance

public CollectionInstance(Type type,
                          java.util.Collection representation)
Constructs an instance of the OCL type Collection via a Java Collection. The OCL runtime type can be either specified by an element type, then the actual type is Collection(element type), or by a collection type.

Parameters:
type - the type of the collection. It is either the element type of the collection or the collection type itself.
representation - the Java Collection representation of this OCL collection.
Method Detail

collectionValue

public static java.util.Collection collectionValue(OclCollection c2)
Determines the Java Collection representation of an OclCollection value.

Parameters:
c2 - an OclCollection value
Returns:
the Java Collection representation of the specified OCL collection.

any

public java.lang.Object any(OclExpression expr)
Description copied from interface: OclCollection
Returns any element in this collection for which expr evaluates to True. If there is more than one element for which expr is True, one of them is returned. The precondition states that there must be at least one element fulfilling expr; otherwise, the result of this operation is Undefined. pre: self->exists( expr )

Specified by:
any in interface OclCollection
Parameters:
expr - an instance of OclExpression (!= null)
Returns:
any element in this collection for which expr evaluates to True.

count

public OclInteger count(OclAny object)
Description copied from interface: OclCollection
The number of times that object occurs in this collection.

Specified by:
count in interface OclCollection
Parameters:
object - an instance of OclAny (!= null)
Returns:
The number of times that object occurs in this collection.

excludes

public OclBoolean excludes(OclAny object)
Description copied from interface: OclCollection
True if object is not an element of collection, False otherwise.

Specified by:
excludes in interface OclCollection
Parameters:
object - an instance of OclAny (!= null)
Returns:
True if object is not an element of collection, False otherwise.

excludesAll

public OclBoolean excludesAll(OclCollection c2)
Description copied from interface: OclCollection
Does this collection contains none of the elements of c2 ?

Specified by:
excludesAll in interface OclCollection
Parameters:
c2 -
Returns:
True if this collection contains none of the elements of c2, False otherwise.

exists

public OclBoolean exists(OclExpression expr)
Description copied from interface: OclCollection
Results in True if expr evaluates to True for at least one element in this collection.

Specified by:
exists in interface OclCollection
Parameters:
expr - an instance of OclExpression (!= null)
Returns:
True if expr evaluates to True for at least one element in this collection, False otherwise.

forAll

public OclBoolean forAll(OclExpression expr)
Description copied from interface: OclCollection
Results in True if expr evaluates to True for each element in this collection; otherwise, result is False.

Specified by:
forAll in interface OclCollection
Parameters:
expr - an instance of OclExpression (!= null)
Returns:
True if expr evaluates to True for each element in this collection; False otherwise.

includes

public OclBoolean includes(OclAny object)
Description copied from interface: OclCollection
Results in True if object is an element of this collection, False otherwise.

Specified by:
includes in interface OclCollection
Parameters:
object - an instance of OclAny (!= null)
Returns:
True if object is an element of this collection, False otherwise.

includesAll

public OclBoolean includesAll(OclCollection c2)
Description copied from interface: OclCollection
Does this collection contains all the elements of c2 ?

Specified by:
includesAll in interface OclCollection
Parameters:
c2 -
Returns:
True if this collection contains all the elements of c2, False otherwise.

isEmpty

public OclBoolean isEmpty()
Description copied from interface: OclCollection
Is this collection the empty collection?

Specified by:
isEmpty in interface OclCollection
Returns:
True if this collection is the empty collection, False otherwise.

isUnique

public OclBoolean isUnique(OclExpression expr)
Description copied from interface: OclCollection
Results in True if expr evaluates to a different value for each element in this collection; otherwise, result is False.

Specified by:
isUnique in interface OclCollection
Parameters:
expr - an instance of OclExpression (!= null)
Returns:
True if expr evaluates to a different value for each element in this collection; False otherwise.

iterate

public java.lang.Object iterate(OclExpression expr)
Deprecated. iterations will be implemented in EvaluationAnalzyer

Description copied from interface: OclCollection
Iterates over the collection.

Note: it is not neseccary to implement this method. It will soley be used for reflection purposes in the type system.

Specified by:
iterate in interface OclCollection
Parameters:
expr - an instance of OclExpression (!= null)
Returns:
the iteration over this collection.

notEmpty

public OclBoolean notEmpty()
Description copied from interface: OclCollection
Is this collection not the empty collection?

Specified by:
notEmpty in interface OclCollection
Returns:
True if this is not the empty collection, False otherwise.

size

public OclInteger size()
Description copied from interface: OclCollection
Results in the number of elements in this collection.

Specified by:
size in interface OclCollection
Returns:
the number of elements in this collection.

sortedBy

public OclSequence sortedBy(OclExpression expression)
Description copied from interface: OclCollection
Results in the Sequence containing all elements of this collection. The element for which expr has the lowest value comes first, and so on. The type of the expr 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). pre: expr.evaluationType().operations()->includes(‘<‘)

Specified by:
sortedBy in interface OclCollection
Parameters:
expression - an instance of OclExpression (!= null)
Returns:
the Sequence containing all elements of this collection

sum

public java.lang.Object sum()
Description copied from interface: OclCollection
The addition of all elements in this collection. Elements must be of a type supporting the '+' operation. The '+' operation must take one parameter of type T and be both associative: (a+b)+c = a+(b+c), and commutative: a+b = b+a. Integer and Real fulfill this condition.

Specified by:
sum in interface OclCollection
Returns:
the addition of all elements in this collection.

one

public OclBoolean one(OclExpression expr)
Description copied from interface: OclCollection
Results in True if there is exactly one element in this collection for which expr is True.

Specified by:
one in interface OclCollection
Parameters:
expr - an instance of OclExpression (!= null)
Returns:
True if there is exactly one element in this collection for which expr is True.

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class PredefinedInstance

getElementType

public Type getElementType()
Returns the element type of this collection's runtime type.

Returns:
the element type of this collection's runtime type.

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object