Ignore:
Timestamp:
01/24/14 13:48:25 (10 years ago)
Author:
pharms
Message:
  • improvement and correction of the task tree decoder to handle optionals correctly
Location:
trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeDecoder.java

    r1327 r1333  
    2929import de.ugoe.cs.autoquest.eventcore.IEventType; 
    3030import de.ugoe.cs.autoquest.eventcore.StringEventType; 
     31import de.ugoe.cs.autoquest.eventcore.gui.Scroll; 
    3132import de.ugoe.cs.autoquest.eventcore.gui.TextInput; 
    3233import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 
     
    103104        correctTargets(taskInstanceList); 
    104105         
     106        // validate the instance list 
     107        try { 
     108            new TaskTreeValidator().validate(taskInstanceList); 
     109        } 
     110        catch (java.lang.AssertionError e) { 
     111            throw new IllegalArgumentException(e.getMessage(), e); 
     112        } 
     113         
    105114        return taskInstanceList; 
    106115    } 
     
    226235        } 
    227236 
    228         // validate the instance 
    229         try { 
    230             new TaskTreeValidator().validate(instance); 
    231         } 
    232         catch (java.lang.AssertionError e) { 
    233             throw new IllegalArgumentException(e.getMessage(), e); 
    234         } 
    235          
    236237        return instance; 
    237238    } 
     
    318319            } 
    319320        } 
     321        else if ("Optional".equals(type)) { 
     322            // update the optional with what is optional if available 
     323            if (children.size() == 1) { 
     324                ITask newChildTask = children.get(0).getTask(); 
     325                 
     326                if (((IOptional) task).getMarkedTask() == null) { 
     327                    taskBuilder.setMarkedTask((IOptional) task, newChildTask); 
     328                } 
     329                else if (!((IOptional) task).getMarkedTask().equals(newChildTask)) { 
     330                    throw new IllegalArgumentException("all children of the same optional must " + 
     331                                                       "be of an identical task model."); 
     332                } 
     333            } 
     334        } 
    320335 
    321336        return task; 
     
    349364     * @return 
    350365     */ 
    351     private IEventType determineType(String type, String enteredText) { 
     366    private IEventType determineType(String type, String additionalInfo) { 
    352367        if ("TextInput".equals(type)) { 
    353             return new TextInput(enteredText, new ArrayList<Event>()); 
     368            return new TextInput(additionalInfo, new ArrayList<Event>()); 
     369        } 
     370        else if ("Scroll".equals(type)) { 
     371            int x = 0; 
     372            int y = 0; 
     373            if (additionalInfo != null) { 
     374                String[] parts = additionalInfo.split(" "); 
     375                if (parts.length > 0) { 
     376                    try { 
     377                        x = Integer.parseInt(parts[0]); 
     378                    } 
     379                    catch (NumberFormatException e) { 
     380                        throw new IllegalArgumentException("could not parse scroll coordinates", e); 
     381                    } 
     382                } 
     383                if (parts.length > 1) { 
     384                    try { 
     385                        y = Integer.parseInt(parts[1]); 
     386                    } 
     387                    catch (NumberFormatException e) { 
     388                        throw new IllegalArgumentException("could not parse scroll coordinates", e); 
     389                    } 
     390                } 
     391            } 
     392            return new Scroll(x, y); 
    354393        } 
    355394        else { 
     
    428467        else if (instance instanceof IOptionalInstance) { 
    429468            IOptionalInstance optInst = (IOptionalInstance) instance; 
    430             taskBuilder.setChild(optInst, replaceTargets(optInst.getChild(), replacements)); 
     469            if (optInst.getChild() != null) { 
     470                taskBuilder.setChild(optInst, replaceTargets(optInst.getChild(), replacements)); 
     471            } 
    431472        } 
    432473        else if ((instance instanceof IEventTaskInstance) && 
  • trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeValidator.java

    r1294 r1333  
    126126                        childTask instanceof IOptional); 
    127127             
    128             assertNotNull("number of children of optional instance must be 1", 
    129                           ((IOptionalInstance) taskInstance).getChild()); 
    130              
    131             assertEquals("task of optional child does not match optional model", 
    132                          childTask, ((IOptionalInstance) taskInstance).getChild().getTask()); 
     128            if (((IOptionalInstance) taskInstance).getChild() != null) { 
     129                assertEquals("task of optional child does not match optional model", 
     130                             childTask, ((IOptionalInstance) taskInstance).getChild().getTask()); 
     131            } 
    133132        } 
    134133        else if (taskInstance.getTask() instanceof IEventTask) { 
     
    151150        } 
    152151        else if (taskInstance instanceof IOptionalInstance) { 
    153             validate(((IOptionalInstance) taskInstance).getChild()); 
     152            if (((IOptionalInstance) taskInstance).getChild() != null) { 
     153                validate(((IOptionalInstance) taskInstance).getChild()); 
     154            } 
    154155        } 
    155156    } 
Note: See TracChangeset for help on using the changeset viewer.