@Test public void testSingleTextValue() { ConfigurationManager.getConfigInstance().setProperty("key2", "5"); DynamicContextualProperty<Integer> prop = null; try { prop = new DynamicContextualProperty<Integer>("key2", 0); assertEquals(5, prop.getValue().intValue()); } catch (Exception e) { e.printStackTrace(); fail("Unexpected exception"); } ConfigurationManager.getConfigInstance().setProperty("key2", "10"); assertEquals(10, prop.getValue().intValue()); ConfigurationManager.getConfigInstance().setProperty("key2", "Invalid"); assertEquals(0, prop.getValue().intValue()); String json = "[{\"value\":2}]"; ConfigurationManager.getConfigInstance().setProperty("key2", json); assertEquals(2, prop.getValue().intValue()); }
@Override public T getValue() { if (values != null) { for (Value<T> v: values) { if (v.getDimensions() == null || v.getDimensions().isEmpty() || predicate.apply(v.getDimensions())) { return v.getValue(); } } } return defaultValue; }
DynamicContextualProperty extends PropertyWrapper<T> { @Override public T getValue() { if (values != null) { for (Value<T> v: values) { if (v.getDimensions() == null || v.getDimensions().isEmpty() || predicate.apply(v.getDimensions())) { return v.getValue(); } } } return defaultValue; } }
DynamicContextualProperty extends PropertyWrapper<T> { @Override public T getValue() { if (values != null) { for (Value<T> v: values) { if (v.getDimensions() == null || v.getDimensions().isEmpty() || predicate.apply(v.getDimensions())) { return v.getValue(); } } } return defaultValue; } @SuppressWarnings("unchecked")  DynamicContextualProperty(String propName, T defaultValue, Predicate<Map<String, Collection<String>>> predicate); @SuppressWarnings("unchecked")  DynamicContextualProperty(String propName, T defaultValue); }
DynamicContextualProperty extends PropertyWrapper<T> { @Override public T getValue() { if (values != null) { for (Value<T> v: values) { if (v.getDimensions() == null || v.getDimensions().isEmpty() || predicate.apply(v.getDimensions())) { return v.getValue(); } } } return defaultValue; } @SuppressWarnings("unchecked")  DynamicContextualProperty(String propName, T defaultValue, Predicate<Map<String, Collection<String>>> predicate); @SuppressWarnings("unchecked")  DynamicContextualProperty(String propName, T defaultValue); @Override T getValue(); }
DynamicContextualProperty extends PropertyWrapper<T> { @Override public T getValue() { if (values != null) { for (Value<T> v: values) { if (v.getDimensions() == null || v.getDimensions().isEmpty() || predicate.apply(v.getDimensions())) { return v.getValue(); } } } return defaultValue; } @SuppressWarnings("unchecked")  DynamicContextualProperty(String propName, T defaultValue, Predicate<Map<String, Collection<String>>> predicate); @SuppressWarnings("unchecked")  DynamicContextualProperty(String propName, T defaultValue); @Override T getValue();  }