001/* ----------------------------------------------------------------------------
002   The Kiwi Toolkit - A Java Class Library
003   Copyright (C) 1998-2004 Mark A. Lindner
004
005   This library is free software; you can redistribute it and/or
006   modify it under the terms of the GNU General Public License as
007   published by the Free Software Foundation; either version 2 of the
008   License, or (at your option) any later version.
009
010   This library is distributed in the hope that it will be useful,
011   but WITHOUT ANY WARRANTY; without even the implied warranty of
012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013   General Public License for more details.
014
015   You should have received a copy of the GNU General Public License
016   along with this library; if not, write to the Free Software
017   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
018   02111-1307, USA.
019 
020   The author may be contacted at: mark_a_lindner@yahoo.com
021   ----------------------------------------------------------------------------
022   $Log: IntegerHolder.java,v $
023   Revision 1.9  2004/05/05 21:22:45  markl
024   Comment header updates.
025
026   Revision 1.8  2004/05/05 18:23:11  markl
027   rename of HolderObject to ValueHolder
028
029   Revision 1.7  2003/01/19 09:42:39  markl
030   Javadoc & comment header updates.
031
032   Revision 1.6  2001/03/12 02:57:40  markl
033   Source code cleanup.
034
035   Revision 1.5  1999/07/25 13:39:39  markl
036   Added a constructor that accepts a subtype.
037
038   Revision 1.4  1999/07/16 07:13:01  markl
039   Modified to subclass HolderObject.
040
041   Revision 1.3  1999/02/09 05:02:56  markl
042   added toString() method
043
044   Revision 1.2  1999/01/10 03:47:05  markl
045   added GPL header & RCS tag
046   ----------------------------------------------------------------------------
047*/
048
049package kiwi.util;
050
051/** A mutable holder for an <code>int</code> value.
052  *
053  * @author Mark Lindner
054  */
055
056public class IntegerHolder extends ValueHolder
057  {
058  /** The current value. */
059  protected int value;
060
061  /** Construct a new <code>IntegerHolder</code> with an initial value of
062   * <code>0</code> and default subtype of <code>0</code>.
063   */
064  
065  public IntegerHolder()
066    {
067    this(0, 0);
068    }
069  
070  /** Construct a new <code>IntegerHolder</code> with a specified initial
071   * value and default subtype of <code>0</code>.
072   *
073   * @param value The initial value.
074   */
075  
076  public IntegerHolder(int value)
077    {
078    this(value, 0);
079    }
080
081  /** Construct a new <code>IntegerHolder</code> with a specified initial
082    * value and subtype.
083    *
084    * @param value The initial value.
085    * @param subtype The subtype for this value.
086    */
087  
088  public IntegerHolder(int value, int subtype)
089    {
090    super(subtype);
091    
092    this.value = value;
093    }
094  
095  /** Set the <code>IntegerHolder</code>'s value.
096    *
097    * @param value The new value.
098    */
099  
100  public final void setValue(int value)
101    {
102    this.value = value;
103    }
104
105  /** Get the <code>IntegerHolder</code>'s value.
106    *
107    * @return The current value.
108    */
109  
110  public final int getValue()
111    {
112    return(value);
113    }
114
115  /** Get a string representation for this object. */
116  
117  public String toString()
118    {
119    return(String.valueOf(value));
120    }
121
122  /** Compare this holder object to another. */
123  
124  public int compareTo(Object other)
125    {
126    int v = ((IntegerHolder)other).getValue();
127
128    return((value < v) ? -1 : ((value > v) ? 1 : 0));
129    }
130  
131  }
132
133/* end of source file */