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