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

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

Added Visitor pattern for tasks.

  • Property svn:executable set to *
File size: 3.6 KB
Line 
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
15package de.ugoe.cs.autoquest.tasktrees.treeimpl;
16
17import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
18import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskVisitor;
19
20/**
21 * TODO comment
22 *
23 * @version $Revision: $ $Date: $
24 * @author 2011, last modified by $Author: $
25 */
26class Task implements ITask {
27
28    /**  */
29    private static final long serialVersionUID = 1L;
30
31    /** */
32    private static int temporalId = 0;
33
34    /** */
35    private int id;
36
37    /** */
38    private String description;
39
40    /**
41     *
42     */
43    Task() {
44        id = getNewId();
45    }
46
47    /**
48     * TODO: comment
49     *
50     * @return
51     */
52    private static synchronized int getNewId() {
53        if (temporalId == Integer.MAX_VALUE) {
54            temporalId = 0;
55        }
56
57        return temporalId++;
58    }
59
60    /**
61     * @return Returns the name.
62     */
63    public int getId() {
64        return id;
65    }
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;
75    }
76
77    /*
78     * (non-Javadoc)
79     *
80     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.TaskTreeNode#equals(TaskTreeNode)
81     */
82    @Override
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());
87    }
88
89    /*
90     * (non-Javadoc)
91     *
92     * @see java.lang.Object#hashCode()
93     */
94    @Override
95    public synchronized int hashCode() {
96        return id;
97    }
98
99    /*
100     * (non-Javadoc)
101     *
102     * @see java.lang.Object#toString()
103     */
104    @Override
105    public synchronized String toString() {
106        StringBuffer result = new StringBuffer();
107        result.append("task ");
108        result.append(id);
109       
110        if (description != null) {
111            result.append(" (");
112            result.append(description);
113            result.append(')');
114        }
115       
116        return result.toString();
117    }
118
119    /*
120     * (non-Javadoc)
121     *
122     * @see java.lang.Object#clone()
123     */
124    @Override
125    public synchronized ITask clone() {
126        Task clone = null;
127        try {
128            clone = (Task) super.clone();
129        }
130        catch (CloneNotSupportedException e) {
131            // this should never happen. Therefore simply dump the exception
132            e.printStackTrace();
133        }
134
135        return clone;
136    }
137
138    /**
139     * TODO: comment
140     *
141     * @param i
142     * @return
143     */
144    void setDescription(String description) {
145        this.description = description;
146    }
147
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
156}
Note: See TracBrowser for help on using the repository browser.