Start page
Start page

Start page / Template development / Template syntax / Data types / Set

Set data type Available from FirstSpirit Version 4.0

Value range of the Set data type

Elements of the template development can be grouped in:

FirstSpirit provides the data type Set for the processing/editing of values which represent an ordered set of unique elements. This data type enables a grouping of elements. Set objects are very flexible and can be extended as required.

Unlike the data types List and Map, an element within a set cannot be accessed via an index value or a key value. It is only possible to output the first, the last, all elements or a specific element of a set. If a specific element of the set is to be output, this element must be known. Unlike a list, for example, it is not possible to simply access the second element in the set. Instead, it is necessary to check whether a specific element is contained within the set; only then can this element be accessed. For this reason, elements may only exist within a set precisely once; i.e. an expression of the form: mapElement_1.equals(mapElement_2) can never return true.

The data type Set can also be looked up in the Sun API documentation:

java.util.Set

Definition

Analogous to maps, sets can also be generated via { } (curlybrackets/braces). The following syntax must be fulfilled:

SET := '{} | '{' [ EXPRESSION [',' EXPRESSION ]*] '}'

The following code example generates an empty set and assigns it to the variables "empty_set":

  $CMS_SET(empty_set, {})$

If a set is to be generated which already contains elements, the elements can be simply passed as a comma-separated list within the curly brackets. The code example generates a new, filled set "mySet":

$CMS_SET(mySet, {"one","two","three"})$

In the following code example an element is added to the set:

$CMS_VALUE(mySet.add("four"))$

Definition using the standard input components

Within the <CMS_INPUT_LIST> tags in the form area of a page or section template, input components are defined which can be subsequently used by the editors to insert the actual editorial contents into the page. The standard input components supported by FirstSpirit return different data types.

The following standard input components return an object of data type "Set":

Then, with the help of a $CMS_VALUE(...)$ instruction, methods can be applied to this object:

$CMS_VALUE(IDENTIFIER.METHOD)$

The IDENTIFIER is the identifier defined in the resultname parameter of the input component.

Access to elements in the set

The elements in the set are accessed, for example, via an iteration:

$CMS_FOR(setWrapper,mySet)$
$CMS_VALUE(setWrapper)$
$CMS_END_FOR$
Output:
setWrapper:three
setWrapper:one
setWrapper:four
setWrapper:two

or via functions:

 $CMS_VALUE(mySet.first())$
 $CMS_VALUE(mySet.last())$

The code example returns the first or the last value of the set.

In addition, the following expression is also possible:

$CMS_VALUE(mySet.contains("one"))$

The contains method checks whether a specific element is a component of the set and returns true for the code example given above.

Methods on set objects

The table below lists all methods which can be invoked on objects of data type "Set":

The object is generated by the following form objects:
CMS_INPUT_CHECKBOX
CMS_INPUT_LIST
Method name Return type Brief description Available since
add(Object) boolean
addAll(Collection) boolean
clear void
compareTo(Comparable) int
contains(Object) boolean checks if the provided element is contained 4.0.0
containsAll(Collection) boolean
copy Collection make a (shallow) copy 4.0.0
distinct(Lambda) Collection Output of a list of unique elements 4.1
equals(Object) boolean
filter(String) Object delivers a filtered collection, the last parameter converted to a lambda expression 4.0.0
filter(Lambda) Object Filtering of list elements 4.0.0
fold(Lambda, Map) Object Summarizing values 4.0.0
getClass Class Class of the invoking object
hashCode int
isCase(Object) boolean
isEmpty boolean Checks whether an expression is empty
isNull boolean Checks whether an expression is null (zero)
iterator Iterator
length int
map(String) Object delivers a mapped collection, the last parameter converted to a lambda expression 4.0.0
map(Lambda) Object Output of list elements as collection 4.0.0
max Object delivers the maximum element (only applicable if elements are compareable) 4.0.0
max(Comparator) Object delivers the maximum element concerning to the given comparator 4.0.0
max(Lambda) Object Filtering by the highest value 4.0.0
min Object delivers the minimum element (only applicable if elements are compareable) 4.0.0
min(Comparator) Object delivers the minimum element concerning to the given comparator 4.0.0
min(Lambda) Object Filtering by the lowest value 4.0.0
plus(Collection) Collection appends all elements to this collection (called for operator '+') 4.0.0
print void
print(Object) void
remove(Object) boolean
removeAll(Collection) boolean
retainAll(Collection) boolean
set(String, Object) Object
size int
toArray Object[]
toArray(Object[]) Object[]
toJson String Convert to JSON string representtion (only handles Maps, Collections, Arrays, Numbers, and Strings) 4.2.14
toString String
toString(String) String Output of elements separated by delimiters as a string 4.0.0
toString(String, String) String Short form for collection.map(attribute).toString(delimiter) 4.0.0
type String

add(Object)

Method name Return type Available since
add(Object) boolean

addAll(Collection)

Method name Return type Available since
addAll(Collection) boolean

clear

Method name Return type Available since
clear void

compareTo(Comparable)

Method name Return type Available since
compareTo(Comparable) int

contains(Object)

checks if the provided element is contained
Method name Return type Available since
contains(Object) boolean 4.0.0

containsAll(Collection)

Method name Return type Available since
containsAll(Collection) boolean

copy

make a (shallow) copy
Method name Return type Available since
copy Collection 4.0.0

distinct(Lambda)

This method filters a collection and returns only the first occurrence relating to a lambda expression.

It can be used to eliminate or ignore duplicates of a list according to a given condition. For this reason, it can be used for glossaries or summaries, which can then serve linked, for example, as navigational element.

See page Mapping expressions (lambda).

Method name Return type Available since
distinct(Lambda) Collection 4.1

equals(Object)

Method name Return type Available since
equals(Object) boolean

filter(String)

delivers a filtered collection, the last parameter converted to a lambda expression
Method name Return type Available since
filter(String) Object 4.0.0

filter(Lambda)

If lists have several attributes per element (comparable with a dataset with several columns), the elements can be filtered by the individual attributes using the method .filter(Lambda).

See page Mapping expressions (lambda).

Method name Return type Available since
filter(Lambda) Object 4.0.0

fold(Lambda, Map)

This method folds the collection with the given lambda expression and start value.

See page Mapping expressions (lambda).

Method name Return type Available since
fold(Lambda, Map) Object 4.0.0

getClass

The .getClass() (in Bean syntax: .class) method returns the class of the invoking object (cf. java.lang.Class).

Invocation:

$CMS_VALUE(myString.class)$
$CMS_VALUE(myString.getClass())$

Output:

java.lang.String
Method name Return type Available since
getClass Class

hashCode

Method name Return type Available since
hashCode int

isCase(Object)

Method name Return type Available since
isCase(Object) boolean

isEmpty

The .isEmpty() (in Bean syntax: .isEmpty) method checks whether an expression or object is empty, e.g. storeElement.isEmpty(). The result of the semantic check depends on the expression or object, e.g. a character string is empty if it does not contain any characters. In the case of objects with complex values or objects, the object decides when it is empty. The data type DomElement for example always contains an empty document, thus it is never null. For this reason, checking an empty DOM editor input component by using the method .isNull()returns the value false, whereas checking the component with .isEmpty() would return the value true.

The method .isEmpty() returns a Boolean value as the check result. true is the check result if the expression or object is empty and false if not.

Method name Return type Available since
isEmpty boolean

isNull

The .isNull() (in Bean syntax: .isNull) method checks whether an expression or object is null , e.g. storeElement.isNull(). In the case of objects with complex values or objects, the object decides when it is null. The data type DomElement for example always contains an empty document, thus it is never null. For this reason, checking an empty DOM editor input component by using the method .isNull() returns the value false, whereas checking the component with .isEmpty() would return the value true.

The method .isNull() returns a Boolean value as the check result. true is the check result if the expression or object is null and false if not.

Method name Return type Available since
isNull boolean

iterator

Method name Return type Available since
iterator Iterator

length

Method name Return type Available since
length int

map(String)

delivers a mapped collection, the last parameter converted to a lambda expression
Method name Return type Available since
map(String) Object 4.0.0

map(Lambda)

See page Mapping expressions (lambda).

Method name Return type Available since
map(Lambda) Object 4.0.0

max

delivers the maximum element (only applicable if elements are compareable)
Method name Return type Available since
max Object 4.0.0

max(Comparator)

delivers the maximum element concerning to the given comparator
Method name Return type Available since
max(Comparator) Object 4.0.0

max(Lambda)

This method delivers the maximum element concerning to the given comparator.

See page Mapping expressions (lambda).

Method name Return type Available since
max(Lambda) Object 4.0.0

min

delivers the minimum element (only applicable if elements are compareable)
Method name Return type Available since
min Object 4.0.0

min(Comparator)

delivers the minimum element concerning to the given comparator
Method name Return type Available since
min(Comparator) Object 4.0.0

min(Lambda)

This method delivers the minimum element concerning to the given comparator.

See page Mapping expressions (lambda).

Method name Return type Available since
min(Lambda) Object 4.0.0

plus(Collection)

appends all elements to this collection (called for operator '+')
Method name Return type Available since
plus(Collection) Collection 4.0.0

print

Method name Return type Available since
print void

print(Object)

Method name Return type Available since
print(Object) void

remove(Object)

Method name Return type Available since
remove(Object) boolean

removeAll(Collection)

Method name Return type Available since
removeAll(Collection) boolean

retainAll(Collection)

Method name Return type Available since
retainAll(Collection) boolean

set(String, Object)

Method name Return type Available since
set(String, Object) Object

size

Method name Return type Available since
size int

toArray

Method name Return type Available since
toArray Object[]

toArray(Object[])

Method name Return type Available since
toArray(Object[]) Object[]

toJson

Convert to JSON string representtion (only handles Maps, Collections, Arrays, Numbers, and Strings)
Method name Return type Available since
toJson String 4.2.14

toString

Method name Return type Available since
toString String

toString(String)

The individual elements, e.g. of a list, can be output as string, separated by a delimiter which can be chosen freely.

Example:

$CMS_SET(myList, ["House","Key","Window"])$
$CMS_VALUE(myList.toString("; "))$

The elements of the list myList are output, separated each by semicolon and a space character:

House; Key; Window
Method name Return type Available since
toString(String) String 4.0.0

toString(String, String)

Short form for collection.map(attribute).toString(delimiter)
Method name Return type Available since
toString(String, String) String 4.0.0

type

Method name Return type Available since
type String

To obtain an object of the set, an entry must be directly addressed with get() or the whole set object must be run through with the CMS_FOR or CMS_RENDER function.

Example:

$CMS_SET(myVariable,"TEXT")$

$CMS_SET(myVariable,1234)$

© 2005 - 2015 e-Spirit AG | All rights reserved. | Last change: 2013-11-13