@Test public void testCallback() { String json = "[{\"value\":5,\"if\":{\"d1\":[\"v1\",\"v2\"]}, \"comment\": \"some comment\"},{\"value\":10,\"if\":{\"d1\":[\"v3\"],\"d2\":[\"x1\"]}, \"runtimeEval\": true},{\"value\":2}]"; ConfigurationManager.getConfigInstance().setProperty("d1", "v2"); final AtomicReference<Integer> ref = new AtomicReference<Integer>(); DynamicContextualProperty<Integer> prop = new DynamicContextualProperty<Integer>("propWithCallback", 0) { @Override protected void propertyChanged(Integer newVal) { ref.set(newVal); } }; assertEquals(0, prop.getValue().intValue()); ConfigurationManager.getConfigInstance().setProperty("propWithCallback", json); assertEquals(5, ref.get().intValue()); assertEquals(5, prop.getValue().intValue()); assertEquals("some comment", prop.values.get(0).getComment()); assertTrue(prop.values.get(1).isRuntimeEval()); assertFalse(prop.values.get(0).isRuntimeEval()); ConfigurationManager.getConfigInstance().setProperty("propWithCallback", "7"); assertEquals(7, ref.get().intValue()); assertEquals(7, 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();  }