/** * This method should construct a new ValuesStorage object for the model instance to use. By default, this object * will be a {@link MapValuesStorage}, but other implementations can be used for other platforms if appropriate * by overriding this method. */ protected ValuesStorage newValuesStorage() { return new MapValuesStorage(); }
/** * {@inheritDoc} */ @Override public void putAll(ValuesStorage other) { if (other instanceof MapValuesStorage) { values.putAll(((MapValuesStorage) other).values); } else { Set<Map.Entry<String, Object>> valuesSet = other.valueSet(); for (Map.Entry<String, Object> entry : valuesSet) { put(entry.getKey(), entry.getValue(), false); } } }
/** * Analogous to {@link #readPropertiesFromMap(Map, Property[])} but adds the values to the model as set values, * i.e. marks the model as dirty with these values. */ public void setPropertiesFromMap(Map<String, Object> values, Property<?>... properties) { if (values == null) { return; } setPropertiesFromValuesStorage(new MapValuesStorage(values), properties); }
/** * {@inheritDoc} */ @Override public void putAll(ValuesStorage other) { if (other instanceof MapValuesStorage) { values.putAll(((MapValuesStorage) other).values); } else { Set<Map.Entry<String, Object>> valuesSet = other.valueSet(); for (Map.Entry<String, Object> entry : valuesSet) { put(entry.getKey(), entry.getValue(), false); } } }
/** * Copies values from the given Map. The values will be added to the model as read values (i.e. will not be * considered set values or mark the model as dirty). */ public void readPropertiesFromMap(Map<String, Object> values, Property<?>... properties) { if (values == null) { return; } readPropertiesFromValuesStorage(new MapValuesStorage(values), properties); }
@Override public void run() { TestModel model = new TestModel(); List<String> list = Arrays.asList("A", "B", "C"); model.setSomeList(list); ValuesStorage newStorage = new MapValuesStorage(); newStorage.put(TestModel.SOME_LIST.getName(), "[\"D\", \"E\", \"F\"]"); model.readPropertiesFromValuesStorage(newStorage, TestModel.SOME_LIST); assertEquals(Arrays.asList("D", "E", "F"), model.getSomeList()); // Second call reads from cache; assert that works too assertTrue(model.hasTransitory(transitoryKeyForProperty(TestModel.SOME_LIST))); assertEquals(Arrays.asList("D", "E", "F"), model.getSomeList()); newStorage.put(TestModel.SOME_LIST.getName(), "[\"H\", \"I\", \"J\"]"); model.setPropertiesFromValuesStorage(newStorage, TestModel.SOME_LIST); int currentFromJSONCount = currentMapper.fromJSONCount; assertEquals(Arrays.asList("H", "I", "J"), model.getSomeList()); assertEquals(currentFromJSONCount + 1, currentMapper.fromJSONCount); // Second call reads from cache; assert that works too assertTrue(model.hasTransitory(transitoryKeyForProperty(TestModel.SOME_LIST))); assertEquals(Arrays.asList("H", "I", "J"), model.getSomeList()); assertEquals(currentFromJSONCount + 1, currentMapper.fromJSONCount); } });
/** * This method should construct a new ValuesStorage object for the model instance to use. By default, this object * will be a {@link MapValuesStorage}, but other implementations can be used for other platforms if appropriate * by overriding this method. */ protected ValuesStorage newValuesStorage() { return new MapValuesStorage(); }
/** * Analogous to {@link #readPropertiesFromMap(Map, Property[])} but adds the values to the model as set values, * i.e. marks the model as dirty with these values. */ public void setPropertiesFromMap(Map<String, Object> values, Property<?>... properties) { if (values == null) { return; } setPropertiesFromValuesStorage(new MapValuesStorage(values), properties); }
/** * Copies values from the given Map. The values will be added to the model as read values (i.e. will not be * considered set values or mark the model as dirty). */ public void readPropertiesFromMap(Map<String, Object> values, Property<?>... properties) { if (values == null) { return; } readPropertiesFromValuesStorage(new MapValuesStorage(values), properties); }