1 package com.randomnoun.common.jexl.eval.function;
2
3
4
5
6
7 import java.util.List;
8
9 import com.randomnoun.common.jexl.eval.EvalContext;
10 import com.randomnoun.common.jexl.eval.EvalException;
11 import com.randomnoun.common.jexl.eval.EvalFunction;
12
13
14
15
16
17
18
19 public class EndsWithFunction
20 implements EvalFunction
21 {
22
23 public Object evaluate(String functionName, EvalContext context, List<Object> arguments)
24 throws EvalException
25 {
26 if (arguments.size() != 2) { throw new EvalException(functionName + "() must contain two parameters"); }
27 if (!(arguments.get(0) instanceof String)) {
28 throw new EvalException(functionName + "() parameter 1 must be a string type");
29 }
30 if (!(arguments.get(1) instanceof String)) {
31 throw new EvalException(functionName + "() parameter 2 must be a string type");
32 }
33
34 String arg0 = (String)arguments.get(0);
35 String arg1 = (String)arguments.get(1);
36 if (arg0 == null) {
37 throw new EvalException(functionName + "() first parameter cannot be null");
38 }
39 if (arg1 == null) {
40 throw new EvalException(functionName + "() second parameter cannot be null");
41 }
42
43 return Boolean.valueOf(arg0.endsWith(arg1));
44 }
45 }