Declarative Objectivity (DO) Language : Operator Expressions : Type Evaluation Operators
Type Evaluation Operators
Type evaluation operators enable you to qualify and access objects based on their class.  
 
Operator
Description
Usage
First Operand
(op1)
Second Operand
(op2)
Result Type 1
See Also
CLASS_NAME
Returns class name of the embedded or referenced object.
CLASS_NAME(op1)
Embedded object, Reference
String or null if op1 is null.
CLASS_TYPE
Returns class of the embedded or referenced object.
CLASS_TYPE(op1)
Embedded object, Reference
Class type or null if op1 is null.
KIND_OF
IS_TYPE
IS
Returns true if the class of the referenced object is the specified class or a subclass of that type.
KIND_OF(op1, op2)
 
op1 KIND_OF op2
Reference
Class type
Boolean
Returns true if the class in op1 is the class in op2 or a subclass of that class.
KIND_OF(op1, op2)
 
op1 KIND_OF op2
Class type
Returns true if the current context object is of the specified class or a subclass of that class.
KIND_OF(op2)
ELEMENTS_OF_TYPE
Filters the collection or sequence of references to include only those that are of the specified class or a subclass of that class.
ELEMENTS_OF_TYPE(op1, op2)
 
op1 ELEMENTS_OF_TYPE op2
Collection or sequence of references
Class type
Sequence with element type the same as op1 2
AS_TYPE
AS
Casts the referenced object to the specified class.
AS_TYPE(op1, op2)
 
op1 AS_TYPE op2
Reference
Class type
Casted reference
ELEMENTS_AS_TYPE
Casts the collection of referenced objects to the specified class.
ELEMENTS_AS_TYPE(op1, op2)
 
op1 ELEMENTS_AS_TYPE op2
Collection or sequence of references
Class type
Sequence of casted reference3
1. Type evaluation operators return null if any operand is null.
2. ELEMENT_OF_TYPE sequence excludes any input element that is null or not of the specified class.
3. ELEMENT_AS_TYPE sequence includes a null reference for each input element that is null or not castable.
Quick Look 
Get the namespace-qualified class name of a referenced object:
FROM Vehicle RETURN CLASS_NAME(currentRental);
Get the tracking number of a rental contract whose first event is a reservation.
FROM RentalContract WHERE KIND_OF(events[0], :Reservation) RETURN trackingNumber;
Get the tracking number of a rental contract whose first event is a reservation with a dropoff that is earlier than a particular date and time.
FROM RentalContract WHERE AS_TYPE(events[0], :Reservation).dropoff < 2017-03-17 12:00:00 RETURN trackingNumber;
Discussion 
For general information about operator formats, operands, and precedence, see About Operator Expressions.
Note:The examples in the following subsections qualify RentalContract objects, which each have an events collection whose element type is RentalEvent. RentalEvent has two subclasses, Reservation and PickUp.
Getting the Name of an Object’s Class
The CLASS_NAME operator returns the name of an embedded or referenced object’s class. This operator returns the object’s namespace-qualified concrete class name, and not the name of the superclass if there is one.
The value returned by the CLASS_NAME operator is a string representation of the object’s class name. You can test the returned name by comparing it to another expression that returns a string, such as a string literal.
Example. The following statement tests for RentalContract objects whose first rental event is a referenced object of the class named 'FleetData.Reservation':
FROM RentalContract WHERE CLASS_NAME(events[0]) == 'FleetData.Reservation' RETURN trackingNumber;
Getting an Object’s Class
The CLASS_TYPE operator returns the class of an embedded or referenced object. This operator returns the object’s namespace-qualified concrete class, and not the superclass if there is one.
The value returned by the CLASS_TYPE operator is a representation of the entire class. You can compare the returned value to another expression that returns a class-type value, such as a class literal. Or, you can use the returned value in an enclosing expression whose operator accepts a class-type operand.
Example. The following statement tests for RentalContract objects whose first rental event is a referenced object of the FleetData.Reservation class:
FROM RentalContract WHERE CLASS_TYPE(events[0]) == :FleetData.Reservation RETURN trackingNumber;
Testing an Object’s Class
The KIND_OF operators test whether a referenced object is a kind of the specified class. The operators return true for an object that is an instance of the specified class itself or a subclass of that class. The class of interest may specified using a class literal or a CLASS_TYPE expression.
Example. The following statement tests for RentalContract objects whose first rental event is a referenced object of the Reservation class (or a subclass of that class, if there is one).
FROM RentalContract WHERE KIND_OF(events[0]), :Reservation) RETURN trackingNumber;
The KIND_OF operators also accept a single argument to test whether the current context object is a kind of a given class. The current object can be one element in a collection or sequence.
Filtering Collected Objects By Class
The ELEMENTS_OF_TYPE operator filters a collection of referenced objects of multiple different classes, and returns a sequence that includes only those elements that are of the specified kind of class (either the specified class itself or a subclass of that class). The class of interest may specified using a class literal or a CLASS_TYPE expression.
If any of the elements in the input referenced collection are null references, they are excluded from the resulting sequence.
Example. The following statement tests for RentalContract objects whose collection of rental events includes exactly three referenced objects of the Reservation class:
FROM RentalContract WHERE COUNT(ELEMENTS_OF_TYPE(events, :Reservation))== 3 RETURN trackingNumber;
Casting Objects
The AS_TYPE operators let you cast a referenced object to a specified class, typically for purposes of obtaining access to attributes of the casted objects in an enclosing expression. The referenced object is castable if it is not null and is of the specified kind of class (either the specified class itself or a subclass of that class). The class of interest may specified using a class literal or a CLASS_TYPE expression.
The AS_TYPE operators return null if the referenced object is not castable.
Example. The following statement tests for RentalContract objects whose first rental event is a Reservation object with a dropoff attribute that is earlier than a given date and time.
FROM RentalContract WHERE AS_TYPE(events[0], :Reservation).dropoff < 2017-03-17 12:00:00 RETURN trackingNumber;
Casting Collected Objects
The ELEMENTS_AS_TYPE operators let you cast a collection of referenced objects to a specified class, typically for purposes of obtaining access to attributes of the casted objects in an enclosing expression. A referenced object is castable if it is not null and it is of the specified kind of class (either the specified class itself or a subclass of that class). The class of interest may specified using a class literal or a CLASS_TYPE expression.
The ELEMENTS_AS_TYPE operator returns a sequence of references of the casted type. The returned collection includes a null reference for any element in the input collection that is either null or not castable.
Example. The following statement tests for RentalContract objects whose collection of rental events includes at least one referenced PickUp object that is associated with a particular Stall. Any Reservation objects in the collection are ignored.
FROM RentalContract WHERE ANY_EQUAL(ELEMENTS_AS_TYPE(events, :PickUp).atStall, 3-3-1-45) RETURN trackingNumber;