unl.cusack.estimator
Class EstimatorModel

java.lang.Object
  |
  +--unl.cusack.estimator.EstimatorModel
Direct Known Subclasses:
PiEstimatorModel

public abstract class EstimatorModel
extends java.lang.Object

The EstimatorModel is the model of an estimator. It is an abstract class, leaving the details of the estimator to the subclasses. The model assumes there is a formula f(i) to compute the ith estimate of the number to be estimated. The model stores the first index which is desired, the number of estimates to store, and the interval between intervals. For instance, if

  • numberOfEstimates=4
  • firstEstimate=3
  • estimateInterval=5 then the model will store f(3), f(8), f(13), and f(18).

    The model maintains a list of object which are registered as listeners to this class. If the model changes, this class will inform each of the registered listeners of the fact that the model has changed, leavinf it up to each of them what they want to do about it.


    Field Summary
    protected  double[] estimates
               
    protected  java.util.Set estimatorListeners
               
     
    Constructor Summary
    EstimatorModel()
              The constructor, assuming an empty model
     
    Method Summary
     void addEstimatorListener(EstimatorListener listener)
              Add a listener the the list
     void dataChanged()
              If any of the data in the model changes, this method takes care of recalculating the estimates, and informing the listeners of the fact that the model has changed.
     double getEstimate(int n)
              Get the nth estimate from the list
     int getEstimatorInterval()
               
     int getFirstEstimate()
              Get the index of the first stored estimate
     double getMaximumEstimate()
               
     double getMinimumEstimate()
               
     int getNumberOfEstimates()
               
    abstract  void recalculateEstimates()
               
     void setEstimateInterval(int n)
              Set the desired interval between estimates to n
     void setFirstEstimate(int n)
              Set the index of the first estimate to n
     void setNumberOfEstimates(int n)
              Sets the number of estimates to n
     void setParameters(int n, int f, int i)
              Set all of the parameters of the model
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    estimates

    protected double[] estimates

    estimatorListeners

    protected java.util.Set estimatorListeners
    Constructor Detail

    EstimatorModel

    public EstimatorModel()
    The constructor, assuming an empty model

    Method Detail

    recalculateEstimates

    public abstract void recalculateEstimates()

    getEstimate

    public double getEstimate(int n)
    Get the nth estimate from the list

    Parameters:
    n - the index of the desired estimate Note: This is asking for the nth estimate that is stored in the model, not f(n), where f is the function that computes the estimates.
    Returns:
    the nth estimate on the list. If n is not between 0 and numberOfEstimates, it returns 0. It should really throw and exception, but for simplicity, and since the point of the example is to demostrate MVC, not exception handling, simple is better.

    getMaximumEstimate

    public double getMaximumEstimate()
    Returns:
    the maximum of the stored estimates

    getMinimumEstimate

    public double getMinimumEstimate()

    getNumberOfEstimates

    public int getNumberOfEstimates()
    Returns:
    the number of stored estimates

    setNumberOfEstimates

    public void setNumberOfEstimates(int n)
    Sets the number of estimates to n

    Parameters:
    n - the number of desired estimates

    getFirstEstimate

    public int getFirstEstimate()
    Get the index of the first stored estimate

    Returns:
    the index of the first estimate

    setFirstEstimate

    public void setFirstEstimate(int n)
    Set the index of the first estimate to n

    Parameters:
    n - the desired index of the first estimate

    getEstimatorInterval

    public int getEstimatorInterval()
    Returns:
    the interval between estimates

    setEstimateInterval

    public void setEstimateInterval(int n)
    Set the desired interval between estimates to n

    Parameters:
    n - the desried interval between estimates.

    setParameters

    public void setParameters(int n,
                              int f,
                              int i)
    Set all of the parameters of the model

    Parameters:
    n - desired number of estimates
    f - desired index of first index
    i - desired interval between estimates

    addEstimatorListener

    public void addEstimatorListener(EstimatorListener listener)
    Add a listener the the list

    Parameters:
    listener - the object desiring to listen to this class

    dataChanged

    public void dataChanged()
    If any of the data in the model changes, this method takes care of recalculating the estimates, and informing the listeners of the fact that the model has changed.