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