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

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.dom4j.Attribute;
import org.dom4j.Branch;
import org.dom4j.Document;
import org.dom4j.DocumentFactory;
import org.dom4j.Element;
import org.dom4j.IllegalAddException;
import org.dom4j.Namespace;
import org.dom4j.Node;
import org.dom4j.ProcessingInstruction;
import org.dom4j.QName;
import org.dom4j.Text;
import org.dom4j.tree.AbstractBranch;
import org.dom4j.tree.AbstractElement;
import org.dom4j.tree.BackedList;
import org.dom4j.tree.ContentListFacade;
import org.dom4j.tree.DefaultText;

public class DefaultElement
extends AbstractElement {
    private static final transient DocumentFactory DOCUMENT_FACTORY = DocumentFactory.getInstance();
    private Object attributes;
    private Object content;
    private Branch parentBranch;
    private QName qname;

    public DefaultElement(String string2) {
        this.qname = DOCUMENT_FACTORY.createQName(string2);
    }

    public DefaultElement(String string2, Namespace namespace) {
        this.qname = DOCUMENT_FACTORY.createQName(string2, namespace);
    }

    public DefaultElement(QName qName) {
        this.qname = qName;
    }

    public DefaultElement(QName qName, int n) {
        this.qname = qName;
        if (n > 1) {
            this.attributes = new ArrayList(n);
        }
    }

    /*
     * Enabled aggressive block sorting
     */
    @Override
    public void add(Attribute attribute) {
        if (attribute.getParent() != null) {
            throw new IllegalAddException((Element)this, (Node)attribute, new StringBuffer().append("The Attribute already has an existing parent \"").append(attribute.getParent().getQualifiedName()).append("\"").toString());
        }
        if (attribute.getValue() == null) {
            Attribute attribute2 = this.attribute(attribute.getQName());
            if (attribute2 != null) {
                this.remove(attribute2);
            }
            return;
        }
        if (this.attributes == null) {
            this.attributes = attribute;
        } else {
            this.attributeList().add((Object)attribute);
        }
        this.childAdded(attribute);
    }

    /*
     * Enabled aggressive block sorting
     */
    @Override
    protected void addNewNode(Node node) {
        Object object = this.content;
        if (object == null) {
            this.content = node;
        } else if (object instanceof List) {
            ((List)object).add((Object)node);
        } else {
            List list = this.createContentList();
            list.add(object);
            list.add((Object)node);
            this.content = list;
        }
        this.childAdded(node);
    }

    /*
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    @Override
    public List additionalNamespaces() {
        Object object = this.content;
        if (object instanceof List) {
            List list = (List)object;
            int n = list.size();
            BackedList backedList = this.createResultList();
            int n2 = 0;
            while (n2 < n) {
                Namespace namespace;
                Object object2 = list.get(n2);
                if (object2 instanceof Namespace && !(namespace = (Namespace)object2).equals(this.getNamespace())) {
                    backedList.addLocal(namespace);
                }
                ++n2;
            }
            return backedList;
        }
        if (!(object instanceof Namespace)) return this.createEmptyList();
        Namespace namespace = (Namespace)object;
        if (!namespace.equals(this.getNamespace())) return this.createSingleResultList(namespace);
        return this.createEmptyList();
    }

    /*
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    @Override
    public List additionalNamespaces(String string2) {
        Object object = this.content;
        if (object instanceof List) {
            List list = (List)object;
            BackedList backedList = this.createResultList();
            int n = list.size();
            int n2 = 0;
            while (n2 < n) {
                Namespace namespace;
                Object object2 = list.get(n2);
                if (object2 instanceof Namespace && !string2.equals((Object)(namespace = (Namespace)object2).getURI())) {
                    backedList.addLocal(namespace);
                }
                ++n2;
            }
            return backedList;
        }
        if (!(object instanceof Namespace)) return this.createEmptyList();
        Namespace namespace = (Namespace)object;
        if (string2.equals((Object)namespace.getURI())) return this.createEmptyList();
        return this.createSingleResultList(namespace);
    }

    @Override
    public Attribute attribute(int n) {
        Object object = this.attributes;
        if (object instanceof List) {
            return (Attribute)((List)object).get(n);
        }
        if (object != null && n == 0) {
            return (Attribute)object;
        }
        return null;
    }

    /*
     * Enabled aggressive block sorting
     */
    @Override
    public Attribute attribute(String string2) {
        Attribute attribute;
        Object object = this.attributes;
        if (object instanceof List) {
            List list = (List)object;
            int n = list.size();
            int n2 = 0;
            while (n2 < n) {
                attribute = (Attribute)list.get(n2);
                if (string2.equals((Object)attribute.getName())) return attribute;
                {
                    ++n2;
                    continue;
                }
            }
            return null;
        }
        if (object == null || !string2.equals((Object)(attribute = (Attribute)object).getName())) return null;
        return attribute;
    }

    @Override
    public Attribute attribute(String string2, Namespace namespace) {
        return this.attribute(this.getDocumentFactory().createQName(string2, namespace));
    }

    /*
     * Enabled aggressive block sorting
     */
    @Override
    public Attribute attribute(QName qName) {
        Attribute attribute;
        Object object = this.attributes;
        if (object instanceof List) {
            List list = (List)object;
            int n = list.size();
            int n2 = 0;
            while (n2 < n) {
                attribute = (Attribute)list.get(n2);
                if (qName.equals(attribute.getQName())) return attribute;
                {
                    ++n2;
                    continue;
                }
            }
            return null;
        }
        if (object == null || !qName.equals((attribute = (Attribute)object).getQName())) return null;
        return attribute;
    }

    @Override
    public int attributeCount() {
        Object object = this.attributes;
        if (object instanceof List) {
            return ((List)object).size();
        }
        if (object != null) {
            return 1;
        }
        return 0;
    }

    @Override
    public Iterator attributeIterator() {
        Object object = this.attributes;
        if (object instanceof List) {
            return ((List)object).iterator();
        }
        if (object != null) {
            return this.createSingleIterator(object);
        }
        return EMPTY_ITERATOR;
    }

    @Override
    protected List attributeList() {
        List list;
        Object object = this.attributes;
        if (object instanceof List) {
            return (List)object;
        }
        if (object != null) {
            List list2 = this.createAttributeList();
            list2.add(object);
            this.attributes = list2;
            return list2;
        }
        this.attributes = list = this.createAttributeList();
        return list;
    }

    @Override
    protected List attributeList(int n) {
        List list;
        Object object = this.attributes;
        if (object instanceof List) {
            return (List)object;
        }
        if (object != null) {
            List list2 = this.createAttributeList(n);
            list2.add(object);
            this.attributes = list2;
            return list2;
        }
        this.attributes = list = this.createAttributeList(n);
        return list;
    }

    @Override
    public List attributes() {
        return new ContentListFacade(this, this.attributeList());
    }

    @Override
    public void clearContent() {
        if (this.content != null) {
            this.contentRemoved();
            this.content = null;
        }
    }

    @Override
    public Object clone() {
        DefaultElement defaultElement = (DefaultElement)super.clone();
        if (defaultElement != this) {
            defaultElement.content = null;
            defaultElement.attributes = null;
            defaultElement.appendAttributes(this);
            defaultElement.appendContent(this);
        }
        return defaultElement;
    }

    @Override
    protected List contentList() {
        Object object = this.content;
        if (object instanceof List) {
            return (List)object;
        }
        List list = this.createContentList();
        if (object != null) {
            list.add(object);
        }
        this.content = list;
        return list;
    }

    @Override
    public List declaredNamespaces() {
        BackedList backedList = this.createResultList();
        Object object = this.content;
        if (object instanceof List) {
            List list = (List)object;
            int n = list.size();
            for (int i = 0; i < n; ++i) {
                Object object2 = list.get(i);
                if (!(object2 instanceof Namespace)) continue;
                backedList.addLocal(object2);
            }
        } else if (object instanceof Namespace) {
            backedList.addLocal(object);
        }
        return backedList;
    }

    /*
     * Enabled aggressive block sorting
     */
    @Override
    public Element element(String string2) {
        Element element;
        Object object = this.content;
        if (object instanceof List) {
            List list = (List)object;
            int n = list.size();
            int n2 = 0;
            while (n2 < n) {
                Object object2 = list.get(n2);
                if (object2 instanceof Element && string2.equals((Object)(element = (Element)object2).getName())) return element;
                {
                    ++n2;
                    continue;
                }
            }
            return null;
        }
        if (!(object instanceof Element) || !string2.equals((Object)(element = (Element)object).getName())) return null;
        return element;
    }

    @Override
    public Element element(String string2, Namespace namespace) {
        return this.element(this.getDocumentFactory().createQName(string2, namespace));
    }

    /*
     * Enabled aggressive block sorting
     */
    @Override
    public Element element(QName qName) {
        Element element;
        Object object = this.content;
        if (object instanceof List) {
            List list = (List)object;
            int n = list.size();
            int n2 = 0;
            while (n2 < n) {
                Object object2 = list.get(n2);
                if (object2 instanceof Element && qName.equals((element = (Element)object2).getQName())) return element;
                {
                    ++n2;
                    continue;
                }
            }
            return null;
        }
        if (!(object instanceof Element) || !qName.equals((element = (Element)object).getQName())) return null;
        return element;
    }

    @Override
    public Document getDocument() {
        if (this.parentBranch instanceof Document) {
            return (Document)this.parentBranch;
        }
        if (this.parentBranch instanceof Element) {
            return ((Element)this.parentBranch).getDocument();
        }
        return null;
    }

    @Override
    protected DocumentFactory getDocumentFactory() {
        DocumentFactory documentFactory = this.qname.getDocumentFactory();
        if (documentFactory != null) {
            return documentFactory;
        }
        return DOCUMENT_FACTORY;
    }

    /*
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    @Override
    public Namespace getNamespaceForPrefix(String string2) {
        Element element;
        Namespace namespace;
        Namespace namespace2;
        if (string2 == null) {
            string2 = "";
        }
        if (string2.equals((Object)this.getNamespacePrefix())) {
            return this.getNamespace();
        }
        if (string2.equals((Object)"xml")) {
            return Namespace.XML_NAMESPACE;
        }
        Object object = this.content;
        if (object instanceof List) {
            List list = (List)object;
            int n = list.size();
            for (int i = 0; i < n; ++i) {
                Object object2 = list.get(i);
                if (!(object2 instanceof Namespace)) continue;
                namespace2 = (Namespace)object2;
                if (string2.equals((Object)namespace2.getPrefix())) return namespace2;
            }
        } else if (object instanceof Namespace) {
            namespace2 = (Namespace)object;
            if (string2.equals((Object)namespace2.getPrefix())) return namespace2;
        }
        if ((element = this.getParent()) != null && (namespace = element.getNamespaceForPrefix(string2)) != null) {
            return namespace;
        }
        if (string2 == null) return Namespace.NO_NAMESPACE;
        if (string2.length() > 0) return null;
        return Namespace.NO_NAMESPACE;
    }

    /*
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    @Override
    public Namespace getNamespaceForURI(String string2) {
        Namespace namespace;
        Element element;
        if (string2 == null) return Namespace.NO_NAMESPACE;
        if (string2.length() <= 0) {
            return Namespace.NO_NAMESPACE;
        }
        if (string2.equals((Object)this.getNamespaceURI())) {
            return this.getNamespace();
        }
        Object object = this.content;
        if (object instanceof List) {
            List list = (List)object;
            int n = list.size();
            for (int i = 0; i < n; ++i) {
                Object object2 = list.get(i);
                if (!(object2 instanceof Namespace)) continue;
                namespace = (Namespace)object2;
                if (string2.equals((Object)namespace.getURI())) return namespace;
            }
        } else if (object instanceof Namespace) {
            namespace = (Namespace)object;
            if (string2.equals((Object)namespace.getURI())) return namespace;
        }
        if ((element = this.getParent()) == null) return null;
        return element.getNamespaceForURI(string2);
    }

    @Override
    public Element getParent() {
        boolean bl = this.parentBranch instanceof Element;
        Element element = null;
        if (bl) {
            element = (Element)this.parentBranch;
        }
        return element;
    }

    @Override
    public QName getQName() {
        return this.qname;
    }

    @Override
    public String getStringValue() {
        Object object = this.content;
        if (object instanceof List) {
            List list = (List)object;
            int n = list.size();
            if (n > 0) {
                if (n == 1) {
                    return this.getContentAsStringValue(list.get(0));
                }
                StringBuffer stringBuffer = new StringBuffer();
                for (int i = 0; i < n; ++i) {
                    String string2 = this.getContentAsStringValue(list.get(i));
                    if (string2.length() <= 0) continue;
                    stringBuffer.append(string2);
                }
                return stringBuffer.toString();
            }
        } else if (object != null) {
            return this.getContentAsStringValue(object);
        }
        return "";
    }

    @Override
    public String getText() {
        Object object = this.content;
        if (object instanceof List) {
            return super.getText();
        }
        if (object != null) {
            return this.getContentAsText(object);
        }
        return "";
    }

    @Override
    public int indexOf(Node node) {
        Object object = this.content;
        if (object instanceof List) {
            return ((List)object).indexOf((Object)node);
        }
        if (object != null && object.equals((Object)node)) {
            return 0;
        }
        return -1;
    }

    /*
     * Enabled aggressive block sorting
     * Lifted jumps to return sites
     */
    @Override
    public Node node(int n) {
        Object object;
        if (n < 0) return null;
        Object object2 = this.content;
        if (object2 instanceof List) {
            List list = (List)object2;
            if (n >= list.size()) {
                return null;
            }
            object = list.get(n);
        } else {
            if (n != 0) return null;
            object = object2;
        }
        if (object == null) return null;
        if (!(object instanceof Node)) return new DefaultText(object.toString());
        return (Node)object;
    }

    @Override
    public int nodeCount() {
        Object object = this.content;
        if (object instanceof List) {
            return ((List)object).size();
        }
        if (object != null) {
            return 1;
        }
        return 0;
    }

    @Override
    public Iterator nodeIterator() {
        Object object = this.content;
        if (object instanceof List) {
            return ((List)object).iterator();
        }
        if (object != null) {
            return this.createSingleIterator(object);
        }
        return EMPTY_ITERATOR;
    }

    /*
     * Enabled aggressive block sorting
     */
    @Override
    public ProcessingInstruction processingInstruction(String string2) {
        ProcessingInstruction processingInstruction;
        Object object = this.content;
        if (object instanceof List) {
            List list = (List)object;
            int n = list.size();
            int n2 = 0;
            while (n2 < n) {
                Object object2 = list.get(n2);
                if (object2 instanceof ProcessingInstruction && string2.equals((Object)(processingInstruction = (ProcessingInstruction)object2).getName())) return processingInstruction;
                {
                    ++n2;
                    continue;
                }
            }
            return null;
        }
        if (!(object instanceof ProcessingInstruction) || !string2.equals((Object)(processingInstruction = (ProcessingInstruction)object).getName())) return null;
        return processingInstruction;
    }

    /*
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    @Override
    public List processingInstructions() {
        Object object = this.content;
        if (object instanceof List) {
            List list = (List)object;
            BackedList backedList = this.createResultList();
            int n = list.size();
            int n2 = 0;
            while (n2 < n) {
                Object object2 = list.get(n2);
                if (object2 instanceof ProcessingInstruction) {
                    backedList.addLocal(object2);
                }
                ++n2;
            }
            return backedList;
        }
        if (!(object instanceof ProcessingInstruction)) return this.createEmptyList();
        return this.createSingleResultList(object);
    }

    /*
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    @Override
    public List processingInstructions(String string2) {
        Object object = this.content;
        if (object instanceof List) {
            List list = (List)object;
            BackedList backedList = this.createResultList();
            int n = list.size();
            int n2 = 0;
            while (n2 < n) {
                ProcessingInstruction processingInstruction;
                Object object2 = list.get(n2);
                if (object2 instanceof ProcessingInstruction && string2.equals((Object)(processingInstruction = (ProcessingInstruction)object2).getName())) {
                    backedList.addLocal(processingInstruction);
                }
                ++n2;
            }
            return backedList;
        }
        if (!(object instanceof ProcessingInstruction)) return this.createEmptyList();
        ProcessingInstruction processingInstruction = (ProcessingInstruction)object;
        if (!string2.equals((Object)processingInstruction.getName())) return this.createEmptyList();
        return this.createSingleResultList(processingInstruction);
    }

    /*
     * Enabled aggressive block sorting
     */
    @Override
    public boolean remove(Attribute attribute) {
        boolean bl;
        Object object = this.attributes;
        if (object instanceof List) {
            Attribute attribute2;
            List list = (List)object;
            bl = list.remove((Object)attribute);
            if (!bl && (attribute2 = this.attribute(attribute.getQName())) != null) {
                list.remove((Object)attribute2);
                bl = true;
            }
        } else {
            bl = false;
            if (object != null) {
                if (attribute.equals(object)) {
                    this.attributes = null;
                    bl = true;
                } else {
                    Attribute attribute3 = (Attribute)object;
                    boolean bl2 = attribute.getQName().equals(attribute3.getQName());
                    bl = false;
                    if (bl2) {
                        this.attributes = null;
                        bl = true;
                    }
                }
            }
        }
        if (bl) {
            this.childRemoved(attribute);
        }
        return bl;
    }

    /*
     * Enabled aggressive block sorting
     */
    @Override
    protected boolean removeNode(Node node) {
        Object object = this.content;
        boolean bl = false;
        if (object != null) {
            if (object == node) {
                this.content = null;
                bl = true;
            } else {
                boolean bl2 = object instanceof List;
                bl = false;
                if (bl2) {
                    bl = ((List)object).remove((Object)node);
                }
            }
        }
        if (bl) {
            this.childRemoved(node);
        }
        return bl;
    }

    @Override
    public boolean removeProcessingInstruction(String string2) {
        Object object = this.content;
        if (object instanceof List) {
            Iterator iterator = ((List)object).iterator();
            while (iterator.hasNext()) {
                Object object2 = iterator.next();
                if (!(object2 instanceof ProcessingInstruction) || !string2.equals((Object)((ProcessingInstruction)object2).getName())) continue;
                iterator.remove();
                return true;
            }
        } else if (object instanceof ProcessingInstruction && string2.equals((Object)((ProcessingInstruction)object).getName())) {
            this.content = null;
            return true;
        }
        return false;
    }

    protected void setAttributeList(List list) {
        this.attributes = list;
    }

    @Override
    public void setAttributes(List list) {
        if (list instanceof ContentListFacade) {
            list = ((ContentListFacade)list).getBackingList();
        }
        this.attributes = list;
    }

    /*
     * Enabled aggressive block sorting
     */
    @Override
    public void setContent(List list) {
        this.contentRemoved();
        if (list instanceof ContentListFacade) {
            list = ((ContentListFacade)list).getBackingList();
        }
        if (list == null) {
            this.content = null;
            return;
        }
        int n = list.size();
        List list2 = this.createContentList(n);
        int n2 = 0;
        do {
            if (n2 >= n) {
                this.content = list2;
                return;
            }
            Object object = list.get(n2);
            if (object instanceof Node) {
                Node node = (Node)object;
                Element element = node.getParent();
                if (element != null && element != this) {
                    node = (Node)node.clone();
                }
                list2.add((Object)node);
                this.childAdded(node);
            } else if (object != null) {
                String string2 = object.toString();
                Text text = this.getDocumentFactory().createText(string2);
                list2.add((Object)text);
                this.childAdded(text);
            }
            ++n2;
        } while (true);
    }

    @Override
    public void setDocument(Document document) {
        if (this.parentBranch instanceof Document || document != null) {
            this.parentBranch = document;
        }
    }

    @Override
    public void setParent(Element element) {
        if (this.parentBranch instanceof Element || element != null) {
            this.parentBranch = element;
        }
    }

    @Override
    public void setQName(QName qName) {
        this.qname = qName;
    }

    @Override
    public boolean supportsParent() {
        return true;
    }
}

