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

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import org.dom4j.DocumentFactory;
import org.dom4j.Namespace;
import org.dom4j.QName;

public class QNameCache {
    private DocumentFactory documentFactory;
    protected Map namespaceCache;
    protected Map noNamespaceCache;

    public QNameCache() {
        this.noNamespaceCache = Collections.synchronizedMap((Map)new WeakHashMap());
        this.namespaceCache = Collections.synchronizedMap((Map)new WeakHashMap());
    }

    public QNameCache(DocumentFactory documentFactory) {
        this.noNamespaceCache = Collections.synchronizedMap((Map)new WeakHashMap());
        this.namespaceCache = Collections.synchronizedMap((Map)new WeakHashMap());
        this.documentFactory = documentFactory;
    }

    protected Map createMap() {
        return Collections.synchronizedMap((Map)new HashMap());
    }

    protected QName createQName(String string2) {
        return new QName(string2);
    }

    protected QName createQName(String string2, Namespace namespace) {
        return new QName(string2, namespace);
    }

    protected QName createQName(String string2, Namespace namespace, String string3) {
        return new QName(string2, namespace, string3);
    }

    /*
     * Enabled aggressive block sorting
     */
    public QName get(String string2) {
        QName qName;
        if (string2 != null) {
            qName = (QName)this.noNamespaceCache.get((Object)string2);
        } else {
            string2 = "";
            qName = null;
        }
        if (qName == null) {
            qName = this.createQName(string2);
            qName.setDocumentFactory(this.documentFactory);
            this.noNamespaceCache.put((Object)string2, (Object)qName);
        }
        return qName;
    }

    public QName get(String string2, String string3) {
        int n = string2.indexOf(58);
        if (n < 0) {
            return this.get(string2, Namespace.get(string3));
        }
        return this.get(string2.substring(n + 1), Namespace.get(string2.substring(0, n), string3));
    }

    /*
     * Enabled aggressive block sorting
     */
    public QName get(String string2, Namespace namespace) {
        QName qName;
        Map map = this.getNamespaceCache(namespace);
        if (string2 != null) {
            qName = (QName)map.get((Object)string2);
        } else {
            string2 = "";
            qName = null;
        }
        if (qName == null) {
            qName = this.createQName(string2, namespace);
            qName.setDocumentFactory(this.documentFactory);
            map.put((Object)string2, (Object)qName);
        }
        return qName;
    }

    /*
     * Enabled aggressive block sorting
     */
    public QName get(String string2, Namespace namespace, String string3) {
        QName qName;
        Map map = this.getNamespaceCache(namespace);
        if (string2 != null) {
            qName = (QName)map.get((Object)string2);
        } else {
            string2 = "";
            qName = null;
        }
        if (qName == null) {
            qName = this.createQName(string2, namespace, string3);
            qName.setDocumentFactory(this.documentFactory);
            map.put((Object)string2, (Object)qName);
        }
        return qName;
    }

    /*
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    protected Map getNamespaceCache(Namespace namespace) {
        if (namespace == Namespace.NO_NAMESPACE) {
            return this.noNamespaceCache;
        }
        Map map = null;
        if (namespace != null) {
            map = (Map)this.namespaceCache.get((Object)namespace);
            if (map != null) return map;
        }
        Map map2 = this.createMap();
        this.namespaceCache.put((Object)namespace, (Object)map2);
        return map2;
    }

    public List getQNames() {
        ArrayList arrayList = new ArrayList();
        arrayList.addAll(this.noNamespaceCache.values());
        Iterator iterator = this.namespaceCache.values().iterator();
        while (iterator.hasNext()) {
            arrayList.addAll(((Map)iterator.next()).values());
        }
        return arrayList;
    }

    public QName intern(QName qName) {
        return this.get(qName.getName(), qName.getNamespace(), qName.getQualifiedName());
    }
}

