return (SegmentNodeState) state;
}
SegmentNodeState before = null;
Template beforeTemplate = null;
ModifiedNodeState after = null;
if (state instanceof ModifiedNodeState) {
after = (ModifiedNodeState) state;
NodeState base = after.getBaseState();
if (base instanceof SegmentNodeState
&& store.containsSegment(((SegmentNodeState) base).getRecordId().getSegmentId())) {
before = (SegmentNodeState) base;
beforeTemplate = before.getTemplate();
}
}
Template template = new Template(state);
RecordId templateId;
if (before != null && template.equals(beforeTemplate)) {
templateId = before.getTemplateId();
} else {
templateId = writeTemplate(template);
}
List<RecordId> ids = Lists.newArrayList();
ids.add(templateId);
String childName = template.getChildName();
if (childName == Template.MANY_CHILD_NODES) {
MapRecord base;
final Map<String, RecordId> childNodes = Maps.newHashMap();
if (before != null
&& before.getChildNodeCount(2) > 1
&& after.getChildNodeCount(2) > 1) {
base = before.getChildNodeMap();
after.compareAgainstBaseState(before, new DefaultNodeStateDiff() {
@Override
public boolean childNodeAdded(String name, NodeState after) {
childNodes.put(name, writeNode(after).getRecordId());
return true;
}