Add proposed item into the (flattened and reversed) tree

@param newNode a new proposed item
@return true if the item was merged and will trigger a repair or false if the proposed item should be kept as such and no repair generated
483413
public boolean addProposedItem(final ItemsNodeInterval newNode) {
        Preconditions.checkState(newNode.getItems().size() == 1, "Invalid node=%s", newNode);
        final Item item = newNode.getItems().get(0);

        return addNode(newNode, new AddNodeCallback() {
            @Override
            public boolean onExistingNode(final NodeInterval existingNode) {
                // If we receive a new proposed that is the same kind as the reversed existing (current node),
                // we match existing and proposed. If not, we keep the proposed item as-is outside of the tree.
                if (isSameKind((ItemsNodeInterval) existingNode)) {
                    final ItemsInterval existingOrNewNodeItems = ((ItemsNodeInterval) existingNode).getItemsInterval();
                    existingOrNewNodeItems.cancelItems(item);
                    return true;
                } else {
                    return false;
                }
            }

            @Override
            public boolean shouldInsertNode(final NodeInterval insertionNode) {
                // At this stage, we're currently merging a proposed item that does not fit any of the existing intervals.
                // If this new node is about to be inserted at the root level, this means the proposed item overlaps any
                // existing item. We keep these as-is, outside of the tree: they will become part of the resulting list.
                if (insertionNode.isRoot()) {
                    return false;
                }

                // If we receive a new proposed that is the same kind as the reversed existing (parent node),
                // we want to insert it to generate a piece of repair (see SubscriptionItemTree#buildForMerge).
                // If not, we keep the proposed item as-is outside of the tree.
                return isSameKind((ItemsNodeInterval) insertionNode);
            }

            private boolean isSameKind(final ItemsNodeInterval insertionNode) {
                final List<Item> insertionNodeItems = insertionNode.getItems();
                Preconditions.checkState(insertionNodeItems.size() == 1, "Expected existing node to have only one item");
                final Item insertionNodeItem = insertionNodeItems.get(0);
                return insertionNodeItem.isSameKind(item);
            }
        });
    }
1349101
public Node insertBefore(Node newChild, Node refChild) throws DOMException
  {
  	if(null == refChild)
  	{
  		appendChild(newChild);
  		return newChild;
  	}
  	
  	if(newChild == refChild)
  	{
  		// hmm...
  		return newChild;
  	}

    Node node = m_firstChild; 
    Node prev = null;  
    boolean foundit = false;
    
    while (null != node)
    {
    	// If the newChild is already in the tree, it is first removed.
    	if(newChild == node)
    	{
    		if(null != prev)
    			((ElemTemplateElement)prev).m_nextSibling = 
    				(ElemTemplateElement)node.getNextSibling();
    		else
    			m_firstChild = (ElemTemplateElement)node.getNextSibling();
    		node = node.getNextSibling();
    		continue; // prev remains the same.
    	}
    	if(refChild == node)
    	{
    		if(null != prev)
    		{
    			((ElemTemplateElement)prev).m_nextSibling = (ElemTemplateElement)newChild;
    		}
    		else
    		{
    			m_firstChild = (ElemTemplateElement)newChild;
    		}
    		((ElemTemplateElement)newChild).m_nextSibling = (ElemTemplateElement)refChild;
    		((ElemTemplateElement)newChild).setParentElem(this);
    		prev = newChild;
    		node = node.getNextSibling();
    		foundit = true;
    		continue;
    	}
    	prev = node;
    	node = node.getNextSibling();
    }
    
    if(!foundit)
    	throw new DOMException(DOMException.NOT_FOUND_ERR, 
    		"refChild was not found in insertBefore method!");
    else
    	return newChild;
  }
603000
@Override
    public TreeNode processMerge(TreeNode node) {

        DefaultMutableTreeNode masterNode = (DefaultMutableTreeNode) node;

        // if master and slave are the same object return the
        // masterNode
        if (masterNode.equals(slaveTopNode)) {
            return masterNode;
        }

        // If there are not children in slaveTopNode return the
        // masterNode
        if (slaveTopNode.getChildCount() == 0) {
            return masterNode;
        }

        mergeNodes(masterNode, slaveTopNode);
        return masterNode;
    }
356344
public boolean addChild(ClusteringTreeNode e) {
		assert (this.center.length == e.center.length);
		return this.children.add(e);
	}
1302160
public void addNode(CDKRNode newNode) {
        getGraph().add(newNode);
        getGraphBitSet().set(getGraph().size() - 1);
    }
912871
public void add(final ObjectSinkNode node) {
        if ( this.firstNode == null ) {
            this.firstNode = node;
            this.lastNode = node;
        } else {
            this.lastNode.setNextObjectSinkNode( node );
            node.setPreviousObjectSinkNode( this.lastNode );
            this.lastNode = node;
        }
        this.size++;
    }
1004542
public final boolean addChild(int index, N newChild) {
		if (newChild == null) {
			return false;
		}

		final int count = (this.children == null) ? 0 : this.children.size();

		final N oldParent = newChild.getParentNode();
		if (oldParent != this && oldParent != null) {
			newChild.removeFromParent();
		}

		final int insertionIndex;

		if (this.children == null) {
			this.children = newInternalList(index + 1);
		}

		if (index < count) {
			// set the element
			insertionIndex = Math.max(index, 0);
			this.children.add(insertionIndex, newChild);
		} else {
			// Resize the array
			insertionIndex = this.children.size();
			this.children.add(newChild);
		}

		++this.notNullChildCount;

		newChild.setParentNodeReference(toN(), true);
		firePropertyChildAdded(insertionIndex, newChild);

		return true;
	}
522551
public void add(final LeftTupleSinkNode node) {
        if ( this.firstNode == null ) {
            this.firstNode = node;
            this.lastNode = node;;
        } else {
            this.lastNode.setNextLeftTupleSinkNode( node );
            node.setPreviousLeftTupleSinkNode( this.lastNode );
            this.lastNode = node;
        }
        this.size++;
    }
310021
private static boolean isGeneratedNodeExcluded(AstNode astNode) {
    AstNode prev = astNode.getPreviousAstNode();
    return prev != null
      && prev.getTokenLine() == astNode.getTokenLine()
      && prev.isCopyBookOrGeneratedNode();
  }
112997
def insert_node(self, node):
        
        if self._is_node_reserved(node):
            return False

        # Put node in map
        self._node_map[node.get_id()] = node
        return True
1119388
public boolean add(Object element) {

        last.next = new Node(element, null);
        last      = last.next;

        elementCount++;

        return true;
    }
550283
private void evaluateSubtreeReplacement() {

        if (this.hypothesis.size() == 1) {
            // skip replacement if only one node is discovered
            return;
        }

        final Set<ReplacementResult<ADTState<I, O>, I, O>> potentialReplacements =
                this.subtreeReplacer.computeReplacements(this.hypothesis, this.alphabet, this.adt);
        final List<ReplacementResult<ADTState<I, O>, I, O>> validReplacements =
                new ArrayList<>(potentialReplacements.size());
        final Set<ADTNode<ADTState<I, O>, I, O>> cachedLeaves =
                potentialReplacements.isEmpty() ? Collections.emptySet() : ADTUtil.collectLeaves(this.adt.getRoot());

        for (final ReplacementResult<ADTState<I, O>, I, O> potentialReplacement : potentialReplacements) {
            final ADTNode<ADTState<I, O>, I, O> proposedReplacement = potentialReplacement.getReplacement();
            final ADTNode<ADTState<I, O>, I, O> nodeToReplace = potentialReplacement.getNodeToReplace();

            assert this.validateADS(nodeToReplace, proposedReplacement, potentialReplacement.getCutoutNodes());

            final ADTNode<ADTState<I, O>, I, O> replacement = this.verifyADS(nodeToReplace,
                                                                             proposedReplacement,
                                                                             cachedLeaves,
                                                                             potentialReplacement.getCutoutNodes());

            // verification may have introduced reset nodes
            final int oldCosts = ADTUtil.computeEffectiveResets(nodeToReplace);
            final int newCosts = ADTUtil.computeEffectiveResets(replacement);

            if (newCosts >= oldCosts) {
                continue;
            }

            validReplacements.add(new ReplacementResult<>(nodeToReplace, replacement));
        }

        for (final ReplacementResult<ADTState<I, O>, I, O> potentialReplacement : validReplacements) {
            final ADTNode<ADTState<I, O>, I, O> replacement = potentialReplacement.getReplacement();
            final ADTNode<ADTState<I, O>, I, O> nodeToReplace = potentialReplacement.getNodeToReplace();

            this.adt.replaceNode(nodeToReplace, replacement);

            this.resiftAffectedTransitions(ADTUtil.collectLeaves(replacement), ADTUtil.getStartOfADS(replacement));
        }

        this.closeTransitions();
    }
732913
protected final void merge(final InternalNode<K, V> nodeParent, final int slot, final Node<K, V> nodeFROMx) {
		final LeafNode<K, V> nodeFROM = (LeafNode<K, V>) nodeFROMx;
		final LeafNode<K, V> nodeTO = this;
		final int sizeTO = nodeTO.allocated;
		final int sizeFROM = nodeFROM.allocated;
		// copy keys from nodeFROM to nodeTO
		System.arraycopy(nodeFROM.keys, 0, nodeTO.keys, sizeTO, sizeFROM);
		System.arraycopy(nodeFROM.values, 0, nodeTO.values, sizeTO, sizeFROM);
		nodeTO.allocated += sizeFROM;
		// remove key from nodeParent
		nodeParent.remove(slot);
		// Update Linked List (left) in new High
		if (nodeFROM.rightid != NULL_ID) {
			final LeafNode<K, V> rightFROM = (LeafNode<K, V>) tree.getNode(nodeFROM.rightid);
			rightFROM.leftid = id;
			tree.putNode(rightFROM);
		}
		// Update Linked List (right)
		rightid = nodeFROM.rightid;
		// update lowIdx on tree
		if (leftid == 0) {
			tree.lowIdx = id;
		}
		// update highIdx on tree
		if (rightid == 0) {
			tree.highIdx = id;
		}
		//
		// Free nodeFROM
		tree.freeNode(nodeFROM);
	}
1235143
public void replaceNode(final ADTNode<S, I, O> oldNode, final ADTNode<S, I, O> newNode) {

        if (this.root.equals(oldNode)) {
            this.root = newNode;
        } else if (ADTUtil.isResetNode(oldNode)) {
            final ADTNode<S, I, O> endOfPreviousADS = oldNode.getParent();
            final O outputToReset = ADTUtil.getOutputForSuccessor(endOfPreviousADS, oldNode);

            newNode.setParent(endOfPreviousADS);
            endOfPreviousADS.getChildren().put(outputToReset, newNode);
        } else {
            final ADTNode<S, I, O> oldNodeParent = oldNode.getParent(); //reset node

            assert ADTUtil.isResetNode(oldNodeParent);

            final ADTNode<S, I, O> endOfPreviousADS = oldNodeParent.getParent();
            final O outputToReset = ADTUtil.getOutputForSuccessor(endOfPreviousADS, oldNodeParent);
            final ADTNode<S, I, O> newResetNode = new ADTResetNode<>(newNode);

            newResetNode.setParent(endOfPreviousADS);
            newNode.setParent(newResetNode);
            endOfPreviousADS.getChildren().put(outputToReset, newResetNode);
        }
    }
449328
public void addNewItem(M newItem) {
    if (this.items == null) {
      this.items = createEmptyList();
    }

    this.items.add(newItem);
  }
1103803
function(newnode, oldnode, ids) {
		var result = true;
		var update = null;
		if (this._attschanged(newnode.attributes, oldnode.attributes, ids)) {
			var newid = this._assistant.id(newnode);
			var oldid = this._assistant.id(oldnode);
			if (newid && newid === oldid) {
				update = new edbml.AttsUpdate(this._doc).setup(oldid, newnode, oldnode);
				this._updates.collect(update, ids);
			} else {
				result = false;
			}
		}
		return result;
	}
827552
public boolean add() {
        if (root == NIL) {
            root = nodeAllocator.newNode();
            copy(root);
            fixAggregates(root);
            return true;
        } else {
            int node = root; assert parent(root) == NIL;
            int parent;
            int cmp;
            do {
                cmp = compare(node);
                if (cmp < 0) {
                    parent = node;
                    node = left(node);
                } else if (cmp > 0) {
                    parent = node;
                    node = right(node);
                } else {
                    merge(node);
                    return false;
                }
            } while (node != NIL);

            node = nodeAllocator.newNode();
            if (node >= capacity()) {
                resize(oversize(node + 1));
            }
            copy(node);
            parent(node, parent);
            if (cmp < 0) {
                left(parent, node);
            } else {
                assert cmp > 0;
                right(parent, node);
            }

            rebalance(node);

            return true;
        }
    }