head	1.1;
access;
symbols;
locks; strict;
comment	@# @;


1.1
date	2001.07.19.19.43.48;	author dlr;	state Exp;
branches;
next	;


desc
@@


1.1
log
@Ported from Joist.
@
text
@package org.tigris.helm.util;

/**
 * Returns a series of sequential integers.
 * Holds onto a number and increments it on demand.
 *
 * @@author <a href="mailto:davidp@@dataweb-systems.com">David C. Pellegrini</a>
 * @@version $Revision: 1.5 $
 *
 * Copyright (c) 1999 dataweb systems, inc.
 * Copyright (c) 1999-2001 CollabNet, Inc.
 */
public class Counter extends Object
{
    private int counterValue;

    public Counter()
    {
        counterValue = 0;
    }

    public Counter(int startingValue)
    {
        counterValue = startingValue;
    }

    /**
     * Sets the current value
     *
     * @@param    newValue  A variable of type int
     * @@return    A variable of type String 
     */
    public void set(int newValue)
    {
        counterValue = newValue;
    }

    /**
     * Sets the current value to zero
     *
     * @@return    A variable of type String 
     */
    public void reset()
    {
        counterValue = 0;
    }

    /**
     * Returns the current value.
     *
     * @@return    A variable of type int 
     */
    public int getValue()
    {
        return counterValue;
    }

    /**
     * Returns the current value.
     *
     * @@return    A variable of type String 
     */
    public String getStringValue()
    {
        return String.valueOf(counterValue);
    }

    /**
     * Increments the current value and returns it.
     *
     * @@return    A variable of type int 
     */
    public int increment()
    {
        return ++counterValue;
    }

    /**
     * Increments the current value and returns it.
     *
     * @@return    A variable of type String 
     */
    public String incrementString()
    {
        return String.valueOf(++counterValue);
    }

    /**
     * Compare the current value against the argument.
     *
     * @@param    compareValue  A variable of type int
     * @@return    A variable of type boolean 
     */
    public boolean greaterThan(int compareValue)
    {
        return (counterValue > compareValue);
    }

    /**
     * Compare the current value against the argument.
     *
     * @@param    compareValue  A variable of type int
     * @@return    A variable of type boolean 
     */
    public boolean greaterThanOrEqual(int compareValue)
    {
        return (counterValue >= compareValue);
    }

    /**
     * Compare the current value against the argument.
     *
     * @@param    compareValue  A variable of type int
     * @@return    A variable of type boolean 
     */
    public boolean lessThan(int compareValue)
    {
        return (counterValue < compareValue);
    }

    /**
     * Compare the current value against the argument.
     *
     * @@param    compareValue  A variable of type int
     * @@return    A variable of type boolean 
     */
    public boolean lessThanOrEqual(int compareValue)
    {
        return (counterValue <= compareValue);
    }

    /**
     * Compare the current value against the argument.
     *
     * @@param    compareValue  A variable of type String
     * @@return    A variable of type boolean 
     * @@exception    NumberFormatException
     */
    public boolean greaterThan(String compareValue)
        throws NumberFormatException
    {
        return greaterThan(Integer.parseInt(compareValue));
    }

    /**
     * Compare the current value against the argument.
     *
     * @@param    compareValue  A variable of type String
     * @@return    A variable of type boolean 
     * @@exception    NumberFormatException
     */
    public boolean greaterThanOrEqual(String compareValue)
        throws NumberFormatException
    {
        return greaterThanOrEqual(Integer.parseInt(compareValue));
    }

    /**
     * Compare the current value against the argument.
     *
     * @@param    compareValue  A variable of type String
     * @@return    A variable of type boolean 
     * @@exception    NumberFormatException
     */
    public boolean lessThan(String compareValue)
        throws NumberFormatException
    {
        return lessThan(Integer.parseInt(compareValue));
    }

    /**
     * Compare the current value against the argument.
     *
     * @@param    compareValue  A variable of type String
     * @@return    A variable of type boolean 
     * @@exception    NumberFormatException
     */
    public boolean lessThanOrEqual(String compareValue)
        throws NumberFormatException
    {
        return lessThanOrEqual(Integer.parseInt(compareValue));
    }
}
@
