001 /* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006 *
007 * Project Info: http://www.jfree.org/jfreechart/index.html
008 *
009 * This library is free software; you can redistribute it and/or modify it
010 * under the terms of the GNU Lesser General Public License as published by
011 * the Free Software Foundation; either version 2.1 of the License, or
012 * (at your option) any later version.
013 *
014 * This library is distributed in the hope that it will be useful, but
015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017 * License for more details.
018 *
019 * You should have received a copy of the GNU Lesser General Public
020 * License along with this library; if not, write to the Free Software
021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022 * USA.
023 *
024 * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025 * in the United States and other countries.]
026 *
027 * ---------
028 * Task.java
029 * ---------
030 * (C) Copyright 2003, 2004, by Object Refinery Limited.
031 *
032 * Original Author: David Gilbert (for Object Refinery Limited);
033 * Contributor(s): -;
034 *
035 * $Id: Task.java,v 1.4.2.1 2005/10/25 21:31:44 mungady Exp $
036 *
037 * Changes
038 * -------
039 * 10-Jan-2003 : Version 1 (DG);
040 * 16-Sep-2003 : Added percentage complete (DG);
041 * 30-Jul-2004 : Added clone() and equals() methods and implemented
042 * Serializable (DG);
043 *
044 */
045
046 package org.jfree.data.gantt;
047
048 import java.io.Serializable;
049 import java.util.Date;
050 import java.util.List;
051
052 import org.jfree.data.time.SimpleTimePeriod;
053 import org.jfree.data.time.TimePeriod;
054 import org.jfree.util.ObjectUtilities;
055 import org.jfree.util.PublicCloneable;
056
057 /**
058 * A simple representation of a task. The task has a description and a
059 * duration. You can add sub-tasks to the task.
060 */
061 public class Task implements Cloneable, PublicCloneable, Serializable {
062
063 /** For serialization. */
064 private static final long serialVersionUID = 1094303785346988894L;
065
066 /** The task description. */
067 private String description;
068
069 /** The time period for the task (estimated or actual). */
070 private TimePeriod duration;
071
072 /** The percent complete (<code>null</code> is permitted). */
073 private Double percentComplete;
074
075 /** Storage for the sub-tasks (if any). */
076 private List subtasks;
077
078 /**
079 * Creates a new task.
080 *
081 * @param description the task description (<code>null</code> not
082 * permitted).
083 * @param duration the task duration (<code>null</code> permitted).
084 */
085 public Task(String description, TimePeriod duration) {
086 if (description == null) {
087 throw new IllegalArgumentException("Null 'description' argument.");
088 }
089 this.description = description;
090 this.duration = duration;
091 this.percentComplete = null;
092 this.subtasks = new java.util.ArrayList();
093 }
094
095 /**
096 * Creates a new task.
097 *
098 * @param description the task description (<code>null</code> not
099 * permitted).
100 * @param start the start date (<code>null</code> not permitted).
101 * @param end the end date (<code>null</code> not permitted).
102 */
103 public Task(String description, Date start, Date end) {
104 this(description, new SimpleTimePeriod(start, end));
105 }
106
107 /**
108 * Returns the task description.
109 *
110 * @return The task description (never <code>null</code>).
111 */
112 public String getDescription() {
113 return this.description;
114 }
115
116 /**
117 * Sets the task description.
118 *
119 * @param description the description (<code>null</code> not permitted).
120 */
121 public void setDescription(String description) {
122 if (description == null) {
123 throw new IllegalArgumentException("Null 'description' argument.");
124 }
125 this.description = description;
126 }
127
128 /**
129 * Returns the duration (actual or estimated) of the task.
130 *
131 * @return The task duration (possibly <code>null</code>).
132 */
133 public TimePeriod getDuration() {
134 return this.duration;
135 }
136
137 /**
138 * Sets the task duration (actual or estimated).
139 *
140 * @param duration the duration (<code>null</code> permitted).
141 */
142 public void setDuration(TimePeriod duration) {
143 this.duration = duration;
144 }
145
146 /**
147 * Returns the percentage complete for this task.
148 *
149 * @return The percentage complete (possibly <code>null</code>).
150 */
151 public Double getPercentComplete() {
152 return this.percentComplete;
153 }
154
155 /**
156 * Sets the percentage complete for the task.
157 *
158 * @param percent the percentage (<code>null</code> permitted).
159 */
160 public void setPercentComplete(Double percent) {
161 this.percentComplete = percent;
162 }
163
164 /**
165 * Sets the percentage complete for the task.
166 *
167 * @param percent the percentage.
168 */
169 public void setPercentComplete(double percent) {
170 setPercentComplete(new Double(percent));
171 }
172
173 /**
174 * Adds a sub-task to the task.
175 *
176 * @param subtask the subtask (<code>null</code> not permitted).
177 */
178 public void addSubtask(Task subtask) {
179 if (subtask == null) {
180 throw new IllegalArgumentException("Null 'subtask' argument.");
181 }
182 this.subtasks.add(subtask);
183 }
184
185 /**
186 * Removes a sub-task from the task.
187 *
188 * @param subtask the subtask.
189 */
190 public void removeSubtask(Task subtask) {
191 this.subtasks.remove(subtask);
192 }
193
194 /**
195 * Returns the sub-task count.
196 *
197 * @return The sub-task count.
198 */
199 public int getSubtaskCount() {
200 return this.subtasks.size();
201 }
202
203 /**
204 * Returns a sub-task.
205 *
206 * @param index the index.
207 *
208 * @return The sub-task.
209 */
210 public Task getSubtask(int index) {
211 return (Task) this.subtasks.get(index);
212 }
213
214 /**
215 * Tests this object for equality with an arbitrary object.
216 *
217 * @param object the other object (<code>null</code> permitted).
218 *
219 * @return A boolean.
220 */
221 public boolean equals(Object object) {
222 if (object == this) {
223 return true;
224 }
225 if (!(object instanceof Task)) {
226 return false;
227 }
228 Task that = (Task) object;
229 if (!ObjectUtilities.equal(this.description, that.description)) {
230 return false;
231 }
232 if (!ObjectUtilities.equal(this.duration, that.duration)) {
233 return false;
234 }
235 if (!ObjectUtilities.equal(this.percentComplete,
236 that.percentComplete)) {
237 return false;
238 }
239 if (!ObjectUtilities.equal(this.subtasks, that.subtasks)) {
240 return false;
241 }
242 return true;
243 }
244
245 /**
246 * Returns a clone of the task.
247 *
248 * @return A clone.
249 *
250 * @throws CloneNotSupportedException never thrown by this class, but
251 * subclasses may not support cloning.
252 */
253 public Object clone() throws CloneNotSupportedException {
254 Task clone = (Task) super.clone();
255 return clone;
256 }
257
258 }