@Override public void initialize(Map<String, String> target) { for (Map.Entry<K, C> entry : initialValues.entrySet()) { if (entry.getValue() != null) { Initializer.Helper.initialiseAttribute(target, entry.getKey().toString(), serializer.toString(entry.getValue())); } } } };
@Override public T add(int index, I initialState) { int last = orderedValues.size(); Preconditions.checkPositionIndex(index, last); if (index == last) { return add(initialState); } T childAfter = orderedValues.get(index); E nodeAfter = valueToElement.get(childAfter); Map<String, String> attributes = Initializer.Helper.buildAttributes(initialState, factory); E fresh = createBefore(getDocument(), nodeAfter, attributes); return elementToValue.get(fresh); }
@Override public V set(I initialState) { final Map<String, String> attributes = Initializer.Helper.buildAttributes(initialState, valueFactory); // Insert a new first-child element of the container. Point<Doc.N> insertionPoint = Point.inElement(container, getDocument().getFirstChild(container)); Doc.E element = getDocument().createElement(insertionPoint, valueTagName, attributes); // onElementAdded will create the value object. assert currentElement != null; assert currentValue != null; cleanup(); return currentValue; }
@Override public T add(I initialState) { Map<String, String> attributes = Initializer.Helper.buildAttributes(initialState, factory); E element = getDocument().createChildElement(parent, childTag, attributes); // As we are using an observable document, that is registered to post us events, we expect // that onElementAdded is called once the child is created. This method in turn creates a // child object for the given element and store it in the elementToValue map. We use this to // return the child for the given element. return elementToValue.get(element); }
public void testInitialiseAttributeThrowsExceptionOnDuplicateKey() { Map<String, String> attrs = CollectionUtils.newHashMap(); attrs.put("k1", "v1"); try { Initializer.Helper.initialiseAttribute(attrs, "k1", "v2"); fail("Expected an IllegalArgumentException"); } catch (IllegalArgumentException expected) { } } }
@Override public void initialize(Map<String, String> target) { if (value != null) { Initializer.Helper.initialiseAttribute(target, valueAttrName, serializer.toString(value)); } } };
public void testInitialiseAttributeThrowsExceptionOnDuplicateKey() { Map<String, String> attrs = CollectionUtils.newHashMap(); attrs.put("k1", "v1"); try { Initializer.Helper.initialiseAttribute(attrs, "k1", "v2"); fail("Expected an IllegalArgumentException"); } catch (IllegalArgumentException expected) { } } }