1. /* ===========================================================
  2. * JFreeChart : a free chart library for the Java(tm) platform
  3. * ===========================================================
  4. *
  5. * (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
  6. *
  7. * Project Info: http://www.jfree.org/jfreechart/index.html
  8. *
  9. * This library is free software; you can redistribute it and/or modify it under the terms
  10. * of the GNU Lesser General Public License as published by the Free Software Foundation;
  11. * either version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  14. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License along with this
  18. * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. *
  21. * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  22. * in the United States and other countries.]
  23. *
  24. * ---------
  25. * Task.java
  26. * ---------
  27. * (C) Copyright 2003, 2004, by Object Refinery Limited.
  28. *
  29. * Original Author: David Gilbert (for Object Refinery Limited);
  30. * Contributor(s): -;
  31. *
  32. * $Id: Task.java,v 1.2 2004/11/27 17:05:33 mungady Exp $
  33. *
  34. * Changes
  35. * -------
  36. * 10-Jan-2003 : Version 1 (DG);
  37. * 16-Sep-2003 : Added percentage complete (DG);
  38. * 30-Jul-2004 : Added clone() and equals() methods and implemented Serializable (DG);
  39. *
  40. */
  41. package org.jfree.data.gantt;
  42. import java.io.Serializable;
  43. import java.util.Date;
  44. import java.util.List;
  45. import org.jfree.data.time.SimpleTimePeriod;
  46. import org.jfree.data.time.TimePeriod;
  47. import org.jfree.util.ObjectUtilities;
  48. import org.jfree.util.PublicCloneable;
  49. /**
  50. * A simple representation of a task. The task has a description and a duration. You can add
  51. * sub-tasks to the task.
  52. */
  53. public class Task implements Cloneable, PublicCloneable, Serializable {
  54. /** The task description. */
  55. private String description;
  56. /** The time period for the task (estimated or actual). */
  57. private TimePeriod duration;
  58. /** The percent complete (<code>null</code> is permitted). */
  59. private Double percentComplete;
  60. /** Storage for the sub-tasks (if any). */
  61. private List subtasks;
  62. /**
  63. * Creates a new task.
  64. *
  65. * @param description the task description (<code>null</code> not permitted).
  66. * @param duration the task duration (<code>null</code> permitted).
  67. */
  68. public Task(String description, TimePeriod duration) {
  69. if (description == null) {
  70. throw new IllegalArgumentException("Null 'description' argument.");
  71. }
  72. this.description = description;
  73. this.duration = duration;
  74. this.percentComplete = null;
  75. this.subtasks = new java.util.ArrayList();
  76. }
  77. /**
  78. * Creates a new task.
  79. *
  80. * @param description the task description (<code>null</code> not permitted).
  81. * @param start the start date (<code>null</code> not permitted).
  82. * @param end the end date (<code>null</code> not permitted).
  83. */
  84. public Task(String description, Date start, Date end) {
  85. this(description, new SimpleTimePeriod(start, end));
  86. }
  87. /**
  88. * Returns the task description.
  89. *
  90. * @return The task description (never <code>null</code>).
  91. */
  92. public String getDescription() {
  93. return this.description;
  94. }
  95. /**
  96. * Sets the task description.
  97. *
  98. * @param description the description (<code>null</code> not permitted).
  99. */
  100. public void setDescription(String description) {
  101. if (description == null) {
  102. throw new IllegalArgumentException("Null 'description' argument.");
  103. }
  104. this.description = description;
  105. }
  106. /**
  107. * Returns the duration (actual or estimated) of the task.
  108. *
  109. * @return The task duration (possibly <code>null</code>).
  110. */
  111. public TimePeriod getDuration() {
  112. return this.duration;
  113. }
  114. /**
  115. * Sets the task duration (actual or estimated).
  116. *
  117. * @param duration the duration (<code>null</code> permitted).
  118. */
  119. public void setDuration(TimePeriod duration) {
  120. this.duration = duration;
  121. }
  122. /**
  123. * Returns the percentage complete for this task.
  124. *
  125. * @return The percentage complete (possibly <code>null</code>).
  126. */
  127. public Double getPercentComplete() {
  128. return this.percentComplete;
  129. }
  130. /**
  131. * Sets the percentage complete for the task.
  132. *
  133. * @param percent the percentage (<code>null</code> permitted).
  134. */
  135. public void setPercentComplete(Double percent) {
  136. this.percentComplete = percent;
  137. }
  138. /**
  139. * Sets the percentage complete for the task.
  140. *
  141. * @param percent the percentage.
  142. */
  143. public void setPercentComplete(double percent) {
  144. setPercentComplete(new Double(percent));
  145. }
  146. /**
  147. * Adds a sub-task to the task.
  148. *
  149. * @param subtask the subtask (<code>null</code> not permitted).
  150. */
  151. public void addSubtask(Task subtask) {
  152. if (subtask == null) {
  153. throw new IllegalArgumentException("Null 'subtask' argument.");
  154. }
  155. this.subtasks.add(subtask);
  156. }
  157. /**
  158. * Removes a sub-task from the task.
  159. *
  160. * @param subtask the subtask.
  161. */
  162. public void removeSubtask(Task subtask) {
  163. this.subtasks.remove(subtask);
  164. }
  165. /**
  166. * Returns the sub-task count.
  167. *
  168. * @return The sub-task count.
  169. */
  170. public int getSubtaskCount() {
  171. return this.subtasks.size();
  172. }
  173. /**
  174. * Returns a sub-task.
  175. *
  176. * @param index the index.
  177. *
  178. * @return The sub-task.
  179. */
  180. public Task getSubtask(int index) {
  181. return (Task) this.subtasks.get(index);
  182. }
  183. /**
  184. * Tests this object for equality with an arbitrary object.
  185. *
  186. * @param object the other object (<code>null</code> permitted).
  187. *
  188. * @return A boolean.
  189. */
  190. public boolean equals(Object object) {
  191. if (object == this) {
  192. return true;
  193. }
  194. if (!(object instanceof Task)) {
  195. return false;
  196. }
  197. Task that = (Task) object;
  198. if (!ObjectUtilities.equal(this.description, that.description)) {
  199. return false;
  200. }
  201. if (!ObjectUtilities.equal(this.duration, that.duration)) {
  202. return false;
  203. }
  204. if (!ObjectUtilities.equal(this.percentComplete, that.percentComplete)) {
  205. return false;
  206. }
  207. if (!ObjectUtilities.equal(this.subtasks, that.subtasks)) {
  208. return false;
  209. }
  210. return true;
  211. }
  212. /**
  213. * Returns a clone of the task.
  214. *
  215. * @return A clone.
  216. *
  217. * @throws CloneNotSupportedException never thrown by this class, but subclasses may
  218. * not support cloning.
  219. */
  220. public Object clone() throws CloneNotSupportedException {
  221. Task clone = (Task) super.clone();
  222. return clone;
  223. }
  224. }