PropertyUtil { public static <V> Object convert(Class type, V value) { if (type == Integer.TYPE || type == Integer.class) { int v = DataUtil.getInt(value, NULL_INT); return v == NULL_INT ? null : v; } else if (type == Long.TYPE || type == Long.class) { long v = DataUtil.getLong(value, NULL_LONG); return v == NULL_LONG ? null : v; } else if (type == Boolean.TYPE || type == Boolean.class) { return DataUtil.doGetBoolean(value, null); } else if (type.isEnum()) { if (type.isInstance(value)) { return value; } else if (value instanceof String) { return Enum.valueOf(type, (String)value); } else { return null; } } else if (type.isInterface()) { return value; } else { return DataUtil.getString(value, null); } }  static Object convert(Class type, V value); static void inject(Object obj, Map<String, V> parameters); static Properties getResourceAsProperties(String resource); static Properties getResourceAsProperties(ClassLoader classLoader, String resource);  }
@Test public void convert() throws Exception { new PropertyUtil(); PropertyUtil.PropertyInjector propertyInjector = new PropertyUtil.PropertyInjector(); propertyInjector.setName("platform.${platform.primary}.trace.uri"); Parameters<String> parameters = new ParametersMap<>(); parameters.put("platform.primary", "raptor"); parameters.put("platform.raptor.trace.uri", "raptor"); parameters.put("platform.smoke.trace.uri", "smoke"); assertEquals("platform.raptor.trace.uri", propertyInjector.replaceName(parameters)); parameters.put("platform.primary", "smoke"); assertEquals("platform.smoke.trace.uri", propertyInjector.replaceName(parameters)); propertyInjector.setName("${platform.primary}"); parameters.put("smoke", "Smoking"); parameters.put("raptor", "Flying"); assertEquals("smoke", propertyInjector.replaceName(parameters)); }