ObjectFunction { @FunctionMeta(description = "size of colection, or map", example = "${w:size(obj)}") public static Object size(Object obj) { if (obj == null) { return null; } else if (obj instanceof Collection) { return ((Collection<?>) obj).size(); } else if (obj instanceof Map) { return ((Map<?, ?>) obj).size(); } else { try { return Reflects.forMethod().invokeMethod(obj, "getSize", (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 testSize() { Assert.assertEquals(null, ObjectFunction.size(null)); Assert.assertEquals(4, ObjectFunction.size(Arrays.<Object> asList("abc", null, true, 3))); HashMap<Object, Object> map = new HashMap<Object, Object>(); map.put("first", true); map.put(1, 2); Assert.assertEquals(2, ObjectFunction.size(map)); }