Home » Data model (DataTypes) » CollectionTypes

CollectionTypes

  • CollectionTypes are based on the Java Collection class.
  • Like Java, we can also make collections of types in SAP Commerce Cloud.
  • Types can be ItemTypes, AtomicType, etc.

Syntax :

1.Collection of AtomicType:

<collectiontype code=”StringCollection” elementtype=”java.lang.String” autocreate=”true” generate=”false”/>

2.Collection of Itemtype:

<collectiontype code=”OrderCollection” elementtype=”Order” autocreate=”true” generate=”false”/>

collectiontype

Exaplanation:

A CollectionType has a unique identifier (referred to as code) and a definition of the type of elements it contains (elementtype). This type definition may include any type of item within the SAP Commerce Cloud – even other CollectionTypes.

elementtype defines the type of items that will be stored in a CollectionType.
It is impossible to store any other type of items in the same CollectionType.

In the example code snippet, the StringCollection type is restricted to String type items only. The SAP Commerce Cloud blocks any attempt of storing, for example, Integer values into a StringCollection instance.

In the example code snippet, the OrderCollection type is restricted to Order type items only. The SAP Commerce Cloud blocks any attempt of storing, for example, String  values into a OrderCollection instance.

collectiontype1