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