axel/src/main/java/fr/xgouchet/xmleditor/core/model/TreeNode.java
public void insertChild(final @NonNull TreeNode<T> child, final int position) {

        // child already has a parent
        if (child.getParent() != null) {
            throw new UnsupportedOperationException("Cannot append child, it already has a parent");
        }

        // child is an ancestor (avoid weird families)
        if (isAncestor(child)) {
            throw new UnsupportedOperationException("Cannot append child, it is an ancestor of this node");
        }

        if (!mChildren.contains(child)) {
            boolean added;
            if (position >= mChildren.size()) {
                added = mChildren.add(child);
            } else {
                mChildren.add(position, child);
                added = true;
            }

            if (added) {
                child.setParent(this);
            }
        }
    }
/**
     * Attach a child to this node. The child will be ordered at the given position, if possible.
     * When inserting the given child, other children after the given position will be shifted to
     * make room for the new child.
     * <p/>
     * If there are not enough children, the child will be ordered after all existing children of
     * this node.
     *
     * @param child    the child to attach to this node (must not be null)
     * @param position the position to give the child in the children list.
     */
Attach a child to this node. The child will be ordered at the given position, if possible.
When inserting the given child, other children after the given position will be shifted to
make room for the new child.

If there are not enough children, the child will be ordered after all existing children of
this node.

@param child    the child to attach to this node (must not be null)
@param position the position to give the child in the children list.
Attach a child to this node . The child will be ordered at the given position if possible . When inserting the given child other children after the given position will be shifted to make room for the new child . If there are not enough children the child will be ordered after all existing children of this node . @param child the child to attach to this node ( must not be null ) @param position the position to give the child in the children list .
public void insertChild(final @NonNull TreeNode<T> child, final int position) {
        if (child.getParent() != null) {
            throw new UnsupportedOperationException("Cannot append child, it already has a parent");
        }
        if (isAncestor(child)) {
            throw new UnsupportedOperationException("Cannot append child, it is an ancestor of this node");
        }
        if (!mChildren.contains(child)) {
            boolean added;
            if (position >= mChildren.size()) {
                added = mChildren.add(child);
            } else {
                mChildren.add(position, child);
                added = true;
            }
            if (added) {
                child.setParent(this);
            }
        }
    }
public void insertChild ( final @ NonNull TreeNode < T > child , final int position ) { if ( child . getParent ( ) != null ) { throw new UnsupportedOperationException ( "Cannot append child, it already has a parent" ) ; } if ( isAncestor ( child ) ) { throw new UnsupportedOperationException ( "Cannot append child, it is an ancestor of this node" ) ; } if ( ! mChildren . contains ( child ) ) { boolean added ; if ( position >= mChildren . size ( ) ) { added = mChildren . add ( child ) ; } else { mChildren . add ( position , child ) ; added = true ; } if ( added ) { child . setParent ( this ) ; } } }
Attach a child to this node.
Attach a child to this node .
// child already has a parent // child is an ancestor (avoid weird families)