Skip to main content

getEqualObject

Short summary

Searches an Object, that is equal to the provided object in terms of the compareTo Method (or an provided comparator from the parentstructure). Does not care about equal or not equal hashcodes.

Return: True when an object that is equal is found, false else

  • Return type: BOOL

Parameters

NameTypeCommentKind
objectCNM_AbstractObject.IObjectThe object for that an aquvivelent is searchedinput
foundObjectCNM_AbstractObject.IObjectThe found object or null if not foundoutput

Code

Declaration

METHOD INTERNAL getEqualObject :BOOL
VAR_INPUT
(*The object for that an aquvivelent is searched*)
object :CNM_AbstractObject.IObject;
END_VAR
VAR_OUTPUT
(*The found object or null if not found*)
foundObject :CNM_AbstractObject.IObject;
END_VAR
VAR
currentNode :CNM_CollectionInterfaces.IBinaryTreeNode;
END_VAR
VAR CONSTANT
OBJECT_NOT_REFERENCED :__XWORD := 0;
END_VAR

Implementation

currentNode := THIS^.rootNode;
getEqualObject := FALSE;
foundObject := OBJECT_NOT_REFERENCED;

IF THIS^.isObjectNull(currentNode) OR_ELSE THIS^.isObjectNull(object) THEN
getEqualObject := FALSE;
RETURN;
END_IF
WHILE THIS^.isObjectValid(currentNode) DO
CASE THIS^.compareNodes(object1 := object, object2 := currentNode.object) OF
CNM_ReturnTypes.ComparationResult.EQUAL:
foundObject := currentNode.object;
getEqualObject := TRUE;
RETURN;
CNM_ReturnTypes.ComparationResult.SMALLER:
currentNode := currentNode.leftChild;
CNM_ReturnTypes.ComparationResult.GREATER:
currentNode := currentNode.rightChild;
END_CASE
END_WHILE