source: branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/RuleUtils.java @ 1654

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

Adding Debug output to find this freaking damn error.

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