Skip to content
Cheatsheets

AMIScript: Scripting

Variables

Basic Types

Boolean b2 = true;
Byte b1 = 5b;

Integer i = 1; // also Int
Short s = 5s;
Long l = 5l;
BigInteger bi = "100";

Float f = 0.5f;
Double d = 0.5d;
BigDecimal bd = "0.5";

Number n = 100; // parent class for other numbers

String s = "s";
Char c = 'c';
UTC u1 = 1709118835000; // millis since epoch
UTCN u2 = 1709118835000000000; // nanos since epoch

Basic Data Structures

1
2
3
4
5
6
7
8
List l = new List("a", "b", "c");
Set s = new Set("id001", "id002");
Map m = new Map("age", 23, "name", "alice");

List names = new List("alice", "bob", "charlie");
List ages = new List(23, 58, 31);
Map columnMap = new Map("names", names, "ages", ages);
Table t = new Table("myTable", columnMap);

Casting

1
2
3
4
5
6
Int i = 418;
String s = i; // implicit
Int i1 = (int) s; // explicit
Int i2 = (int) (s.substring(0,2)); // explicit
UTC u = parseDate("2024-02-28", "yyyy-MM-dd", "UTC"); // parsing
Map m = parseJson("{\"name\": \"alice\", \"age\": 23}"); // parsing

Strings

1
2
3
4
5
String s1 = "hello \"world\"!"; // hello "world"!
String s2 = "first line: ${s1}"; // first line: hello "world"!
String s3 = """hello ${s1} \"world\"!"""; // hello ${s1} \"world\"!
String s4 = """hello
world""";

Comments

1
2
3
4
// Single line
/*
Multi-line
*/

If statements

1
2
3
4
5
6
7
8
int x = 6;
int y;
if (x > 5) {
    y = x+1;
    logInfo("true case");
} else {
    y = 0;
}
1
2
3
4
int x = 6;
int y;
if (x > 5)
    y=x+1;
int x = 6;
int y = x > 5 ? x+1 : 0;

Loops

1
2
3
4
int x = 0;
for (int i=0; i<10; i++) {
  x += i;
}
1
2
3
4
5
6
int x = 0;
int i = 0;
while (i<10) {
  x += i;
  i++;
}
1
2
3
4
List myList = new List("Hello","World");
for (String s: myList) {
  logInfo(s);
}
int x = 0;
int i = 1;
while (true) {
  x += i;
  if (x < 5) {
    continue;
  }
  i++;
  if (i > 10) {
    break;
  }
}

Methods

1
2
3
4
5
6
int addFive(int x) {
  return x + 5;
};
double addFive(double x) {
  return x + 5;
};

Operators

Numerical

1
2
3
5 + 4 - 2 == 7;
(3 * 4) / 6 == 2;
10 % 3 == 1;

Numerical Assignment

1
2
3
4
5
6
int x = 2;
x++; // x is 3
x += 3; // x is 6
x *= 2; // x is 12
x /= 4; // x is 3
x %= 2; // x is 1

Boolean

1
2
3
4
5
Boolean b1 = (5 < 10); // T
Boolean b2 = (3 >= 4); // F
Boolean b3 = (1 == 1); // T
(b1 && (b2 || b3)); // T
!b1; // F

Regex

See Java Pattern for =~

1
2
3
String myRegex = "id[0-9][0-9]";
"id0a" =~ myRegex; // F
"id01" =~ myRegex; // T

See Simplified Text Matching for ~~

1
2
3
String mySimplifiedTextMatching = "^id*|^myid*";
"yourid01" ~~ mySimplifiedTextMatching; // F
"myid01" ~~ mySimplifiedTextMatching; // T