ObjectUtils { @SuppressWarnings("all") public static boolean isEmpty(Object o) { if(o == null) return true; if(o instanceof String) { if(((String)o).length() == 0){ return true; } } else if(o instanceof Collection) { if(((Collection)o).isEmpty()){ return true; } } else if(o.getClass().isArray()) { if(Array.getLength(o) == 0){ return true; } } else if(o instanceof Map) { if(((Map)o).isEmpty()){ return true; } }else { return false; } return false; }  static boolean isNullOrEmptyString(Object o); @SuppressWarnings("all") static boolean isEmpty(Object o); static int getSize(Object o); static boolean isNotEmpty(Object c);  }
@Test public void testIsEmpty() { Assert.assertTrue(ObjectUtils.isEmpty(null)); Assert.assertTrue(ObjectUtils.isEmpty("")); Assert.assertTrue(ObjectUtils.isEmpty(new ArrayList())); Assert.assertTrue(ObjectUtils.isEmpty(new HashMap())); Assert.assertTrue(ObjectUtils.isEmpty(new Object[]{})); Assert.assertTrue(!ObjectUtils.isEmpty(" ")); Assert.assertTrue(!ObjectUtils.isEmpty(Arrays.asList(1,2,3))); Assert.assertTrue(!ObjectUtils.isEmpty(NOT_EMPTY_MAP)); Assert.assertTrue(!ObjectUtils.isEmpty(new Object[]{1,2,3})); }
@Test public void testIsEmptyWithIeelgalArgument() { Assert.assertFalse(ObjectUtils.isEmpty(new Object())); }