/***************************************************************
 * Source: @(#)$Id$
 * Scope:  Counter class
 *
 *  12/16/1999  GVT  First Implementation
 ***************************************************************/

package counter.models;

import gvt.mvc.*;

/**
 * This class implements the model of a
 * Counter
 *
 * @author   Giuseppe Vitillaro
 * @version  $Id$
 */
public class Counter extends Model {
    private int n;

    /**
     * The Constructor: it resets the counter;
     */
    public Counter ( ) {
	reset();
    }


    /**
     * increments the counter
     */
    public void incr ( ) {
	n++;
	setChanged();
	notifyViews();
    }

    /**
     * decrements the counter
     */
    public void decr ( ) {
	n--;
	setChanged();
	notifyViews();
    }
    

    /**
     * resets the counter to zero
     */
    public void reset ( ) {
	n = 0;
	setChanged();
	notifyViews();
    }

    /**
     * set the counter to a given value
     */
    public void set ( Number n ) {
	this.n = n.intValue();
	setChanged();
	notifyViews();
    }

    /**
     * get the value of the counter
     */
    public Number get ( ) {
	return new Integer(n);
    }
}
