$fn

( documentation for Telosys generator version 3.3.0 )


Object providing a set of utility functions


Since : 2.0.3

Attributes and methods
.argumentsList(List fields) : String

Returns a string containing a list of field names separated by a comma

Parameters :
   fields : list of fields to be added in the arguments list

Example :
   $fn.argumentsList( $entity.attributes )
   Returns : 'id, firstName, lastName, age'

Since : 2.0.5

.argumentsListWithGetter(String object, List fields) : String

Returns a string containing a list of fields getters separated by a comma

Parameters :
   object : name of the object providing the getters
   fields : list of fields to be added in the arguments list

Example :
   $fn.argumentsListWithGetter( 'person', $entity.attributes )
   Returns : 'person.getId(), person.getFirstName(), person.getLastName(), person.getAge()'

Since : 2.0.5

.argumentsListWithType(List fields) : String

Returns a string containing a list of fields (type and name) separated by a comma

Parameters :
   fields : list of fields to be added in the arguments list

Example :
   $fn.argumentsListWithType( $entity.attributes )
   Result example for Java language : 'int id, String firstName, String lastName, int age'
   Result example for Go language : 'id int32, firstName string, lastName string, age uint'

Since : 2.0.5

.argumentsListWithWrapperType(List fields) : String

Returns a string containing a list of fields (wrapper type and name) separated by a comma

Parameters :
   fields : list of fields to be added in the arguments list

Example :
   $fn.argumentsListWithWrapperType( $entity.attributes )
   Returns : 'Integer id, String firstName, String lastName, Integer age'

Since : 3.0.0

.backslash(String s, String c) : String

Protects each occurrence of the given char with a backslash in the given string

Parameters :
   s : the string to be processed
   c : the character to be protected with a backslash

.buildIntValues(Collection collection) : List

Builds a list of N integer consecutive values starting with 1

Parameters :
   collection : the collection determining the number of values (collection size)

Example :
   #set ( $values = $fn.buildIntValues($entity.attributes) )
   Values size = $values.size()
   #foreach( $v in $values )
    . value = $v
   #end
   #set($last = ( $values.size() - 1) )
   #foreach ( $i in [0..$last] )
    . value($i) = $values.get($i)
   #end

Since : 3.0.0

.buildIntValues(Collection collection, int int) : List

Builds a list of N integer consecutive values starting with the given value

Parameters :
   collection : the collection determining the number of values (collection size)
   int : the first value of the list

Example :
   #set ( $values = $fn.buildIntValues($entity.attributes, 0) )
   Values size = $values.size()
   #foreach( $v in $values )
    . value = $v
   #end
   #set($last = ( $values.size() - 1) )
   #foreach ( $i in [0..$last] )
    . value($i) = $values.get($i)
   #end

Since : 3.0.0

.buildIntValues(int int) : List

Builds a list of N integer consecutive values starting with 1

Parameters :
   int : the number of values to be created

Example :
   #set ( $values = $fn.buildIntValues(5) ) ## 5 values from 1 to 5
   Values size = $values.size()
   #foreach( $v in $values )
    . value = $v
   #end
   #set($last = ( $values.size() - 1) )
   #foreach ( $i in [0..$last] )
    . value($i) = $values.get($i)
   #end

Since : 3.0.0

.buildIntValues(int int, int int) : List

Builds a list of N integer consecutive values starting with the given value

Parameters :
   int : the number of values to be created
   int : the first value of the list

Example :
   #set ( $values = $fn.buildIntValues(10,0) ) ## 10 values from 0 to 9
   Values size = $values.size()
   #foreach( $v in $values )
    . value = $v
   #end
   #set($last = ( $values.size() - 1) )
   #foreach ( $i in [0..$last] )
    . value($i) = $values.get($i)
   #end

Since : 3.0.0

.buildValues(List attributes, int step) : ValuesInContext

Builds a list of literal values.
Returns a list with one literal value for each attribute according with the attribute type.
e.g. : 12 for an integer, true for a boolean, 230L for a long, 'ABC' for a string, etc
Each value can be retrieved by its attribute's name, e.g. $values.getValue($attribute.name)
A list of all values separated by a comma is returned by $values.allValues
Those values are typically used to populate attributes in test cases

Parameters :
   attributes : list of attributes requiring a literal value
   step : a step (from 1 to N) used to change the values builded

Example :
   #set( $values = $fn.buildValues($entity.attributes, 1) )
   #foreach( $attribute in $entity.attributes )
    Literal value for $attribute.name : $values.getValue($attribute.name)
   #end
    All values : $values.allValues

Since : 2.1.1

.capitalize(String string) : String

Capitalizes the given string
changing the first letter to upper case

Parameters :
   string : the string to be capitalized

Example :
   $fn.capitalize($var)

Since : 2.1.0

.className(Object object) : String

Returns the class name (CanonicalName) for the given object (or 'null' if undefined)

Parameters :
   object : object reference for which to get the class name

Example :
   $fn.className($var)

Since : 3.3.0

.concatLists(List list1, List list2) : List

Concatenates 2 lists ( add all the elements of the second list at the end of the first one )
The 2 given lists remain unchanged. The result is stored in a new list.

Parameters :
   list1 : List of objects
   list2 : List of objects to be added at the end of list1

Example :
   #set ( $list3 = $fn.concatLists( $list1, $list2 )

Since : 2.0.7

.escapeXml(String s) : String

Returns the XML string for the given string
Replaces special characters (&, <, >, etc) by their corresponding XML notation

Parameters :
   s : the string to be escaped

.file(String filePath) : FileInContext

Returns a file object for the given file path

Parameters :
   filePath : the file path (relative or absolute)

Example :
   ## relative path : for a file located in the current project :
   #set( $file = $fn.file('myfile.csv') )
   #set( $file = $fn.file('dir/foo.txt') )
   ## absolute path : for a file located anywhere :
   #set( $file = $fn.file('C:\Temp\values.csv') )
   #set( $file = $fn.file('/tmp/values.csv') )

Since : 3.3.0

.fileFromBundle(String filePath) : FileInContext

Returns a file object for the given file path located in the current bundle folder

Parameters :
   filePath : the file path (in the current bundle folder)

Example :
   #set( $file = $fn.fileFromBundle('myfile.csv') )
   #set( $file = $fn.fileFromBundle('dir/foo.txt') )

Since : 3.3.0

.fileFromModel(String filePath) : FileInContext

Returns a file object for the given file path located in the current model folder

Parameters :
   filePath : the file path (in the current model folder)

Example :
   #set( $file = $fn.fileFromModel('myfile.csv') )
   #set( $file = $fn.fileFromModel('dir/foo.txt') )

Since : 3.3.0

.firstCharToUpperCase(String s) : String

Converts the first character to upper case

Parameters :
   s : the string to be converted

Since : 2.0.7

.get(String objectName, Object defaultValue) : Any kind of object

Returns the object stored with the given name in the Velocity Context
If there's no object for the given name the default value is returned

Parameters :
   objectName : the name (or key) in the Velocity Context
   defaultValue : the value to be returned if the object is not defined

Example :
   $fn.get('groupId','defaultValue')

Since : 2.1.0

.isBlank(String s) : boolean

Returns true if the given string is 'blank'
(true if the string is null or void or only composed of blanks)

Parameters :
   s : the string to be tested

Since : 2.0.3

.isDefined(String objectName) : boolean

Returns TRUE if the given object name is defined in the Velocity Context

Parameters :
   objectName : the name (or key) in the Velocity Context

Example :
   #if ( $fn.isDefined('myvar') )

Since : 2.1.0

.isNotBlank(String s) : boolean

Returns true if the given string is not 'blank'
(true if the string is not null, not void and not only composed of blanks)

Parameters :
   s : the string to be tested

.isNotVoid(Object list/map/array) : boolean

Returns TRUE if the given list/map/array is NOT VOID

Parameters :
   list/map/array :

Example :
   #if ( $fn.isNotVoid( $entity.attributes ) )

Since : 2.0.7

.isVoid(Object list/map/array) : boolean

Returns TRUE if the given list/map/array is VOID

Parameters :
   list/map/array :

Example :
   #if ( $fn.isVoid( $entity.attributes ) )

Since : 2.0.7

.join(Collection collection, String separator) : String

Returns a string built by joining all the elements of the given collection
the 'separator' is added between each element

Parameters :
   collection : the collection (any kind of objects
   separator : the separator string (void string if no separator required)

Example :
   #set ( $v = $fn.join( $myList, "," ) )
   #set ( $v = $fn.join( $myList, "" ) )

Since : 3.3.0

.joinWithPrefixSuffix(Collection collection, String separator, String prefix, String suffix) : String

Returns a string built by joining all the elements of the given collection
the 'separator' is added between each element
the 'prefix' is added before each element
the 'suffix' is added after each element

Parameters :
   collection : the collection (any kind of objects
   separator : the separator string (or void)
   prefix : the prefix string (or void)
   suffix : the suffix string (or void)

Example :
   #set ( $v = $fn.joinWithPrefixSuffix( $myList, ";", "[", "]" ) )
   #set ( $v = $fn.joinWithPrefixSuffix( $myList, ", ", "", ".class" ) )

Since : 3.3.0

.quote(String s) : String

Adds a double quote character at the beginning and at the end of the given string

Parameters :
   s : the string to be quoted

.replaceInList(List list, Object oldElement, Object newElement) : void

Replaces all occurrences of an element with another in the given list

Parameters :
   list : the list containing the elements
   oldElement : the element to be replaced
   newElement : the new element replacing the original

Example :
   #set($list = ['a', 'b', 'cc', 'b', 'dd'])
   $fn.replaceInList($list, 'b', 'BBB')##
    result : [a, BBB, cc, BBB, dd]
   
   #set($foo = [1, 0, 3, 0, 4, 0])
   $fn.replaceInList($foo, 0, 9)##
    result : [1, 9, 3, 9, 4, 9]
   
   #set($foo = [1, 'aa', 3.2, 'zz', true, 5])
   $fn.replaceInList($foo, 'zz', 99)##
    result : [1, aa, 3.2, 99, true, 5]
   

Since : 3.3.0

.size(Object list/map/array) : int

Returns the SIZE of the given list/map/array

Parameters :
   list/map/array :

Example :
   Number of attribute = $fn.size( $entity.attributes )

Since : 2.0.7

.tab : String

Returns a single tabulation character

.tab(int n) : String

Returns N tabulation characters

Parameters :
   n : the number of tabulations to be returned

.toList(String[] array) : List

Returns a list of strings from the given array of strings

Parameters :
   array : the array of strings ( String[] )

Example :
   #set ( $mylist = $fn.toList( $mystring.split(",") ) )

Since : 3.3.0

.toLowerCase(String s) : String

Converts all of the characters in the given string to lower case

Parameters :
   s : the string to be converted

Since : 2.0.7

.toUpperCase(String s) : String

Converts all of the characters in the given string to upper case

Parameters :
   s : the string to be converted

Since : 2.0.7

.trimAll(List list) : void

Trims all string occurrences in the given list

Parameters :
   list : the list containing the elements

Example :
   #set($list = ['a', ' b', ' c c ', 'd '])
   $fn.trimAll($list)##
    result : [a, b, c c, d ]
   
   #set($foo = [1, ' a ', 3.2, ' zz' ])
   $fn.trimAll($foo)##
    result : [1, a, 3.2, zz]
   

Since : 3.3.0

.uncapitalize(String string) : String

Uncapitalizes the given string
changing the first letter to lower case

Parameters :
   string : the string to be uncapitalized

Example :
   $fn.uncapitalize($var)

Since : 2.1.0

.unquote(String s) : String

Removes the double quote character at the beginning and at the end of the given string (if any)
If the string is not quoted it is returned as is
If there's a quote character only at the beginning or at the end the string is returned as is


Parameters :
   s : the string to be unquoted