@Test public void getProperty() { this.name = "test"; assertEquals("test", BeanHelper.getProperty(this, "name")); assertEquals("java.lang.String", BeanHelper.getNestedProperty(this, "name.class.name")); this.name = null; assertNull(BeanHelper.getNestedProperty(this, "name")); assertNull(BeanHelper.getNestedProperty(this, "name.class.name")); try { assertNull(BeanHelper.getNestedProperty(this, "nonExistingProperty.test.hurzel")); fail("Exception expected."); } catch (final RuntimeException ex) { } testStrings = new String[]{null, "zwei", "drei"}; assertEquals("zwei", BeanHelper.getIndexedProperty(this, "testStrings[1]")); assertEquals("java.lang.String", BeanHelper.getNestedProperty(this, "testStrings[1].class.name")); assertNull(BeanHelper.getNestedProperty(this, "testStrings[0]")); assertNull(BeanHelper.getNestedProperty(this, "testStrings[0].class.name")); testInts = new int[]{1, 2, 3, 5, 6}; assertEquals(2, BeanHelper.getIndexedProperty(this, "testInts[1]")); }
public static String getProperty(final Method method) { final String name = method.getName(); int pos = 0; if ((name.startsWith("get") == true || name.startsWith("has") == true) && name.length() > 3) { pos = 3; } else if (name.startsWith("is") == true && name.length() > 2) { pos = 2; } else { return null; } final String property = name.substring(pos); return StringUtils.uncapitalize(property); }
BeanHelper { public static String getProperty(final Method method) { final String name = method.getName(); int pos = 0; if ((name.startsWith("get") == true || name.startsWith("has") == true) && name.length() > 3) { pos = 3; } else if (name.startsWith("is") == true && name.length() > 2) { pos = 2; } else { return null; } final String property = name.substring(pos); return StringUtils.uncapitalize(property); } }
BeanHelper { public static String getProperty(final Method method) { final String name = method.getName(); int pos = 0; if ((name.startsWith("get") == true || name.startsWith("has") == true) && name.length() > 3) { pos = 3; } else if (name.startsWith("is") == true && name.length() > 2) { pos = 2; } else { return null; } final String property = name.substring(pos); return StringUtils.uncapitalize(property); }  }
BeanHelper { public static String getProperty(final Method method) { final String name = method.getName(); int pos = 0; if ((name.startsWith("get") == true || name.startsWith("has") == true) && name.length() > 3) { pos = 3; } else if (name.startsWith("is") == true && name.length() > 2) { pos = 2; } else { return null; } final String property = name.substring(pos); return StringUtils.uncapitalize(property); }  static void enterTestMode(); static void exitTestMode(); static String determinePropertyName(final Method method); static Method determineGetter(final Class<?> clazz, final String fieldname); static Annotation[] getDeclaredAnnotations(final Class<?> clazz, final String fieldname); static Method determineGetter(final Class<?> clazz, final String fieldname, final boolean onlyPublicGetter); static List<Method> getAllGetterMethods(final Class<?> clazz); static List<Method> getAllGetterMethods(final Class<?> clazz, final boolean includingSuperClasses); static String getProperty(final Method method); static Class<?> determinePropertyType(final Method method); static Method determineSetter(final Class<?> clazz, final String fieldname); static Method determineSetter(final Class<?> clazz, final Method method); static void invokeSetter(final Object obj, final Method method, final Object value); static Object invoke(final Object obj, final Method method); static Object invoke(final Object obj, final Method method, final Object[] args); static Object newInstance(final String className); static Object newInstance(final Class<?> clazz); static Object newInstance(final Class<?> clazz, final Class<?> paramType, final Object param); static Object newInstance(final Class<?> clazz, final Class<?> paramType1, final Class<?> paramType2,
      final Object param1,
      final Object param2); static Object newInstance(final Class<?> clazz, final Class<?>[] paramTypes, final Object... params); static Object invoke(final Object obj, final Method method, final Object arg); static Field[] getAllDeclaredFields(Class<?> clazz); static Field getDeclaredField(Class<?> clazz, String fieldname); static Method[] getAllDeclaredMethods(Class<?> clazz); static Object getProperty(final Object bean, final String property); static Object setProperty(final Object bean, final String property, final Object value); static Object getIndexedProperty(final Object bean, final String property); static Object getNestedProperty(final Object bean, final String property); static Field[] getDeclaredPropertyFields(final Class<?> clazz); static Object getFieldValue(final Object obj, final Class<?> clazz, final String fieldname); static Object getFieldValue(final Object obj, final Field field); static boolean copyProperties(final Object src, final Object dest, final String... properties); @SuppressWarnings("unchecked") static boolean copyProperties(final Object src, final Object dest, final boolean whitespaceEqualsNull,
      final String... properties); }
BeanHelper { public static String getProperty(final Method method) { final String name = method.getName(); int pos = 0; if ((name.startsWith("get") == true || name.startsWith("has") == true) && name.length() > 3) { pos = 3; } else if (name.startsWith("is") == true && name.length() > 2) { pos = 2; } else { return null; } final String property = name.substring(pos); return StringUtils.uncapitalize(property); }  static void enterTestMode(); static void exitTestMode(); static String determinePropertyName(final Method method); static Method determineGetter(final Class<?> clazz, final String fieldname); static Annotation[] getDeclaredAnnotations(final Class<?> clazz, final String fieldname); static Method determineGetter(final Class<?> clazz, final String fieldname, final boolean onlyPublicGetter); static List<Method> getAllGetterMethods(final Class<?> clazz); static List<Method> getAllGetterMethods(final Class<?> clazz, final boolean includingSuperClasses); static String getProperty(final Method method); static Class<?> determinePropertyType(final Method method); static Method determineSetter(final Class<?> clazz, final String fieldname); static Method determineSetter(final Class<?> clazz, final Method method); static void invokeSetter(final Object obj, final Method method, final Object value); static Object invoke(final Object obj, final Method method); static Object invoke(final Object obj, final Method method, final Object[] args); static Object newInstance(final String className); static Object newInstance(final Class<?> clazz); static Object newInstance(final Class<?> clazz, final Class<?> paramType, final Object param); static Object newInstance(final Class<?> clazz, final Class<?> paramType1, final Class<?> paramType2,
      final Object param1,
      final Object param2); static Object newInstance(final Class<?> clazz, final Class<?>[] paramTypes, final Object... params); static Object invoke(final Object obj, final Method method, final Object arg); static Field[] getAllDeclaredFields(Class<?> clazz); static Field getDeclaredField(Class<?> clazz, String fieldname); static Method[] getAllDeclaredMethods(Class<?> clazz); static Object getProperty(final Object bean, final String property); static Object setProperty(final Object bean, final String property, final Object value); static Object getIndexedProperty(final Object bean, final String property); static Object getNestedProperty(final Object bean, final String property); static Field[] getDeclaredPropertyFields(final Class<?> clazz); static Object getFieldValue(final Object obj, final Class<?> clazz, final String fieldname); static Object getFieldValue(final Object obj, final Field field); static boolean copyProperties(final Object src, final Object dest, final String... properties); @SuppressWarnings("unchecked") static boolean copyProperties(final Object src, final Object dest, final boolean whitespaceEqualsNull,
      final String... properties);  }