/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sample.scatterplot.persistence;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;

/**
 *
 * <p>Class that represents the samples of any real physical magnitude. Every sample
 * has the timestamp and the float measured value (you can think in sea level,
 * high of the waves, wind strength,...).</p>
 *
 * <p>This class will be extended by real magnitudes. And any entity must define
 * a query called <em>PLOT_TYPE_NAME-findSamplesBetweenDates</em> that searches
 * for samples between a start and end date. Besides any real plot must
 * be added to PloType enumeration.</p>
 *
 * Example:
 * <pre>
 * &#064;NamedQueries({
 * &#064;NamedQuery(name = "SEA_LEVEL-findSamplesBetweenDates",
 *   query = "SELECT s FROM SeaLevel AS s WHERE s.sampleDate > :begin AND s.sampleDate < :end"
 * )
 * &#125;)
 * </pre>
 *
 * @see PlotType
 * @author ricky
 */
@MappedSuperclass
public abstract class PlotSample implements Serializable {

    /**
     * sample timestamp
     */
    @Id
    @Column(name = "SDATE")
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    protected Date sampleDate = null;

    /**
     * sample value
     */
    @Column(name = "SVALUE", nullable=false)
    protected float sampleValue = 0.0f;

    /**
     * Empty constructor
     */
    public PlotSample() {
        sampleDate = new Date(new java.util.Date().getTime());
        sampleValue = 0.0f;
    }

    /**
     * Constructor via properties.
     * @param sampleDate The timestamp
     * @param sampleValue The value
     */
    public PlotSample(Date sampleDate, float sampleValue) {
        this.sampleDate = sampleDate;
        this.sampleValue = sampleValue;
    }

    /**
     * Every measured magnitude the application works with must
     * be represented by a PlotType. This abstract class returns the PlotTType
     * of the sample.
     * @return The PlotType of the sample.
     */
    abstract public PlotType getPlotType();

    /**
     * sampleDate getter
     * @return
     */
    public Date getSampleDate() {
        return sampleDate;
    }

    /**
     * sampleDate setter
     * @param sampleDate
     */
    public void setSampleDate(Date sampleDate) {
        this.sampleDate = sampleDate;
    }

    /**
     * sampleValue getter
     * @return
     */
    public float getSampleValue() {
        return sampleValue;
    }

    /**
     * sampleValue setter
     * @param sampleValue
     */
    public void setSampleValue(float sampleValue) {
        this.sampleValue = sampleValue;
    }

    /**
     *
     * @return
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (sampleDate != null ? sampleDate.hashCode() : 0);
        return hash;
    }

    /**
     *
     * @param object
     * @return
     */
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (object.getClass() != this.getClass()) {
            return false;
        }
        PlotSample other = (PlotSample) object;
        if ((this.sampleDate == null && other.sampleDate != null) ||
                (this.sampleDate != null && !this.sampleDate.equals(other.sampleDate))) {
            return false;
        }
        return true;
    }

    /**
     * 
     * @return
     */
    @Override
    public String toString() {
        return "sample.scatterplot.persistence.PlotSample[date=" + sampleDate + " value=" + sampleValue + "]";
    }

}

