AttributeListImpl.java 3.06 KB
/*
 * Decompiled with CFR 0_118.
 */
package com.day.crx.packaging.impl.proxy;

import com.day.crx.packaging.impl.proxy.AttributeList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

class AttributeListImpl
implements AttributeList {
    private final Map<String, Value> attributes = new LinkedHashMap<String, Value>();
    private boolean modified;

    AttributeListImpl() {
    }

    public void addAttribute(String name, String value, char quoteChar) {
        this.attributes.put(name.toLowerCase(), new Value(quoteChar, value));
    }

    public void addAttribute(String name, char quoteChar) {
        this.attributes.put(name.toLowerCase(), null);
    }

    public void reset() {
        this.attributes.clear();
        this.modified = false;
    }

    @Override
    public int attributeCount() {
        return this.attributes.size();
    }

    @Override
    public Iterator<String> attributeNames() {
        return this.attributes.keySet().iterator();
    }

    @Override
    public boolean containsAttribute(String name) {
        return this.attributes.containsKey(name.toLowerCase());
    }

    @Override
    public String getValue(String name) {
        Value value = this.getValueEx(name);
        if (value != null) {
            return value.value;
        }
        return null;
    }

    @Override
    public char getQuoteChar(String name) {
        Value value = this.getValueEx(name);
        if (value != null) {
            return value.quoteChar;
        }
        return '\u0000';
    }

    @Override
    public String getQuotedValue(String name) {
        Value value = this.getValueEx(name);
        if (value != null) {
            return value.toString();
        }
        return null;
    }

    @Override
    public void setValue(String name, String value) {
        if (value == null) {
            this.removeValue(name);
        } else {
            Value old = this.getValueEx(name);
            if (old == null) {
                this.addAttribute(name, value, '\"');
                this.modified = true;
            } else if (!old.value.equals(value)) {
                this.addAttribute(name, value, old.quoteChar);
                this.modified = true;
            }
        }
    }

    @Override
    public void removeValue(String name) {
        this.attributes.remove(name.toLowerCase());
        this.modified = true;
    }

    @Override
    public boolean isModified() {
        return this.modified;
    }

    protected Value getValueEx(String name) {
        return this.attributes.get(name.toLowerCase());
    }

    static class Value {
        public final char quoteChar;
        public final String value;
        private String stringRep;

        public Value(char quoteChar, String value) {
            this.quoteChar = quoteChar;
            this.value = value;
        }

        public String toString() {
            if (this.stringRep == null) {
                this.stringRep = "" + this.quoteChar + this.value + this.quoteChar;
            }
            return this.stringRep;
        }
    }

}