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: DateHolder.java,v $ 023 Revision 1.6 2004/05/05 21:22:45 markl 024 Comment header updates. 025 026 Revision 1.5 2004/05/05 18:24:03 markl 027 rename of HolderObject to ValueHolder 028 029 Revision 1.4 2003/01/19 09:42:38 markl 030 Javadoc & comment header updates. 031 032 Revision 1.3 2001/03/12 02:57:39 markl 033 Source code cleanup. 034 035 Revision 1.2 1999/07/19 03:58:48 markl 036 Set default subtype. 037 038 Revision 1.1 1999/07/16 07:12:31 markl 039 Initial revision 040 ---------------------------------------------------------------------------- 041*/ 042 043package kiwi.util; 044 045import java.util.*; 046 047import kiwi.text.*; 048 049/** A mutable holder for a <code>Date</code> value. 050 * 051 * @author Mark Lindner 052 */ 053 054public class DateHolder extends ValueHolder 055 { 056 /** The current value. */ 057 protected Date value; 058 059 /** Construct a new <code>DateHolder</code> with an initial value of the 060 * current date and time, and a default subtype of 061 * <code>FormatConstants.DATE_FORMAT</code>. 062 * 063 * @see kiwi.text.FormatConstants 064 */ 065 066 public DateHolder() 067 { 068 this(new Date()); 069 } 070 071 /** Construct a new <code>DateHolder</code> with a specified initial 072 * value, and a default subtype of 073 * <code>FormatConstants.DATE_FORMAT</code>. 074 * 075 * @param value The initial value. 076 */ 077 078 public DateHolder(Date value) 079 { 080 this(value, FormatConstants.DATE_FORMAT); 081 } 082 083 /** Construct a new <code>DateHolder</code> with a specified initial 084 * value and subtype. A subtype is particularly useful for a 085 * <code>Date</code> object, since it may be used to specify which part 086 * of the value is significant (such as the date, the time, or both). 087 * 088 * @param value The initial value. 089 */ 090 091 public DateHolder(Date value, int subtype) 092 { 093 super(subtype); 094 095 this.value = value; 096 } 097 098 /** Set the <code>DateHolder</code>'s value. 099 * 100 * @param value The new value. 101 */ 102 103 public final void setValue(Date value) 104 { 105 this.value = value; 106 } 107 108 /** Get the <code>DateHolder</code>'s value. 109 * 110 * @return The current value. 111 */ 112 113 public final Date getValue() 114 { 115 return(value); 116 } 117 118 /** Get a string representation for this object. */ 119 120 public String toString() 121 { 122 return(value == null ? null : String.valueOf(value)); 123 } 124 125 /** Compare this holder object to another. */ 126 127 public int compareTo(Object other) 128 { 129 Date v = ((DateHolder)other).getValue(); 130 131 if((v == null) && (value == null)) 132 return(0); 133 else if((v == null) && (value != null)) 134 return(1); 135 else if((v != null) && (value == null)) 136 return(-1); 137 else 138 return(value.compareTo(v)); 139 } 140 141 } 142 143/* end of source file */