/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  java.lang.Class
 *  java.lang.Comparable
 *  java.lang.Object
 *  java.lang.RuntimeException
 *  java.lang.String
 *  java.lang.StringBuffer
 *  java.util.Comparator
 */
package org.dom4j.util;

import java.util.Comparator;
import org.dom4j.Attribute;
import org.dom4j.Branch;
import org.dom4j.CDATA;
import org.dom4j.CharacterData;
import org.dom4j.Comment;
import org.dom4j.Document;
import org.dom4j.DocumentType;
import org.dom4j.Element;
import org.dom4j.Entity;
import org.dom4j.Namespace;
import org.dom4j.Node;
import org.dom4j.ProcessingInstruction;
import org.dom4j.QName;
import org.dom4j.Text;

public class NodeComparator
implements Comparator {
    /*
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    public int compare(Object object, Object object2) {
        int n = -1;
        if (object == object2) {
            return 0;
        }
        if (object == null) return n;
        if (object2 == null) {
            return 1;
        }
        if (object instanceof Node) {
            if (!(object2 instanceof Node)) return 1;
            return this.compare((Node)object, (Node)object2);
        }
        if (object2 instanceof Node) return n;
        if (!(object instanceof Comparable)) return object.getClass().getName().compareTo(object2.getClass().getName());
        return ((Comparable)object).compareTo(object2);
    }

    public int compare(String string2, String string3) {
        if (string2 == string3) {
            return 0;
        }
        if (string2 == null) {
            return -1;
        }
        if (string3 == null) {
            return 1;
        }
        return string2.compareTo(string3);
    }

    public int compare(Attribute attribute, Attribute attribute2) {
        int n = this.compare(attribute.getQName(), attribute2.getQName());
        if (n == 0) {
            n = this.compare(attribute.getValue(), attribute2.getValue());
        }
        return n;
    }

    public int compare(CharacterData characterData, CharacterData characterData2) {
        return this.compare(characterData.getText(), characterData2.getText());
    }

    public int compare(Document document, Document document2) {
        int n = this.compare(document.getDocType(), document2.getDocType());
        if (n == 0) {
            n = this.compareContent(document, document2);
        }
        return n;
    }

    /*
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    public int compare(DocumentType documentType, DocumentType documentType2) {
        if (documentType == documentType2) {
            return 0;
        }
        if (documentType == null) {
            return -1;
        }
        if (documentType2 == null) {
            return 1;
        }
        int n = this.compare(documentType.getPublicID(), documentType2.getPublicID());
        if (n != 0) return n;
        n = this.compare(documentType.getSystemID(), documentType2.getSystemID());
        if (n != 0) return n;
        return this.compare(documentType.getName(), documentType2.getName());
    }

    public int compare(Element element, Element element2) {
        int n;
        int n2 = this.compare(element.getQName(), element2.getQName());
        if (n2 == 0 && (n2 = (n = element.attributeCount()) - element2.attributeCount()) == 0) {
            for (int i = 0; i < n; ++i) {
                Attribute attribute = element.attribute(i);
                int n3 = this.compare(attribute, element2.attribute(attribute.getQName()));
                if (n3 == 0) continue;
                return n3;
            }
            n2 = this.compareContent(element, element2);
        }
        return n2;
    }

    public int compare(Entity entity, Entity entity2) {
        int n = this.compare(entity.getName(), entity2.getName());
        if (n == 0) {
            n = this.compare(entity.getText(), entity2.getText());
        }
        return n;
    }

    public int compare(Namespace namespace, Namespace namespace2) {
        int n = this.compare(namespace.getURI(), namespace2.getURI());
        if (n == 0) {
            n = this.compare(namespace.getPrefix(), namespace2.getPrefix());
        }
        return n;
    }

    public int compare(Node node, Node node2) {
        short s = node.getNodeType();
        int n = s - node2.getNodeType();
        if (n != 0) {
            return n;
        }
        switch (s) {
            default: {
                throw new RuntimeException(new StringBuffer().append("Invalid node types. node1: ").append((Object)node).append(" and node2: ").append((Object)node2).toString());
            }
            case 1: {
                return this.compare((Element)node, (Element)node2);
            }
            case 9: {
                return this.compare((Document)node, (Document)node2);
            }
            case 2: {
                return this.compare((Attribute)node, (Attribute)node2);
            }
            case 3: {
                return this.compare((Text)node, (Text)node2);
            }
            case 4: {
                return this.compare((CDATA)node, (CDATA)node2);
            }
            case 5: {
                return this.compare((Entity)node, (Entity)node2);
            }
            case 7: {
                return this.compare((ProcessingInstruction)node, (ProcessingInstruction)node2);
            }
            case 8: {
                return this.compare((Comment)node, (Comment)node2);
            }
            case 10: {
                return this.compare((DocumentType)node, (DocumentType)node2);
            }
            case 13: 
        }
        return this.compare((Namespace)node, (Namespace)node2);
    }

    public int compare(ProcessingInstruction processingInstruction, ProcessingInstruction processingInstruction2) {
        int n = this.compare(processingInstruction.getTarget(), processingInstruction2.getTarget());
        if (n == 0) {
            n = this.compare(processingInstruction.getText(), processingInstruction2.getText());
        }
        return n;
    }

    public int compare(QName qName, QName qName2) {
        int n = this.compare(qName.getNamespaceURI(), qName2.getNamespaceURI());
        if (n == 0) {
            n = this.compare(qName.getQualifiedName(), qName2.getQualifiedName());
        }
        return n;
    }

    /*
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    public int compareContent(Branch branch, Branch branch2) {
        int n = branch.nodeCount();
        int n2 = n - branch2.nodeCount();
        if (n2 != 0) return n2;
        int n3 = 0;
        while (n3 < n) {
            n2 = this.compare(branch.node(n3), branch2.node(n3));
            if (n2 != 0) {
                return n2;
            }
            ++n3;
        }
        return n2;
    }
}

