@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 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); }
@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; }