1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.jexl3.examples;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.apache.commons.jexl3.JexlBuilder;
24 import org.apache.commons.jexl3.JexlContext;
25 import org.apache.commons.jexl3.JexlEngine;
26 import org.apache.commons.jexl3.JexlExpression;
27 import org.apache.commons.jexl3.MapContext;
28 import org.junit.jupiter.api.Test;
29
30
31
32
33 public class ArrayTest {
34
35
36
37 static void example(final AbstractOutput out) throws Exception {
38
39
40
41
42 final JexlEngine jexl = new JexlBuilder().create();
43
44
45
46 final JexlContext jc = new MapContext();
47
48 final List<Object> l = new ArrayList<>();
49 l.add("Hello from location 0");
50 final Integer two = 2;
51 l.add(two);
52 jc.set("array", l);
53
54 JexlExpression e = jexl.createExpression("array[1]");
55 Object o = e.evaluate(jc);
56 out.print("Object @ location 1 = ", o, two);
57
58 e = jexl.createExpression("array[0].length()");
59 o = e.evaluate(jc);
60
61 out.print("The length of the string at location 0 is : ", o, 21);
62 }
63
64
65
66
67
68
69 public static void main(final String[] args) throws Exception {
70 example(AbstractOutput.SYSTEM);
71 }
72
73
74
75
76
77 @Test
78 public void testExample() throws Exception {
79 example(AbstractOutput.JUNIT);
80 }
81 }