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: TaggedObject.java,v $
023   Revision 1.6  2004/05/05 21:22:45  markl
024   Comment header updates.
025
026   Revision 1.5  2003/01/19 09:42:39  markl
027   Javadoc & comment header updates.
028
029   Revision 1.4  2001/03/18 06:33:16  markl
030   Added toString() method.
031
032   Revision 1.3  2001/03/12 03:16:51  markl
033   *** empty log message ***
034
035   Revision 1.2  1999/01/10 03:56:22  markl
036   added GPL header & RCS tag
037   ----------------------------------------------------------------------------
038*/
039
040package kiwi.util;
041
042/** An object-id or object-tag pair. Sometimes it is useful to assign a tag
043  * or numeric ID to an object for purposes of identification. Most commonly
044  * the identifier is a unique integer, but in some circumstances it is more
045  * appropriate to use another object as an identifier. This class allows
046  * an object to be associated with either an integer or an arbitrary object.
047  *
048  * @author Mark Lindner
049  */
050
051public class TaggedObject
052  {
053  private Object obj;
054  private Object tag = null;
055  private int id = -1;
056
057  /** Construct a new <code>TaggedObject</code> for the given user object
058    * and identifier object.
059    *
060    * @param obj The user object.
061    * @param tag The identifier object.
062    */
063  
064  public TaggedObject(Object obj, Object tag)
065    {
066    this.obj = obj;
067    this.tag = tag;
068    }
069
070  /** Construct a new <code>TaggedObject</code> for the given user object
071    * and numerical ID.
072    *
073    * @param obj The user object.
074    * @param id The numerical ID.
075    */
076  
077  public TaggedObject(Object obj, int id)
078    {
079    this.obj = obj;
080    this.id = id;
081    }
082
083  /** Get the user object.
084    *
085    * @return The user object.
086    */
087  
088  public final Object getObject()
089    {
090    return(obj);
091    }
092
093  /** Get the numerical ID.
094    *
095    * @return The numerical ID, or <code>-1</code> if there is no numerical ID
096    * for this object.
097    */
098  
099  public final int getID()
100    {
101    return(id);
102    }
103
104  /** Get the identifier object.
105    *
106    * @return The identifier object, or <code>null</code> if there is no
107    * identifier object for this object.
108    */
109  
110  public final Object getTag()
111    {
112    return(tag);
113    }
114
115  /** Get a string representation of the tagged object.
116   *
117   * @since Kiwi 1.3
118   */
119
120  public String toString()
121    {
122    return(obj.toString());
123    }
124  
125  }
126
127/* end of source file */