// Copyright 1997 The Open Group Research Institute.  All rights reserved.

package krb5.lib;

import krb5.lib.crypto.Confounder;

/**
 * Global sequence number
 */
public class GlobalSeqNumber implements SeqNumber {

	/**
	 * Last sequence number
	 */
	private static int lastSeqNumber = Confounder.intValue();

	/**
	 * Class constructor
	 *
	 * @param start is of type int
	 */
	public GlobalSeqNumber(int start) {
		lastSeqNumber = start;
	}

	/**
	 * Class constructor
	 *
	 * @param start is of type Integer
	 */
	public GlobalSeqNumber(Integer start) {
		this(start.intValue());
	}

	/**
	 * Sets to random value
	 */
	public synchronized void randInit() {
		lastSeqNumber = Confounder.intValue();
	}

	/**
	 * Returns current value
	 *
	 * @return int is a result
	 */
	public synchronized int current() {
		return lastSeqNumber;
	}

	/**
	 * Returns next value
	 *
	 * @return int is a result
	 */
	public synchronized int next() {
		return lastSeqNumber + 1;
	}

	/**
	 * Steps to next value and returns the new value
	 *
	 * @return int is a result
	 */
	public synchronized int step() {
		return ++lastSeqNumber;
	}

}