package hep.aida.ref.histogram;

/**
 * Implementation of IBaseHistogram.
 *
 * @author The AIDA Team at SLAC.
 *
 */
import hep.aida.*;
import hep.aida.ref.*;

public abstract class AbstractBaseHistogram extends ManagedObject implements IBaseHistogram {
    
    private int dimension;
    private IAnnotation annotation = new Annotation();
    
    /** 
     * Creates a new instance of BaseHistogram.
     * @param name The name of the BaseHistogram. See ManagedObject for details.
     * @param title The title of the BaseHistogram.
     * @param dimension The dimension of the BaseHistogram.
     *
     */
    public AbstractBaseHistogram(String name, String title, int dimension) {
        super(name);
        this.dimension = dimension;
        annotation.addItem(Annotation.titleKey,title,true);
    }

    /**
     * Get the histogram title.
     * @return the Histogram title.
     *
     */
    public String title() {
        String title =  annotation.value(Annotation.titleKey);
        if ( title == null ) 
            title = "";
        return title;
    }
    
    /**
     * Set the histogram title.
     * @param title The title.
     *
     */
    public void setTitle(String title) {
        if ( title == null )
            title = "";
        annotation.setValue(Annotation.titleKey,title);
    }
    
    /**
     * Get the IAnnotation associated with the histogram.
     * @return The IAnnotation.
     *
     */
    public IAnnotation annotation() {
        return annotation;
    }
    
    public void setAnnotation( IAnnotation annotation ) {
        this.annotation = annotation;
    }
    
    /**
     * Get the dimension of the histogram.
     *
     */
    public int dimension() {
        return dimension;
    }
    
    /**
     * Reset the histogram; as if just created.
     *
     */
    public void reset() {
        annotation.reset();
    }
    
    /**
     * Number of in-range entries in the histogram.
     * @return The number of in-range entries.
     *
     */
    abstract public int entries();
    
}
