package hep.aida.ref.remote;

/**
 * Implementation of IAnnotation.
 *
 * @author The AIDA Team at SLAC.
 *
 */
import hep.aida.*;
import hep.aida.ref.Annotation;
import java.util.Vector;
import java.util.Enumeration;

public class RemoteAnnotation extends Annotation{
    
    /**
     * Creates a new instance of Annotation.
     *
     */
    public RemoteAnnotation() {
        super();
    }
    
    /**
     * Add a key/value pair with a given visibility.
     *
     */
    public void addItem( String  key, String  value ) {
        addItem(key, value, false);
    }
    
    public void addItem( String  key, String  value, boolean sticky ) {
        if ( keyVector.contains(key) ) throw new IllegalArgumentException("Item "+key+" already exists");
        keyVector.add(key);
        valVector.add(value);
        stkVector.add(new Boolean(sticky));
    }
    
    /**
     * Remove the item indicated by a given key.
     *
     */
    public void removeItem( String  key ) {
        if ( ! keyVector.contains(key) ) throw new IllegalArgumentException("Item "+key+" does not exist");
        int index = keyVector.indexOf(key);
        if ( isSticky( index ) ) throw new IllegalArgumentException("Item "+key+" is sticky; it cannot be removed");
        keyVector.remove(index);
        valVector.remove(index);
        stkVector.remove(index); 
    }
    
    /**
     * Retrieve the value for a given key.
     * @return The value of the corresponding item.
     *
     */
    public String  value( String  key ) {
        if ( ! keyVector.contains(key) ) throw new IllegalArgumentException("Item "+key+" does not exist");
        int index = keyVector.indexOf(key);
        return (String)valVector.get(index);
    }
    
    /**
     * Set value for a given key.
     * @param key The item's key.
     * @param value The new value for the correponding item.
     *
     */
    public void setValue( String  key, String value ) {
        if ( ! keyVector.contains(key) ) throw new IllegalArgumentException("Item "+key+" does not exist");
        int index = keyVector.indexOf(key);
        valVector.set(index,value);
    }
    
    /**
     * Set stickyness for a given key.
     * @param key The item's key.
     * @param sticky The new stickyness for the correponding item.
     *
     */
    public void setSticky( String  key, boolean sticky ) {
        if ( ! keyVector.contains(key) ) throw new IllegalArgumentException("Item "+key+" does not exist");
        int index = keyVector.indexOf(key);
        stkVector.set(index, new Boolean(sticky));
    }
        
}
