containsObject
Short summary
This method checks if a given object is contained in the collection. Overwrite default implementation to use the advantages of balanced trees
Return: FALSE: list does not contain given object
TRUE: list does contain given object
- Return type:
BOOL
Parameters
| Name | Type | Comment | Kind |
|---|---|---|---|
| object | CNM_AbstractObject.IObject | the object to be checked if it exists inside the collection | input |
Code
Declaration
METHOD containsObject :BOOL
VAR_INPUT
(*the object to be checked if it exists inside the collection*)
object :CNM_AbstractObject.IObject;
END_VAR
VAR
currentElement :CNM_CollectionInterfaces.IBinaryTreeNode;
END_VAR
Implementation
currentElement := THIS^.rootnode;
IF THIS^.isObjectNull(currentElement) OR THIS^.isObjectNull(object) THEN
containsObject := FALSE;
RETURN;
END_IF
containsObject := object.isEqual(currentElement.object);
WHILE NOT containsObject DO
CASE THIS^.compareNodes(object,currentelement.object) OF
CNM_ReturnTypes.ComparationResult.GREATER:
IF THIS^.isObjectValid(currentElement.rightChild) THEN
currentElement := currentElement.rightChild;
ELSE
RETURN;
END_IF
CNM_ReturnTypes.ComparationResult.SMALLER:
IF THIS^.isObjectValid(currentElement.leftChild) THEN
currentElement := currentElement.leftChild;
ELSE
RETURN;
END_IF
ELSE
// if reached, the node comparator founds both objects equal but object.isEqual not
RETURN;
END_CASE
containsObject := object.isEqual(currentElement.object);
END_WHILE