source: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/Task.java @ 1167

Last change on this file since 1167 was 1157, checked in by adeicke, 11 years ago

Added Visitor pattern for tasks.

  • Property svn:executable set to *
File size: 3.6 KB
RevLine 
[1113]1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
[922]15package de.ugoe.cs.autoquest.tasktrees.treeimpl;
[439]16
[1146]17import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
[1157]18import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskVisitor;
[439]19
20/**
21 * TODO comment
[557]22 *
[439]23 * @version $Revision: $ $Date: $
[557]24 * @author 2011, last modified by $Author: $
[439]25 */
[1146]26class Task implements ITask {
27
28    /**  */
29    private static final long serialVersionUID = 1L;
30
[557]31    /** */
32    private static int temporalId = 0;
[439]33
[557]34    /** */
[1146]35    private int id;
[439]36
[557]37    /** */
38    private String description;
[439]39
[557]40    /**
41     *
42     */
[1146]43    Task() {
[557]44        id = getNewId();
[439]45    }
46
[557]47    /**
48     * TODO: comment
49     *
50     * @return
51     */
52    private static synchronized int getNewId() {
53        if (temporalId == Integer.MAX_VALUE) {
54            temporalId = 0;
55        }
[439]56
[557]57        return temporalId++;
58    }
[439]59
[557]60    /**
61     * @return Returns the name.
62     */
[1146]63    public int getId() {
64        return id;
[439]65    }
[557]66
67    /*
68     * (non-Javadoc)
69     *
70     * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNode#getDescription()
71     */
72    @Override
73    public String getDescription() {
74        return description;
[439]75    }
[557]76
77    /*
78     * (non-Javadoc)
79     *
[922]80     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.TaskTreeNode#equals(TaskTreeNode)
[557]81     */
82    @Override
[1146]83    public final boolean equals(ITask task) {
84        // tasks are only equal if they are identical or if they have the same id
85        // (may happen, if they are cloned)
86        return (this == task) || (this.hashCode() == task.hashCode());
[439]87    }
[557]88
89    /*
90     * (non-Javadoc)
91     *
92     * @see java.lang.Object#hashCode()
93     */
94    @Override
95    public synchronized int hashCode() {
[1146]96        return id;
[439]97    }
[557]98
99    /*
100     * (non-Javadoc)
101     *
102     * @see java.lang.Object#toString()
103     */
104    @Override
[1126]105    public synchronized String toString() {
106        StringBuffer result = new StringBuffer();
[1146]107        result.append("task ");
[1126]108        result.append(id);
109       
110        if (description != null) {
[1146]111            result.append(" (");
[1126]112            result.append(description);
[1146]113            result.append(')');
[1126]114        }
115       
116        return result.toString();
[439]117    }
118
[557]119    /*
120     * (non-Javadoc)
121     *
122     * @see java.lang.Object#clone()
123     */
124    @Override
[1146]125    public synchronized ITask clone() {
126        Task clone = null;
[557]127        try {
[1146]128            clone = (Task) super.clone();
[470]129        }
[557]130        catch (CloneNotSupportedException e) {
131            // this should never happen. Therefore simply dump the exception
132            e.printStackTrace();
133        }
134
135        return clone;
[467]136    }
[439]137
[1146]138    /**
139     * TODO: comment
140     *
141     * @param i
142     * @return
143     */
144    void setDescription(String description) {
145        this.description = description;
146    }
147
[1157]148    /* (non-Javadoc)
149     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITask#accept(de.ugoe.cs.autoquest.tasktrees.treeifc.TaskVisitor)
150     */
151    @Override
152    public void accept(ITaskVisitor visitor) {
153        visitor.visit(this);
154    }
155
[439]156}
Note: See TracBrowser for help on using the repository browser.