package hr.fer.labust.diverapp.agent;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AttributeList {
    private List<String> mAttributeNames;
    private Map<String, Attribute> mAttributes;

    AttributeList() {
        mAttributeNames = new ArrayList<>();
        mAttributes = new HashMap<>();
    }

    public void put (String name, String value) {
        if (mAttributeNames.contains(name)) {
            ((Attribute)mAttributes.get(name)).setValue(value);
        }
        else {
            mAttributeNames.add(name);
            mAttributes.put(name, new Attribute(name, value));
        }
    }

    public void remove(String name) {
        mAttributeNames.remove(name);
        mAttributes.remove(name);
    }

    public boolean contains(String name) {
        return mAttributeNames.contains(name);
    }

    public int size() {
        return mAttributeNames.size();
    }

    public Attribute get(int index) {
        return mAttributes.get(mAttributeNames.get(index));
    }

    public Attribute get(String name) {
        return mAttributes.get(name);
    }

    public String getName(int index) {
        return mAttributes.get(mAttributeNames.get(index)).getName();
    }

    public String getName(String name) {
        return mAttributes.get(name).getName();
    }

    public String getValue(int index) {
        return mAttributes.get(mAttributeNames.get(index)).getValue();
    }

    public String getValue(String name) {
        return mAttributes.get(name).getValue();
    }
}
