    001    /* ===========================================================
    002     * JFreeChart : a free chart library for the Java(tm) platform
    003     * ===========================================================
    004     *
    005     * (C) Copyright 2000-2007, 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-2007, by Object Refinery Limited.
    031     *
    032     * Original Author:  David Gilbert (for Object Refinery Limited);
    033     * Contributor(s):   -;
    034     *
    035     * Changes
    036     * -------
    037     * 10-Jan-2003 : Version 1 (DG);
    038     * 16-Sep-2003 : Added percentage complete (DG);
    039     * 30-Jul-2004 : Added clone() and equals() methods and implemented
    040     *               Serializable (DG);
    041     *
    042     */
    043
    044    package org.jfree.data.gantt;
    045
    046    import java.io.Serializable;
    047    import java.util.Date;
    048    import java.util.List;
    049
    050    import org.jfree.data.time.SimpleTimePeriod;
    051    import org.jfree.data.time.TimePeriod;
    052    import org.jfree.util.ObjectUtilities;
    053    import org.jfree.util.PublicCloneable;
    054
    055    /**
    056     * A simple representation of a task.  The task has a description and a
    057     * duration.  You can add sub-tasks to the task.
    058     */
    059    public class Task implements Cloneable, PublicCloneable, Serializable {
    060
    061        /** For serialization. */
    062        private static final long serialVersionUID = 1094303785346988894L;
    063
    064        /** The task description. */
    065        private String description;
    066
    067        /** The time period for the task (estimated or actual). */
    068        private TimePeriod duration;
    069
    070        /** The percent complete (<code>null</code> is permitted). */
    071        private Double percentComplete;
    072
    073        /** Storage for the sub-tasks (if any). */
    074        private List subtasks;
    075
    076        /**
    077         * Creates a new task.
    078         *
    079         * @param description  the task description (<code>null</code> not
    080         *                     permitted).
    081         * @param duration  the task duration (<code>null</code> permitted).
    082         */
    083        public Task(String description, TimePeriod duration) {
    084            if (description == null) {
    085                throw new IllegalArgumentException("Null 'description' argument.");
    086            }
    087            this.description = description;
    088            this.duration = duration;
    089            this.percentComplete = null;
    090            this.subtasks = new java.util.ArrayList();
    091        }
    092
    093        /**
    094         * Creates a new task.
    095         *
    096         * @param description  the task description (<code>null</code> not
    097         *                     permitted).
    098         * @param start  the start date (<code>null</code> not permitted).
    099         * @param end  the end date (<code>null</code> not permitted).
    100         */
    101        public Task(String description, Date start, Date end) {
    102            this(description, new SimpleTimePeriod(start, end));
    103        }
    104
    105        /**
    106         * Returns the task description.
    107         *
    108         * @return The task description (never <code>null</code>).
    109         */
    110        public String getDescription() {
    111            return this.description;
    112        }
    113
    114        /**
    115         * Sets the task description.
    116         *
    117         * @param description  the description (<code>null</code> not permitted).
    118         */
    119        public void setDescription(String description) {
    120            if (description == null) {
    121                throw new IllegalArgumentException("Null 'description' argument.");
    122            }
    123            this.description = description;
    124        }
    125
    126        /**
    127         * Returns the duration (actual or estimated) of the task.
    128         *
    129         * @return The task duration (possibly <code>null</code>).
    130         */
    131        public TimePeriod getDuration() {
    132            return this.duration;
    133        }
    134
    135        /**
    136         * Sets the task duration (actual or estimated).
    137         *
    138         * @param duration  the duration (<code>null</code> permitted).
    139         */
    140        public void setDuration(TimePeriod duration) {
    141            this.duration = duration;
    142        }
    143
    144        /**
    145         * Returns the percentage complete for this task.
    146         *
    147         * @return The percentage complete (possibly <code>null</code>).
    148         */
    149        public Double getPercentComplete() {
    150            return this.percentComplete;
    151        }
    152
    153        /**
    154         * Sets the percentage complete for the task.
    155         *
    156         * @param percent  the percentage (<code>null</code> permitted).
    157         */
    158        public void setPercentComplete(Double percent) {
    159            this.percentComplete = percent;
    160        }
    161
    162        /**
    163         * Sets the percentage complete for the task.
    164         *
    165         * @param percent  the percentage.
    166         */
    167        public void setPercentComplete(double percent) {
    168            setPercentComplete(new Double(percent));
    169        }
    170
    171        /**
    172         * Adds a sub-task to the task.
    173         *
    174         * @param subtask  the subtask (<code>null</code> not permitted).
    175         */
    176        public void addSubtask(Task subtask) {
    177            if (subtask == null) {
    178                throw new IllegalArgumentException("Null 'subtask' argument.");
    179            }
    180            this.subtasks.add(subtask);
    181        }
    182
    183        /**
    184         * Removes a sub-task from the task.
    185         *
    186         * @param subtask  the subtask.
    187         */
    188        public void removeSubtask(Task subtask) {
    189            this.subtasks.remove(subtask);
    190        }
    191
    192        /**
    193         * Returns the sub-task count.
    194         *
    195         * @return The sub-task count.
    196         */
    197        public int getSubtaskCount() {
    198            return this.subtasks.size();
    199        }
    200
    201        /**
    202         * Returns a sub-task.
    203         *
    204         * @param index  the index.
    205         *
    206         * @return The sub-task.
    207         */
    208        public Task getSubtask(int index) {
    209            return (Task) this.subtasks.get(index);
    210        }
    211
    212        /**
    213         * Tests this object for equality with an arbitrary object.
    214         *
    215         * @param object  the other object (<code>null</code> permitted).
    216         *
    217         * @return A boolean.
    218         */
    219        public boolean equals(Object object) {
    220            if (object == this) {
    221                return true;
    222            }
    223            if (!(object instanceof Task)) {
    224                return false;
    225            }
    226            Task that = (Task) object;
    227            if (!ObjectUtilities.equal(this.description, that.description)) {
    228                return false;
    229            }
    230            if (!ObjectUtilities.equal(this.duration, that.duration)) {
    231                return false;
    232            }
    233            if (!ObjectUtilities.equal(this.percentComplete,
    234                    that.percentComplete)) {
    235                return false;
    236            }
    237            if (!ObjectUtilities.equal(this.subtasks, that.subtasks)) {
    238                return false;
    239            }
    240            return true;
    241        }
    242
    243        /**
    244         * Returns a clone of the task.
    245         *
    246         * @return A clone.
    247         *
    248         * @throws CloneNotSupportedException  never thrown by this class, but
    249         *         subclasses may not support cloning.
    250         */
    251        public Object clone() throws CloneNotSupportedException {
    252            Task clone = (Task) super.clone();
    253            return clone;
    254        }
    255
    256    }