ObjectFunction { @FunctionMeta(description = "Length of String, or array", example = "${w:length(obj)}") public static Object length(Object obj) { if (obj == null) { return null; } else if (obj instanceof CharSequence) { return ((CharSequence) obj).length(); } else if (obj.getClass().isArray()) { return Array.getLength(obj); } else { try { return Reflects.forMethod().invokeMethod(obj, "getLength", (Object[]) null); } catch (Exception e) { return null; } } }  @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 testLength() { Assert.assertEquals(null, ObjectFunction.length(null)); Assert.assertEquals(3, ObjectFunction.length("abc")); Assert.assertEquals(4, ObjectFunction.length(new Object[] { "abc", null, true, 3 })); Assert.assertEquals(null, ObjectFunction.length(Arrays.<Object> asList("abc", null, true, 3))); }