Skip to main content

setNodeComparator

Short summary

Sets a comparator, that is used to compare two nodes of this tree. Optional, if not set, object.compareTo will be used.

Attention: The comparator can only be set if the tree has at most one element.

Attention: Will be deep destructed within the deep destruct context of this class.

Return: SUCCESS: new comparator was set ABORTED: tree already contained more than one object

Parameters

NameTypeCommentKind
nodeComparatorCNM_AbstractObject.IComparatorthe comparator that should be used to compare two nodesinput

Code

Declaration

METHOD setNodeComparator :CNM_ReturnTypes.SingleExecutionResult
VAR_INPUT
(*the comparator that should be used to compare two nodes*)
nodeComparator :CNM_AbstractObject.IComparator;
END_VAR
VAR CONSTANT
MAXIMUM_SIZE_TO_SET_COMPARATOR :UDINT := 1;
END_VAR

Implementation

IF THIS^.size > MAXIMUM_SIZE_TO_SET_COMPARATOR THEN
setNodeComparator := CNM_ReturnTypes.SingleExecutionResult.ABORTED;
ELSE
THIS^.nodeComparator := nodeComparator;
setNodeComparator := CNM_ReturnTypes.SingleExecutionResult.SUCCESS;
END_IF