B2Win Suite Documentation (Under Construction)
ContactB2Data
5.2
5.2
  • B2Win Suite Documentation
  • Scripting
    • B2Win Suite Scripting Overview
    • Scripting in B2Data
      • Custom Script Nodes
        • Custom Script
        • Source Script Node (File)
        • Source Script Node (Table)
        • Source Script Node (Object)
        • If-Else Condition
        • Condition Node
      • In DataPrep
      • Properties
      • Workflow Applications
        • Workflow #1
        • Workflow #2
    • Getting Started
    • Language Basics
    • Data Types and Data Structures
      • Primitive Data Types
      • Data Structures
      • SuiteTable
      • Row, Column, StringColumn
    • Non-static Classes
      • Instant Class
      • LocalDateTime
      • LocalDate
      • LocalTime
      • JsonNode Class
      • File Class
    • Static Classes
      • Duration Class
      • Math Class
      • StrictMath Class
      • InstantUtil
      • NumericUtil
      • GeneralDateUtil
      • LocalDateTimeUtil
      • LocalDateUtil
      • LocalTimeUtil
      • DbUtil
      • StateUtil
      • FileUtil
      • JsonUtil
      • HttpUtil
      • NodeInputReader
      • RandomUtil
    • Property Class
    • Context and System
      • Context Class
      • System Class
    • Logging and Configuration
      • Logging
      • Configuration
    • Tutorial
    • Feedback
Powered by GitBook
On this page
  • Array Literal
  • List Literal
  • Map Literal

Was this helpful?

  1. Scripting
  2. Data Types and Data Structures

Data Structures

Array Literal, List Literal, Set Literal, Map literal

PreviousPrimitive Data TypesNextSuiteTable

Was this helpful?

syntax:

Array Literal

An array is a fixed-size, contiguous memory structure that stores elements of the same type.

Syntax

A [ followed by zero or more expressions separated by , and ending with ], e.g. [ 1, 2, "three" ]

This syntax creates an Object[].

Empty array literal can be specified as [] with result of creating Object[]

JEXL will attempt to strongly type the array; if all entries are of the same class or if all entries are Number instance, the array literal will be an MyClass[] in the former case, a Number[] in the latter case.

Furthermore, if all entries in the array literal are of the same class and that class has an equivalent primitive type, the array returned will be a primitive array. e.g. [1, 2, 3] will be interpreted as int[].

Methods

  • size() -> Integer: Returns the number of elements in the array.

  • get(index: Integer) -> T: Retrieves the element at the specified index and returns it.

  • set(index: Integer, value: T): Sets the value of the element at the given index.

Usage

var arr = Integer[]; // create an array of integers

arr = [1,2,3]; // set elements to array

arr.size(); // returns integer (3)
arr.get(1); // returns 2
arr.set(1, 4); // arr is now: [1, 4, 3]

List Literal

A list is a dynamic array-like data structure that can grow or shrink and allows storage of elements of different types.

Syntax

A [ followed by zero or more expressions separated by , and ending with ,...], e.g. [ 1, 2, "three",...]

This syntax creates an ArrayList<Object>.

Empty list literal can be specified as [...]

Methods

  • add(value: T): Adds a new element with the provided value to the array.

  • remove(index: Integer): Removes the element at the specified index.

  • remove(value: T): Removes the first occurrence of the element with the specified value.

  • clear(): Clears all elements from the array.

  • size(): Integer Returns the number of elements in the list.

  • isEmpty(): Boolean Checks if the list is empty and returns true if it has no elements; otherwise, it returns false.

  • static of(): List<T> Creates and returns an empty list.This class allows you to create and manage lists with elements of a specific data type.

  • contains(Object o): Boolean - Returns boolean depending on whether list contains specified parameter.

  • toArray() - convert List to Array Data Structure

Usage

var list = [1, 2, "three",...] // creating a list, able to add and remove

list.add("four"); // now list is [1, 2, "three", "four"]

list.remove(2); // now list is [1,2]

list.contains(1); // returns true

list.clear(); // clears list

Map Literal

A map represented as HashMap<Object, Object>, is a collection that associates unique keys with corresponding values, facilitating efficient retrieval and modification of data based on key references.

Syntax

A { followed by zero or more sets of key : value pairs separated by , and ending with }, e.g. { "one" : 1, "two" : 2, "three" : 3, "more": "many more" }

This syntax creates a HashMap<Object,Object>.

Empty map literal can be specified as {:}

Methods

  • create(); Map

Creates an empty map and returns it.

  • add(Map<String, Object> map, String key, Object value): void

adds a key-value pair to map. Returns nothing

  • size(); Integer

Returns number of key-value pairs in map.

  • isEmpty: Boolean

Returns true of map is empty, otherwise returns false.

  • cotainsKey(Object key): Boolean

Returns true if map contains specified key, otherwise returns false.

  • containsValue(Object value): Boolean

Returns true if map contains specified value, otherwise returns false.

  • remove(String key): Object

Removes key from Map and returns the remove value object.

  • keySet(); and values();

Return the keys and values of the map, respectively.

Usage

var map = MapUtil.create();

MapUtil.add(map, "name", "steve");
MapUtil.add(map, "age", 40);
MapUtil.add(map, "birthday", LocalDate.now());

map.values(); // returns 2023-11-22,steve,40
map.keySet(); // returns birthday,name,age
map.remove("age"); // remove, age from map and returns 40

return map; 

Or you can define map Manually:

var map = {
    "name": "steve",
    "age": 40,
    "birthday": LocalDate.now()
}

HashMaps are especially useful for defining a row in

https://commons.apache.org/proper/commons-jexl/reference/syntax.html
SuiteTable