ObjectFunction { @FunctionMeta(description = "Check if the value is equal or is one of value in the given values.", example = "${w:in(values, value)}") @SuppressWarnings("unchecked") public static boolean in(Object values, Object value) { if (values == null || value == null) { return false; } if (values instanceof List) { for (Object v : (List<Object>) values) { if (v != null && value.toString().equals(v.toString())) { return true; } } return false; } else if (values.getClass().isArray()) { int len = Array.getLength(values); for (int i = 0; i < len; i++) { Object v = Array.get(values, i); if (v != null && value.toString().equals(v.toString())) { return true; } } return false; } else { return values.toString().equals(value.toString()); } }  @FunctionMeta(description = "Length of String, or array", example = "${w:length(obj)}") static Object length(Object obj); @FunctionMeta(description = "size of colection, or map", example = "${w:size(obj)}") static Object size(Object obj); @FunctionMeta(description = "Check if the value is equal or is one of value in the given values.", example = "${w:in(values, value)}") @SuppressWarnings("unchecked") static boolean in(Object values, Object value);  }
@Test public void testIn() { Assert.assertEquals(false, ObjectFunction.in(null, null)); Assert.assertEquals(false, ObjectFunction.in("abc", "ab")); Assert.assertEquals(true, ObjectFunction.in("abc", "abc")); Assert.assertEquals(true, ObjectFunction.in(Arrays.asList("a", "abc"), "abc")); Assert.assertEquals(true, ObjectFunction.in(new Object[] { "a", "abc" }, "abc")); Assert.assertEquals(false, ObjectFunction.in(new Object[] { "a", "abc" }, "abcd")); Assert.assertEquals(true, ObjectFunction.in(new Object[] { 1, "2", 3 }, "3")); }