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 | |
---|
15 | package de.ugoe.cs.autoquest.tasktrees.temporalrelation; |
---|
16 | |
---|
17 | import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality; |
---|
18 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; |
---|
19 | import de.ugoe.cs.autoquest.usageprofiles.SymbolComparator; |
---|
20 | import de.ugoe.cs.autoquest.usageprofiles.SymbolMap; |
---|
21 | import de.ugoe.cs.autoquest.usageprofiles.SymbolStrategy; |
---|
22 | |
---|
23 | // TODO: Auto-generated Javadoc |
---|
24 | /** |
---|
25 | * <p> |
---|
26 | * concrete implementation of a symbol strategy required in the creation of a |
---|
27 | * {@link de.ugoe.cs.autoquest.usageprofiles.Trie}. The strategy can be |
---|
28 | * parameterized with a considered task equality. It uses task instance |
---|
29 | * comparators to perform task comparison. It creates task specific symbol maps, |
---|
30 | * which are {@link TaskSymbolIdentityMap} and {@link TaskSymbolBucketedMap} |
---|
31 | * depending on the level of considered task equality. |
---|
32 | * </p> |
---|
33 | * |
---|
34 | * @author Patrick Harms |
---|
35 | */ |
---|
36 | public class TaskHandlingStrategy implements SymbolStrategy<ITaskInstance> { |
---|
37 | |
---|
38 | /** The Constant serialVersionUID. */ |
---|
39 | private static final long serialVersionUID = 1L; |
---|
40 | |
---|
41 | /** <p> the level of task equality considered in this task handling strategy </p>. */ |
---|
42 | private final TaskEquality consideredEquality; |
---|
43 | |
---|
44 | /** <p> the comparator used for task comparisons </p>. */ |
---|
45 | private TaskInstanceComparator comparator; |
---|
46 | |
---|
47 | /** |
---|
48 | * <p> |
---|
49 | * initializes this strategy with a task equality to be considered for task |
---|
50 | * comparisons g |
---|
51 | * </p>. |
---|
52 | * |
---|
53 | * @param consideredEquality the task equality to be considered for task comparisons |
---|
54 | */ |
---|
55 | public TaskHandlingStrategy(TaskEquality consideredEquality) { |
---|
56 | this.consideredEquality = consideredEquality; |
---|
57 | |
---|
58 | if (this.consideredEquality == TaskEquality.IDENTICAL) { |
---|
59 | comparator = new TaskIdentityComparator(); |
---|
60 | } else { |
---|
61 | comparator = new TaskInstanceComparator(this.consideredEquality); |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | /* |
---|
66 | * (non-Javadoc) |
---|
67 | * |
---|
68 | * @see |
---|
69 | * de.ugoe.cs.autoquest.usageprofiles.SymbolStrategy#copySymbolMap(SymbolMap |
---|
70 | * ) |
---|
71 | */ |
---|
72 | @Override |
---|
73 | public <V> SymbolMap<ITaskInstance, V> copySymbolMap( |
---|
74 | SymbolMap<ITaskInstance, V> other) { |
---|
75 | if (consideredEquality == TaskEquality.IDENTICAL) { |
---|
76 | return new TaskSymbolIdentityMap<V>(other); |
---|
77 | } else { |
---|
78 | return new TaskSymbolBucketedMap<V>(comparator); |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | /* |
---|
83 | * (non-Javadoc) |
---|
84 | * |
---|
85 | * @see de.ugoe.cs.autoquest.usageprofiles.SymbolStrategy#createSymbolMap() |
---|
86 | */ |
---|
87 | @Override |
---|
88 | public <V> SymbolMap<ITaskInstance, V> createSymbolMap() { |
---|
89 | if (consideredEquality == TaskEquality.IDENTICAL) { |
---|
90 | return new TaskSymbolIdentityMap<V>(); |
---|
91 | } else { |
---|
92 | return new TaskSymbolBucketedMap<V>(comparator); |
---|
93 | } |
---|
94 | } |
---|
95 | |
---|
96 | /* |
---|
97 | * (non-Javadoc) |
---|
98 | * |
---|
99 | * @see |
---|
100 | * de.ugoe.cs.autoquest.usageprofiles.SymbolStrategy#getSymbolComparator() |
---|
101 | */ |
---|
102 | @Override |
---|
103 | public SymbolComparator<ITaskInstance> getSymbolComparator() { |
---|
104 | return comparator; |
---|
105 | } |
---|
106 | |
---|
107 | /** |
---|
108 | * <p> |
---|
109 | * convenience method to have a correctly typed return value as alternative |
---|
110 | * to {@link #getSymbolComparator()}; |
---|
111 | * </p>. |
---|
112 | * |
---|
113 | * @return the task comparator |
---|
114 | */ |
---|
115 | public TaskInstanceComparator getTaskComparator() { |
---|
116 | return comparator; |
---|
117 | } |
---|
118 | |
---|
119 | } |
---|