/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  java.lang.IndexOutOfBoundsException
 *  java.lang.Object
 *  java.lang.String
 *  java.lang.StringBuffer
 *  java.util.ArrayList
 *  java.util.Collection
 *  java.util.Iterator
 *  java.util.List
 */
package org.dom4j.tree;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.dom4j.IllegalAddException;
import org.dom4j.Node;
import org.dom4j.tree.AbstractBranch;

public class BackedList
extends ArrayList {
    private AbstractBranch branch;
    private List branchContent;

    public BackedList(AbstractBranch abstractBranch, List list) {
        super(abstractBranch, list, list.size());
    }

    public BackedList(AbstractBranch abstractBranch, List list, int n) {
        super(n);
        this.branch = abstractBranch;
        this.branchContent = list;
    }

    public BackedList(AbstractBranch abstractBranch, List list, List list2) {
        super((Collection)list2);
        this.branch = abstractBranch;
        this.branchContent = list;
    }

    /*
     * Enabled aggressive block sorting
     */
    public void add(int n, Object object) {
        int n2 = this.size();
        if (n < 0) {
            throw new IndexOutOfBoundsException(new StringBuffer().append("Index value: ").append(n).append(" is less than zero").toString());
        }
        if (n > n2) {
            throw new IndexOutOfBoundsException(new StringBuffer().append("Index value: ").append(n).append(" cannot be greater than ").append("the size: ").append(n2).toString());
        }
        int n3 = n2 == 0 ? this.branchContent.size() : (n < n2 ? this.branchContent.indexOf(this.get(n)) : 1 + this.branchContent.indexOf(this.get(n2 - 1)));
        this.branch.addNode(n3, this.asNode(object));
        super.add(n, object);
    }

    public boolean add(Object object) {
        this.branch.addNode(this.asNode(object));
        return super.add(object);
    }

    public boolean addAll(int n, Collection collection) {
        this.ensureCapacity(this.size() + collection.size());
        int n2 = this.size();
        Iterator iterator = collection.iterator();
        while (iterator.hasNext()) {
            int n3 = n + 1;
            this.add(n, iterator.next());
            --n2;
            n = n3;
        }
        if (n2 != 0) {
            return true;
        }
        return false;
    }

    public boolean addAll(Collection collection) {
        this.ensureCapacity(this.size() + collection.size());
        int n = this.size();
        Iterator iterator = collection.iterator();
        while (iterator.hasNext()) {
            this.add(iterator.next());
            --n;
        }
        if (n != 0) {
            return true;
        }
        return false;
    }

    public void addLocal(Object object) {
        super.add(object);
    }

    protected Node asNode(Object object) {
        if (object instanceof Node) {
            return (Node)object;
        }
        throw new IllegalAddException(new StringBuffer().append("This list must contain instances of Node. Invalid type: ").append(object).toString());
    }

    public void clear() {
        Iterator iterator = this.iterator();
        while (iterator.hasNext()) {
            Object object = iterator.next();
            this.branchContent.remove(object);
            this.branch.childRemoved(this.asNode(object));
        }
        super.clear();
    }

    public Object remove(int n) {
        Object object = super.remove(n);
        if (object != null) {
            this.branch.removeNode(this.asNode(object));
        }
        return object;
    }

    public boolean remove(Object object) {
        this.branch.removeNode(this.asNode(object));
        return super.remove(object);
    }

    /*
     * Enabled aggressive block sorting
     */
    public Object set(int n, Object object) {
        int n2 = this.branchContent.indexOf(this.get(n));
        if (n2 < 0) {
            n2 = n == 0 ? 0 : Integer.MAX_VALUE;
        }
        if (n2 < this.branchContent.size()) {
            this.branch.removeNode(this.asNode(this.get(n)));
            this.branch.addNode(n2, this.asNode(object));
        } else {
            this.branch.removeNode(this.asNode(this.get(n)));
            this.branch.addNode(this.asNode(object));
        }
        this.branch.childAdded(this.asNode(object));
        return super.set(n, object);
    }
}

