Changeset 1146 for trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/Task.java
- Timestamp:
- 04/04/13 16:06:07 (11 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/Task.java
r1126 r1146 15 15 package de.ugoe.cs.autoquest.tasktrees.treeimpl; 16 16 17 import java.util.Collections; 18 import java.util.LinkedList; 19 import java.util.List; 20 21 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 17 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 22 18 23 19 /** … … 27 23 * @author 2011, last modified by $Author: $ 28 24 */ 29 public class TaskTreeNode implements ITaskTreeNode { 25 class Task implements ITask { 26 27 /** */ 28 private static final long serialVersionUID = 1L; 29 30 30 /** */ 31 31 private static int temporalId = 0; 32 32 33 33 /** */ 34 private String name;34 private int id; 35 35 36 36 /** */ 37 37 private String description; 38 38 39 /** */40 private int id;41 42 /** children */43 private List<ITaskTreeNode> children;44 45 39 /** 46 40 * 47 41 */ 48 public TaskTreeNode(String name) { 49 this.name = name; 42 Task() { 50 43 id = getNewId(); 51 44 } … … 67 60 * @return Returns the name. 68 61 */ 69 public String getName() {70 return name;62 public int getId() { 63 return id; 71 64 } 72 65 … … 81 74 } 82 75 83 /**84 *85 */86 public synchronized List<ITaskTreeNode> getChildren() {87 if ((children == null) || (children.size() == 0)) {88 return new LinkedList<ITaskTreeNode>();89 }90 91 return Collections.unmodifiableList(children);92 }93 94 76 /* 95 77 * (non-Javadoc) … … 98 80 */ 99 81 @Override 100 public boolean equals(ITaskTreeNode taskTreeNode) { 101 if (!this.getClass().isInstance(taskTreeNode)) { 102 return false; 103 } 104 105 if (taskTreeNode.hashCode() != hashCode()) { 106 return false; 107 } 108 109 TaskTreeNode other = (TaskTreeNode) taskTreeNode; 110 111 if (id != other.id) { 112 return false; 113 } 114 115 if (!name.equals(other.name)) { 116 return false; 117 } 118 119 synchronized (other) { 120 if (children == null) { 121 return (other.children == null); 122 } 123 else if (other.children == null) { 124 return (children == null); 125 } 126 else if (other.children.size() != children.size()) { 127 return false; 128 } 129 130 for (int i = 0; i < children.size(); i++) { 131 if (!children.get(i).equals(other.children.get(i))) { 132 return false; 133 } 134 } 135 } 136 137 return true; 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()); 138 86 } 139 87 … … 145 93 @Override 146 94 public synchronized int hashCode() { 147 return getClass().getSimpleName().hashCode();95 return id; 148 96 } 149 97 … … 156 104 public synchronized String toString() { 157 105 StringBuffer result = new StringBuffer(); 158 result.append(name); 159 result.append('('); 106 result.append("task "); 160 107 result.append(id); 161 108 162 109 if (description != null) { 163 result.append(" ,");110 result.append(" ("); 164 111 result.append(description); 112 result.append(')'); 165 113 } 166 114 167 if (children != null) { 168 result.append(", "); 169 result.append(children.size()); 170 result.append(" children"); 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(); 171 128 } 172 173 result.append(')'); 174 return result.toString(); 129 catch (CloneNotSupportedException e) { 130 // this should never happen. Therefore simply dump the exception 131 e.printStackTrace(); 132 } 133 134 return clone; 175 135 } 176 136 … … 185 145 } 186 146 187 /**188 *189 */190 synchronized void addChild(ITaskTreeNode child) {191 if (children == null) {192 children = new LinkedList<ITaskTreeNode>();193 }194 195 children.add(child);196 }197 198 /**199 *200 */201 synchronized void addChild(int index, ITaskTreeNode child) {202 if (children == null) {203 children = new LinkedList<ITaskTreeNode>();204 }205 206 children.add(index, child);207 }208 209 /**210 * TODO: comment211 *212 * @param i213 * @return214 */215 synchronized ITaskTreeNode removeChild(int index) {216 return children.remove(index);217 }218 219 /*220 * (non-Javadoc)221 *222 * @see java.lang.Object#clone()223 */224 @Override225 public synchronized ITaskTreeNode clone() {226 TaskTreeNode clone = null;227 try {228 clone = (TaskTreeNode) super.clone();229 230 if (children != null) {231 clone.children = new LinkedList<ITaskTreeNode>();232 233 for (ITaskTreeNode child : children) {234 clone.children.add(child.clone());235 }236 }237 238 }239 catch (CloneNotSupportedException e) {240 // this should never happen. Therefore simply dump the exception241 e.printStackTrace();242 }243 244 return clone;245 }246 247 147 }
Note: See TracChangeset
for help on using the changeset viewer.