@Test public void testGetCurrentValueForMethods() { DerivedModelWithMethods model = new DerivedModelWithMethods(); model.setSimpleEnumField(SimpleEnum.Name); model.setComplexEnumField(ComplexEnum.Application); model.setStringField("Another test"); model.setLongField(92345); model.setIntField(-234); model.setBoolField(false); Assert.assertEquals(SimpleEnum.Name, model.getCurrentValue("simpleEnumField")); Assert.assertEquals(ComplexEnum.Application, model.getCurrentValue("complexEnumField")); Assert.assertEquals("Another test", model.getCurrentValue("stringField")); Assert.assertEquals((long)92345, model.getCurrentValue("longField")); Assert.assertEquals(-234, model.getCurrentValue("intField")); Assert.assertEquals(false, model.getCurrentValue("boolField")); }
public Object getCurrentValue(String value) { Method[] methods = getClass().getDeclaredMethods(); Object result = null; boolean foundMethod = false; for (Method method : methods) { String getMethod = "get" + value.substring(0, 1).toUpperCase() + value.substring(1); String isMethod = "is" + value.substring(0, 1).toUpperCase() + value.substring(1); if (method.getName().equals(getMethod) || method.getName().equals(isMethod)) { Class noParams[] = {}; try { result = method.invoke(this, (Object[])noParams); } catch (IllegalAccessException ignored) { } catch (InvocationTargetException ignored) { } foundMethod = true; } } if (!foundMethod) { Field[] fields = getClass().getDeclaredFields(); for (Field field : fields) { try { if (field.getName().equals(value)) { result = field.get(this); break; } } catch (IllegalAccessException ignored) { } } } return result; }
AppConfigBaseModel { public Object getCurrentValue(String value) { Method[] methods = getClass().getDeclaredMethods(); Object result = null; boolean foundMethod = false; for (Method method : methods) { String getMethod = "get" + value.substring(0, 1).toUpperCase() + value.substring(1); String isMethod = "is" + value.substring(0, 1).toUpperCase() + value.substring(1); if (method.getName().equals(getMethod) || method.getName().equals(isMethod)) { Class noParams[] = {}; try { result = method.invoke(this, (Object[])noParams); } catch (IllegalAccessException ignored) { } catch (InvocationTargetException ignored) { } foundMethod = true; } } if (!foundMethod) { Field[] fields = getClass().getDeclaredFields(); for (Field field : fields) { try { if (field.getName().equals(value)) { result = field.get(this); break; } } catch (IllegalAccessException ignored) { } } } return result; } }
AppConfigBaseModel { public Object getCurrentValue(String value) { Method[] methods = getClass().getDeclaredMethods(); Object result = null; boolean foundMethod = false; for (Method method : methods) { String getMethod = "get" + value.substring(0, 1).toUpperCase() + value.substring(1); String isMethod = "is" + value.substring(0, 1).toUpperCase() + value.substring(1); if (method.getName().equals(getMethod) || method.getName().equals(isMethod)) { Class noParams[] = {}; try { result = method.invoke(this, (Object[])noParams); } catch (IllegalAccessException ignored) { } catch (InvocationTargetException ignored) { } foundMethod = true; } } if (!foundMethod) { Field[] fields = getClass().getDeclaredFields(); for (Field field : fields) { try { if (field.getName().equals(value)) { result = field.get(this); break; } } catch (IllegalAccessException ignored) { } } } return result; }  }
AppConfigBaseModel { public Object getCurrentValue(String value) { Method[] methods = getClass().getDeclaredMethods(); Object result = null; boolean foundMethod = false; for (Method method : methods) { String getMethod = "get" + value.substring(0, 1).toUpperCase() + value.substring(1); String isMethod = "is" + value.substring(0, 1).toUpperCase() + value.substring(1); if (method.getName().equals(getMethod) || method.getName().equals(isMethod)) { Class noParams[] = {}; try { result = method.invoke(this, (Object[])noParams); } catch (IllegalAccessException ignored) { } catch (InvocationTargetException ignored) { } foundMethod = true; } } if (!foundMethod) { Field[] fields = getClass().getDeclaredFields(); for (Field field : fields) { try { if (field.getName().equals(value)) { result = field.get(this); break; } } catch (IllegalAccessException ignored) { } } } return result; }  ArrayList<String> configurationValueList(); ArrayList<String> globalValueList(); ArrayList<String> getConfigurationCategories(); ArrayList<String> getGlobalCategories(); boolean valueBelongsToCategory(String value, String category); Object getCurrentValue(String value); void applyCustomSettings(String configName, AppConfigStorageItem item); }
AppConfigBaseModel { public Object getCurrentValue(String value) { Method[] methods = getClass().getDeclaredMethods(); Object result = null; boolean foundMethod = false; for (Method method : methods) { String getMethod = "get" + value.substring(0, 1).toUpperCase() + value.substring(1); String isMethod = "is" + value.substring(0, 1).toUpperCase() + value.substring(1); if (method.getName().equals(getMethod) || method.getName().equals(isMethod)) { Class noParams[] = {}; try { result = method.invoke(this, (Object[])noParams); } catch (IllegalAccessException ignored) { } catch (InvocationTargetException ignored) { } foundMethod = true; } } if (!foundMethod) { Field[] fields = getClass().getDeclaredFields(); for (Field field : fields) { try { if (field.getName().equals(value)) { result = field.get(this); break; } } catch (IllegalAccessException ignored) { } } } return result; }  ArrayList<String> configurationValueList(); ArrayList<String> globalValueList(); ArrayList<String> getConfigurationCategories(); ArrayList<String> getGlobalCategories(); boolean valueBelongsToCategory(String value, String category); Object getCurrentValue(String value); void applyCustomSettings(String configName, AppConfigStorageItem item);  }