Ignore:
Timestamp:
04/04/13 16:06:07 (11 years ago)
Author:
pharms
Message:
  • complete refactoring of task tree model with a separation of task models and task instances
  • appropriate adaptation of task tree generation process
  • appropriate adaptation of commands and task tree visualization
File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/Task.java

    r1126 r1146  
    1515package de.ugoe.cs.autoquest.tasktrees.treeimpl; 
    1616 
    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; 
     17import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
    2218 
    2319/** 
     
    2723 * @author 2011, last modified by $Author: $ 
    2824 */ 
    29 public class TaskTreeNode implements ITaskTreeNode { 
     25class Task implements ITask { 
     26 
     27    /**  */ 
     28    private static final long serialVersionUID = 1L; 
     29 
    3030    /** */ 
    3131    private static int temporalId = 0; 
    3232 
    3333    /** */ 
    34     private String name; 
     34    private int id; 
    3535 
    3636    /** */ 
    3737    private String description; 
    3838 
    39     /** */ 
    40     private int id; 
    41  
    42     /** children */ 
    43     private List<ITaskTreeNode> children; 
    44  
    4539    /** 
    4640     *  
    4741     */ 
    48     public TaskTreeNode(String name) { 
    49         this.name = name; 
     42    Task() { 
    5043        id = getNewId(); 
    5144    } 
     
    6760     * @return Returns the name. 
    6861     */ 
    69     public String getName() { 
    70         return name; 
     62    public int getId() { 
     63        return id; 
    7164    } 
    7265 
     
    8174    } 
    8275 
    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  
    9476    /* 
    9577     * (non-Javadoc) 
     
    9880     */ 
    9981    @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()); 
    13886    } 
    13987 
     
    14593    @Override 
    14694    public synchronized int hashCode() { 
    147         return getClass().getSimpleName().hashCode(); 
     95        return id; 
    14896    } 
    14997 
     
    156104    public synchronized String toString() { 
    157105        StringBuffer result = new StringBuffer(); 
    158         result.append(name); 
    159         result.append('('); 
     106        result.append("task "); 
    160107        result.append(id); 
    161108         
    162109        if (description != null) { 
    163             result.append(", "); 
     110            result.append(" ("); 
    164111            result.append(description); 
     112            result.append(')'); 
    165113        } 
    166114         
    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(); 
    171128        } 
    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; 
    175135    } 
    176136 
     
    185145    } 
    186146 
    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: comment 
    211      *  
    212      * @param i 
    213      * @return 
    214      */ 
    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     @Override 
    225     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 exception 
    241             e.printStackTrace(); 
    242         } 
    243  
    244         return clone; 
    245     } 
    246  
    247147} 
Note: See TracChangeset for help on using the changeset viewer.