001 package com.croftsoft.core.math;
002
003 import java.io.Serializable;
004 import java.math.BigInteger;
005
006 import com.croftsoft.core.lang.NullArgumentException;
007
008 /*********************************************************************
009 * An incrementable integer counter with no maximum limit.
010 *
011 * <p />
012 *
013 * @version
014 * 2001-03-30
015 * @since
016 * 2001-03-30
017 * @author
018 * <a href="http://www.CroftSoft.com/">David W. Croft</a>
019 *********************************************************************/
020
021 public final class Counter
022 implements Serializable
023 //////////////////////////////////////////////////////////////////////
024 //////////////////////////////////////////////////////////////////////
025 {
026
027 private static final long serialVersionUID = 1L;
028
029 private BigInteger count;
030
031 //////////////////////////////////////////////////////////////////////
032 //////////////////////////////////////////////////////////////////////
033
034 public Counter ( BigInteger count )
035 //////////////////////////////////////////////////////////////////////
036 {
037 NullArgumentException.check ( this.count = count );
038 }
039
040 public Counter ( )
041 //////////////////////////////////////////////////////////////////////
042 {
043 this ( BigInteger.ZERO );
044 }
045
046 //////////////////////////////////////////////////////////////////////
047 //////////////////////////////////////////////////////////////////////
048
049 public BigInteger getCount ( )
050 //////////////////////////////////////////////////////////////////////
051 {
052 return count;
053 }
054
055 /*********************************************************************
056 * Synchronized.
057 *********************************************************************/
058 public synchronized BigInteger increment ( )
059 //////////////////////////////////////////////////////////////////////
060 {
061 return ( count = count.add ( BigInteger.ONE ) );
062 }
063
064 //////////////////////////////////////////////////////////////////////
065 //////////////////////////////////////////////////////////////////////
066 }