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: ValueHolder.java,v $ 023 Revision 1.2 2004/05/05 21:22:46 markl 024 Comment header updates. 025 026 Revision 1.1 2004/05/05 18:23:11 markl 027 rename of HolderObject to ValueHolder 028 029 Revision 1.3 2003/01/19 09:42:39 markl 030 Javadoc & comment header updates. 031 032 Revision 1.2 2001/03/12 02:57:40 markl 033 Source code cleanup. 034 035 Revision 1.1 1999/07/16 07:13:06 markl 036 Initial revision 037 ---------------------------------------------------------------------------- 038*/ 039 040package kiwi.util; 041 042/** An abstract base class for mutable holder objects. This base class declares 043 * a comparator method that may be used to determine the relative order of 044 * two holder objects, based on the cardinality of their respective values. 045 * It also introduces the notion of a <i>subtype</i>, which is an arbitrary 046 * integer that may be used to store additional information about the value 047 * stored in this holder. One possible use for the subtype field is to store 048 * a format type (such as one of the data format constants defined in the 049 * <code>kiwi.text.FormatConstants</code> interface); such information can be 050 * useful to tree and table cell renderers, for example. 051 * 052 * @see kiwi.text.FormatConstants 053 * 054 * @author Mark Lindner 055 */ 056 057public abstract class ValueHolder implements Comparable 058 { 059 /** The subtype for the value stored by this holder. */ 060 protected int subtype; 061 062 /** Construct a new <code>ValueHolder</code>. */ 063 064 protected ValueHolder() 065 { 066 this(0); 067 } 068 069 /** Construct a new <code>ValueHolder</code> with the specified subtype. 070 * 071 * @param subtype The subtype. 072 */ 073 074 protected ValueHolder(int subtype) 075 { 076 this.subtype = subtype; 077 } 078 079 /** Compare the value in this <code>ValueHolder</code> to the value in 080 * another <code>ValueHolder</code>. It is assumed that the two values 081 * are of the same type (hence that the holders are also of the same type). 082 * 083 * @param other The <code>ValueHolder</code> to compare against. 084 * @return <code>-1</code> if this object is "less than" the other object; 085 * <code>1</code> if this object is "greater than" the other object, and 086 * <code>0</code> if the objects are "equal." 087 */ 088 089 public abstract int compareTo(Object other); 090 091 /** Set the subtype for the value stored by this holder. 092 * 093 * @param subtype The new subtype. 094 */ 095 096 public void setSubtype(int subtype) 097 { 098 this.subtype = subtype; 099 } 100 101 /** Get the subtype for the value stored by this holder. 102 * 103 * @return The current subtype. The default subtype is 0. 104 */ 105 106 public int getSubtype() 107 { 108 return(subtype); 109 } 110 111 } 112 113/* end of source file */