source: branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/RuleUtils.java @ 1645

Last change on this file since 1645 was 1645, checked in by rkrimmel, 10 years ago

Trying to replace event instances in the sessions

File size: 4.9 KB
RevLine 
[1107]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
15package de.ugoe.cs.autoquest.tasktrees.temporalrelation;
16
[1294]17import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;
18import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance;
[1146]19import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder;
20import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
21import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList;
22import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory;
[1107]23
24/**
25 * <p>
[1281]26 * provides some convenience methods for rule application
[1107]27 * </p>
28 *
29 * @author Patrick Harms
30 */
31class RuleUtils {
32   
[1281]33    /**
34     * <p>
35     * counter for generating unique ids. Starts at 0 for each new program start
36     * </p>
37     */
[1107]38    private static int idCounter = 0;
39
40    /**
[1281]41     * <p>
42     * generates a sub sequence for a specified range of elements in the provided task instances
43     * list.
44     * </p>
45     *
46     * @param parent      the list of which the range shall be extracted
47     * @param startIndex  the start index of the range
48     * @param endIndex    the end index of the range (inclusive)
49     * @param model       the task model (required for instantiating the sub sequence)
50     * @param taskFactory the task factory used for instantiating the sub sequence
51     * @param taskBuilder the task builder to perform changes in the task structure
[1107]52     *
[1281]53     * @return a task instance representing the requested sub sequence
[1107]54     */
[1146]55    static ITaskInstance getSubSequenceInRange(ITaskInstanceList parent,
56                                               int               startIndex,
57                                               int               endIndex,
[1294]58                                               ISequence         model,
[1146]59                                               ITaskFactory      taskFactory,
60                                               ITaskBuilder      taskBuilder)
[1127]61    {
[1294]62        ISequenceInstance subsequence = taskFactory.createNewTaskInstance(model);
[1127]63
64        for (int i = startIndex; i <= endIndex; i++) {
[1146]65            taskBuilder.addChild(subsequence, parent.get(i));
[1127]66        }
67
[1146]68        return subsequence;
[1127]69    }
70
71    /**
[1281]72     * <p>
73     * replaces a sub sequence for a specified range of elements in the provided task instances
74     * list by a sub task instance
75     * </p>
76     *
77     * @param parent      the list of which the range shall be replaced
78     * @param startIndex  the start index of the range
79     * @param endIndex    the end index of the range (inclusive)
80     * @param model       the task model (required for instantiating the sub sequence)
81     * @param taskFactory the task factory used for instantiating the sub sequence
82     * @param taskBuilder the task builder to perform changes in the task structure
[1127]83     *
[1281]84     * @return the replacement for the range
[1127]85     */
[1294]86    static ISequenceInstance createNewSubSequenceInRange(ITaskInstanceList parent,
87                                                         int               startIndex,
88                                                         int               endIndex,
89                                                         ISequence         model,
90                                                         ITaskFactory      taskFactory,
91                                                         ITaskBuilder      taskBuilder)
[1107]92    {
[1294]93        ISequenceInstance subsequence = taskFactory.createNewTaskInstance(model);
[1645]94       
95       
96       
97        System.out.println("Got model: " + model.toString());
98       
99       
100       
101       
102       
103        System.out.println(parent);
104        //System.out.println(parent.get(startIndex));
[1107]105        for (int i = startIndex; i <= endIndex; i++) {
[1645]106                System.out.println("Trying to add "+ parent.get(startIndex) + " to the model");
[1146]107            taskBuilder.addChild(subsequence, parent.get(startIndex));
[1645]108           
[1146]109            taskBuilder.removeTaskInstance(parent, startIndex);
[1107]110        }
111
[1146]112        taskBuilder.addTaskInstance(parent, startIndex, subsequence);
113
114        return subsequence;
[1107]115    }
116
117    /**
[1281]118     * <p>
119     * returns the next available id (uses the id counter)
120     * </p>
121     *
122     * @return the next available id
[1107]123     */
[1127]124    static synchronized String getNewId() {
[1107]125        return Integer.toString(idCounter++);
126    }
127
128    /**
[1281]129     * <p>
130     * prevent instantiation
131     * </p>
[1107]132     */
133    private RuleUtils() {
134        // prevent instantiation
135    }
136
137}
Note: See TracBrowser for help on using the repository browser.