Skip to content

Basic Data Types

This article describes all basic data types used in the JuniperBot Template Engine.

Some methods may have an invoke quota. Quota means how many times this method can be invoked per single template. Attempts to invoke that exceed the specified quota will be ignored and will not take any action.

Literals

Literals are the most basic expressions, check the table below:

NameExample
Float-1.5, 5.7, 1.0
Integer-10, 56, 0
Null Referencenull
Booleantrue или false
String"string in double brackets"
'apostrophe string'
Character'g'

Lists

There are two ways to specify a list in Template Engine. It can be either by enumeration or by comprehension.

  1. To specify a list by enumeration, you need to provide every single element of the list, as shown below:

    [1, 2, 3]
    

    The list defined this way is mutable. It does support methods to add, remove, replace elements and clear the list.

  2. To specify a list by comprehension, you just need to specify both the beginning and the ending elements of the list:

    [1..3]
    

    The list defined this way is immutable. It's kind of a tuple that is very convenient to use in loops.

WARNING

The maximum list size is 250 elements.

Methods

Type Conversion does not apply for list methods:

JuniperBot Template
{{ [1..3].contains(1) }} - {{ [1..3].contains('1') }}

This example will print true - false.

When working with lists, especially with methods involving searching, you should always keep the data type in mind.

WARNING

Modifying methods are only available for lists created by enumeration like the example above.

MethodParametersReturnsDescription
add(Element)Number
String
Boolean
BooleanAppends the specified element to the end of list.
Returns true if element has been added.
addIfAbsent(Element)Number
String
Boolean
BooleanAppends the specified element to the end of list if the list doesn't contain it yet.
Returns true if element has been added.
addAll(List)ListBooleanAppends all of the elements in the specified collection to the end of this list.
Returns true if list has changed in result.
replace(Index, Element)Index:
Number

Element:
Number
String
Boolean
Number
String
Boolean
Replaces the element at the specified position in this list with the specified element.
Returns the element previously at the specified position.
remove(Element)Number
String
Boolean
BooleanRemoves the first occurrence of the specified element from this list, if it is present.
Returns true if this list contained the specified element.
removeAll(List)ListBooleanRemoves all elements that are contained in the specified list.
Returns true if at least one element has been removed.
removeAt(Index)NumberNumber
String
Boolean
Removes the element at the specified position in this list.
Returns the element that was removed from the list.
contains(Element)Number
String
Boolean
BooleanReturns true if list contains the specified element.
containsAll(List)ListBooleanReturns true if list contains all of the elements in the specified list.
containsAny(List)ListBooleanReturns true if list contains any of the elements in the specified list.
indexOf(Element)Number
String
Boolean
NumberReturns the index of the first occurrence of the specified element, or -1 if this list does not contain the element.
countOf(Element)Number
String
Boolean
NumberReturns the amount of occurrences of the specified element.
clear()--Removes all of the elements from this list.

Maps

It is also possible to represent collections of key and value pairs, so-called maps, where keys can either be Identifiers or Strings and values can take form of any kind of expression:

{ key1: 'value1', 'key 2': 'value2' }

Keep in mind that identifiers used to represent the key elements are not used as variable placeholders, instead, they are converted to their String representation. For example, the identifier key1 shown above will be converted to the String value "key1".

WARNING

The maximum map size is 250 entries.

Methods

Type Conversion does not apply for map methods.

JuniperBot Template
{% set map = { key: 1 } %}
{{ map.containsValue(1) }} - {{ map.containsValue('1') }}

This example will print true - false.

When working with maps, especially with methods involving searching values, you should always keep the data type in mind.

WARNING

Following methods are only available for maps created manually like the example above.

MethodParametersReturnsDescription
put(Key, Value)Key:
String

Value:
Number
String
Boolean
Number
String
Boolean
Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced by the specified value.
Returns the previous value associated with key, or null if there was no mapping for key.
putAll(Map)Map-Copies all of the mappings from the specified map to this map.
putIfAbsent(Key, Value)Key:
String

Value:
Number
String
Boolean
Number
String
Boolean
If the specified key is not already associated with a value, associates it with the given value and returns null, otherwise returns the current value.
remove(Key)StringNumber
String
Boolean
Removes the specified key and its corresponding value from this map.
Returns the previous value associated with the key, or null if the key was not present in the map.
remove(Key, Value)Key:
String

Value:
Number
String
Boolean
BooleanRemoves the entry for the specified key only if it is mapped to the specified value.
Returns true if entry was removed
containsKey(Key)StringBooleanReturns true if the map contains the specified key.
containsValue(Value)Number
String
Boolean
BooleanReturns true if the map has at least one key associated with the specified value.
clear()--Removes all of the mappings from this map

DateTime

This data type represents date and time and allows to manipulate them.

Properties

PropertyTypeDescription
millisNumberMilliseconds
millisOfDayNumberMillis of day
millisOfSecondNumberMillis of second
secondOfDayNumberSecond of day
secondOfMinuteNumberSecond of minute
minuteOfDayNumberMinute of day
minuteOfHourNumberMinute of hour
hourOfDayNumberHour of day
dayOfMonthNumberDay of month
dayOfWeekNumberDay of week
dayOfYearNumberDay of year
weekOfWeekyearNumberWeek of weekyear
weekyearNumberWeek year *
monthOfYearNumberMonth of year
yearNumberYear
yearOfCenturyNumberYear of century
yearOfEraNumberYear of era
centuryOfEraNumberCentury of era
eraNumberEra
zoneOffsetNumberTimezone offset in milliseconds
isAfterNowBooleantrue if this date is in future
isBeforeNowBooleantrue if this date is in past

* Week year

Because the first day of the first week does not always fall on the first day of the year, sometimes the week-year will differ from the month year.

For example, in the US, the week that contains Jan 1 is always the first week. In the US, weeks also start on Sunday. If Jan 1 was a Monday, the Dec 31 would belong to the same week as Jan 1, and thus the same week-year as Jan 1. Dec 30 would have a different week-year than Dec 31.

Methods

The methods below do not modify the current instance, but return a new one.

MethodParametersReturnsDescription
plusMillis(Amount)NumberDateTimeReturns a copy of this datetime plus the specified number of millis.
plusSeconds(Amount)NumberDateTimeReturns a copy of this datetime plus the specified number of seconds.
plusMinutes(Amount)NumberDateTimeReturns a copy of this datetime plus the specified number of minutes.
plusHours(Amount)NumberDateTimeReturns a copy of this datetime plus the specified number of hours.
plusDays(Amount)NumberDateTimeReturns a copy of this datetime plus the specified number of days.
plusWeeks(Amount)NumberDateTimeReturns a copy of this datetime plus the specified number of weeks.
plusMonths(Amount)NumberDateTimeReturns a copy of this datetime plus the specified number of months
plusYears(Amount)NumberDateTimeReturns a copy of this datetime plus the specified number of years.
minusMillis(Amount)NumberDateTimeReturns a copy of this datetime minus the specified number of millis.
minusSeconds(Amount)NumberDateTimeReturns a copy of this datetime minus the specified number of seconds.
minusMinutes(Amount)NumberDateTimeReturns a copy of this datetime minus the specified number of minutes.
minusHours(Amount)NumberDateTimeReturns a copy of this datetime minus the specified number of hours.
minusDays(Amount)NumberDateTimeReturns a copy of this datetime minus the specified number of days.
minusWeeks(Amount)NumberDateTimeReturns a copy of this datetime minus the specified number of weeks.
minusMonths(Amount)NumberDateTimeReturns a copy of this datetime minus the specified number of months.
minusYears(Amount)NumberDateTimeReturns a copy of this datetime minus the specified number of years.
isAfter(Date)DateTimeBooleanIs this date strictly after the specified date.
isBefore(Date)DateTimeBooleanIs this date strictly before the specified date.

All rights sniffed.