package genesom;

public abstract class DecayModel {

  protected boolean notinited = true;
  protected double span = Double.MAX_VALUE;
  protected double from = Double.MAX_VALUE;
  protected double to = Double.MAX_VALUE;
  protected double eta = 0.; // read e[x]t[r]a -Additional general purpose param

  protected double last   = Double.MAX_VALUE;
  protected double result = Double.MAX_VALUE;

  public void setSpan(double span) { this.span = span; }
  public void setFrom(double from) { this.from = from; }
  public void setTo(double to)     { this.to = to; }
  public void setEta(double eta)   { this.eta = eta; }

  public double getSpan() { return span; }
  public double getFrom() { return from; }
  public double getTo()   { return to; }
  public double getEta()  { return eta; }

  abstract protected double calcResult(double x);

  public double get(double x) {

    if(notinited) throw new RuntimeException(this.getClass().getName() +
                          " has not been initialized properly!");

    if(x != last) result = calcResult(last = x);

    return result;
  }


  public boolean init() {
    return notinited = (span == Double.MAX_VALUE || span <= 0. ||
                        from == Double.MAX_VALUE ||
                          to == Double.MAX_VALUE);
  }

  public String toString() {
    return getClass().getName() +
      ": [" + from + " : " + to + "] (" + eta + ") - " + span;
  }
}
