bildwelt
E2E FORUM
E2E Bridge E2E Commerce

Reply To: array tips and tricks

E2E Forum Modeling & Development array tips and tricks Reply To: array tips and tricks

#2922

Kirstin
Keymaster

A very interesting discussion, indeed. I made an example model and tried out the operations mentioned in this thread.
Find below a recap of what exactly the operations do in array context:

Empty Array

set array = select each from array where false;

A new array is created containing all references to elements of array that correspond to the condition (which are none). The reference of array is changed to point to the new array.

What the modeler sees: array is empty now. You can append items using the append statement.

set array = NULL;

The reference of array is changed to point to nowhere.
What the modeler sees: A non-existent array. You can append items using the append statement, the array will implicitly be created, then.

Caution: Arrays within arrays
Let’s assume you have an array of complex type ArrayElement and this complex type has a property subArray with multiplicity 0..*.

  • What you can do, if subArray is NULL:
    set array1[0].subArray = anotherArray;
    The reference subArray is changed to point to anotherArray.

  • What you can’t do, if subArray is NULL:
    append "something" to array1[0].subArray;
    In this case (get statement on the right side of a statement), the Runtime will throw a get error for array1[0].subArray.


Copy Array Content

set array2 = select each from array1 where true;

A new array is created containing all references to elements of array1 that correspond to the condition (which are all). The reference array2 is changed to point to the new array.

What the modeler sees: Two arrays array1 and array2 that contain the same element references. A change to array1 itself will not change array2 (e.g. appending elements), but a change to an element of array1 will change that very same element in array2.
set array2 = array1.copy();

A new array is created that contains a true deep copy of all elements of array1. The reference array2 is changed to point to the new array.
What the modeler sees: Two arrays array1 and array2 that are completely independent. A change to array1 in any way will not change array2.


Appending
Arrays

set array2 = array2.concatArrays(array1)

A new array is created containing all references to elements of array1 and array2. The reference array2 is changed to point to the new array.

What the modeler sees: An array array2 containing all element references of array1 and array2. A change to array1 itself will not change array2 (e.g. appending elements), but a change to an element of array1 will change that very same element in array2.