Skip to main content

andThen

Short summary​

Method to concat actions perfomed on an object. This way two (or more) Actions can be performed on data with one foreach. All concatinated appliers can be cleared with THIS^.clear(); Example: You want to double your numbers and then increment them, you would write:

ConcreteDoubleApplier.andThen(ConcreteIncrementApplier);

If you have a list with 1 2 3, after a forEach with this Applier the list will be transformed to: 3 5 7.

Warning: It is possible to create infinite loops using andThen. For example: A1.andThen(A2).andThen(A1) The program will go into unknown behaviour if this occurs and the foreach call may or may not work as you intended.

Return: THIS^ IApplier

Parameters​

NameTypeCommentKind
applierCNM_CollectionInterfaces.IApplierthe applier to be used on each objectinput

Code​

Declaration​

METHOD FINAL andThen :CNM_CollectionInterfaces.IChainedApplier
VAR_INPUT
(*the applier to be used on each object*)
applier :CNM_CollectionInterfaces.IApplier;
END_VAR
VAR
chained :CNM_CollectionInterfaces.IChainedApplier;
clonedActions :CNM_CollectionInterfaces.ICollection;
cloneObj :CNM_AbstractObject.IObject;
pList :POINTER TO ApplierList;
END_VAR

Implementation​

IF(THIS^.isObjectValid(applier) AND_THEN THIS^.isObjectValid(THIS^.myactions))THEN
IF __QUERYINTERFACE(applier, chained) THEN
IF (chained.actions.count > 1) THEN
IF(NOT THIS^.isEqual(applier))THEN
__QUERYPOINTER(chained.actions, pList);
THIS^.myactions.addAppliers(pList^.list);
ELSE
IF(THIS^.myactions.list.clone(clonedObject => cloneObj) = CNM_ReturnTypes.CloneResult.SUCCESS)THEN
IF( __QUERYINTERFACE(cloneObj, clonedActions))THEN
THIS^.myactions.addAppliers(clonedActions);
END_IF
clonedActions.destruct();
END_IF
END_IF
END_IF
ELSE
THIS^.myactions.addApplier(applier);
END_IF
END_IF

andThen := THIS^;