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/TaskModel.java

    r1132 r1146  
    1515package de.ugoe.cs.autoquest.tasktrees.treeimpl; 
    1616 
     17import java.util.Collection; 
     18import java.util.Collections; 
    1719import java.util.HashMap; 
     20import java.util.List; 
    1821import java.util.Map; 
    1922 
    20 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree; 
    21 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 
    22 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNodeInfo; 
     23import de.ugoe.cs.autoquest.tasktrees.treeifc.IMarkingTemporalRelationship; 
     24import de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship; 
     25import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     26import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
     27import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; 
     28import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInfo; 
     29import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 
    2330 
    2431/** 
     
    2835 * @author 2012, last modified by $Author: patrick$ 
    2936 */ 
    30 public class TaskTree implements ITaskTree { 
     37class TaskModel implements ITaskModel { 
    3138     
    32     /** the map of nodes */ 
    33     private Map<ITaskTreeNode, ITaskTreeNodeInfo> taskMap; 
     39    /** */ 
     40    private static final long serialVersionUID = 1L; 
    3441 
    35     /** the root node of the task tree */ 
    36     private ITaskTreeNode rootNode; 
     42    /** the map of tasks */ 
     43    private List<IUserSession> userSessions; 
     44 
     45    /** the map of tasks */ 
     46    private Map<ITask, TaskInfo> taskMap = new HashMap<ITask, TaskInfo>(); 
    3747 
    3848    /** 
    39      * TODO: comment 
    40      *  
     49     * 
    4150     */ 
    42     TaskTree(ITaskTreeNode rootNode) { 
    43         this.rootNode = rootNode; 
     51    TaskModel(List<IUserSession> userSessions) { 
     52        if ((userSessions == null) || (userSessions.size() == 0)) { 
     53            throw new IllegalArgumentException("user sessions must not be null"); 
     54        } 
     55         
     56        this.userSessions = userSessions; 
     57         
     58        for (IUserSession session : this.userSessions) { 
     59            for (ITaskInstance taskInstance : session) { 
     60                addTaskToMap(taskInstance.getTask()); 
     61            } 
     62        } 
    4463    } 
    4564 
    46     /* 
    47      * (non-Javadoc) 
    48      *  
    49      * @see de.ugoe.cs.tasktree.treeifc.TaskTree#getRoot() 
     65 
     66    /* (non-Javadoc) 
     67     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getUserSessions() 
    5068     */ 
    5169    @Override 
    52     public ITaskTreeNode getRoot() { 
    53         return rootNode; 
     70    public List<IUserSession> getUserSessions() { 
     71        return Collections.unmodifiableList(userSessions); 
    5472    } 
    5573 
    56     /* 
    57      * (non-Javadoc) 
    58      *  
    59      * @see de.ugoe.cs.tasktree.treeifc.TaskTree#getTaskMap() 
     74 
     75    /* (non-Javadoc) 
     76     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getTasks() 
    6077     */ 
    6178    @Override 
    62     public synchronized Map<ITaskTreeNode, ITaskTreeNodeInfo> getTaskMap() { 
    63         if (taskMap == null) { 
    64             taskMap = new HashMap<ITaskTreeNode, ITaskTreeNodeInfo>(); 
    65             addNodeToMap(rootNode, null); 
    66         } 
    67         return taskMap; 
     79    public Collection<ITask> getTasks() { 
     80        return Collections.unmodifiableCollection(taskMap.keySet()); 
     81    } 
     82 
     83 
     84    /* (non-Javadoc) 
     85     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getTaskInfo(de.ugoe.cs.autoquest.tasktrees.treeifc.ITask) 
     86     */ 
     87    @Override 
     88    public ITaskInfo getTaskInfo(ITask task) { 
     89        return taskMap.get(task); 
    6890    } 
    6991 
    7092    /** 
    71      * TODO: comment 
    72      *  
    73      * @param rootNode 
     93     * 
    7494     */ 
    75     private void addNodeToMap(ITaskTreeNode node, ITaskTreeNode parent) { 
    76         NodeInfo nodeInfo = (NodeInfo) taskMap.get(node); 
     95    private void addTaskToMap(ITask task) { 
     96        TaskInfo taskInfo = taskMap.get(task); 
    7797 
    78         if (nodeInfo == null) { 
    79             nodeInfo = new NodeInfo(node); 
    80             taskMap.put(node, nodeInfo); 
     98        if (taskInfo == null) { 
     99            taskInfo = new TaskInfo(task); 
     100            taskMap.put(task, taskInfo); 
    81101        } 
    82102 
    83         if (parent != null) { 
    84             // through first removing an existing parent it is assured, that a parent is recorded 
    85             // only once. This is needed, because parent may be reused in a tree as well, but we 
    86             // always iterate the whole tree 
    87             //nodeInfo.removeParent(parent); 
    88             nodeInfo.addParent(parent); 
     103        if (task instanceof IStructuringTemporalRelationship) { 
     104            for (ITask child : ((IStructuringTemporalRelationship) task).getChildren()) { 
     105                addTaskToMap(child); 
     106            } 
    89107        } 
    90  
    91         for (ITaskTreeNode child : node.getChildren()) { 
    92             addNodeToMap(child, node); 
     108        else if (task instanceof IMarkingTemporalRelationship) { 
     109            addTaskToMap(((IMarkingTemporalRelationship) task).getMarkedTask()); 
    93110        } 
    94111    } 
     
    100117     */ 
    101118    @Override 
    102     public TaskTree clone() { 
    103         TaskTree clone = null; 
    104         try { 
    105             clone = (TaskTree) super.clone(); 
    106  
    107             clone.rootNode = rootNode.clone(); 
    108  
    109             // the clone will create the task map itself, when it is first retrieved 
    110             clone.taskMap = null; 
    111  
    112         } 
    113         catch (CloneNotSupportedException e) { 
    114             // this should never happen. Therefore simply dump the exception 
    115             e.printStackTrace(); 
    116         } 
    117  
    118         return clone; 
     119    public TaskModel clone() { 
     120        return new TaskModel(userSessions); 
    119121    } 
    120122 
Note: See TracChangeset for help on using the changeset viewer.