[1260] | 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 | |
---|
[2146] | 15 | package de.ugoe.cs.autoquest.eventcore; |
---|
[1260] | 16 | |
---|
| 17 | import java.util.Collections; |
---|
| 18 | import java.util.LinkedList; |
---|
| 19 | import java.util.List; |
---|
| 20 | |
---|
| 21 | /** |
---|
| 22 | * <p> |
---|
[2146] | 23 | * This class is a dummy hierarchical event target to represent groups of event targets. A group of |
---|
| 24 | * event targets can be integrated in any hierarchical event target model using the method |
---|
| 25 | * {@link HierarchicalEventTargetModel#groupEventTargets(List, String, IEventTargetFactory)}. A |
---|
| 26 | * group has the same behavior as any other parent hierarchical event target. |
---|
[1260] | 27 | * </p> |
---|
| 28 | * |
---|
| 29 | * @author Patrick Harms |
---|
| 30 | */ |
---|
[2146] | 31 | public class HierarchicalEventTargetGroup extends AbstractDefaultHierarchicalEventTarget { |
---|
[1260] | 32 | |
---|
[1274] | 33 | /** |
---|
| 34 | * <p> |
---|
| 35 | * default serial version UID |
---|
| 36 | * </p> |
---|
| 37 | */ |
---|
[1260] | 38 | private static final long serialVersionUID = 1L; |
---|
| 39 | |
---|
| 40 | /** |
---|
[2146] | 41 | * the list of grouped event targets |
---|
[1260] | 42 | */ |
---|
[2146] | 43 | private List<IHierarchicalEventTarget> groupedEventTargets = |
---|
| 44 | new LinkedList<IHierarchicalEventTarget>(); |
---|
[1260] | 45 | |
---|
| 46 | /** |
---|
| 47 | * <p> |
---|
[2146] | 48 | * instantiates an event target group with a name and its optional parent event target |
---|
[1260] | 49 | * </p> |
---|
| 50 | * |
---|
[2146] | 51 | * @param groupName the name of the event target group |
---|
| 52 | * @param parent the optional parent event target of the group |
---|
| 53 | * @param eventTargetModel the event target model to which the group will belong |
---|
[1260] | 54 | */ |
---|
[2146] | 55 | public HierarchicalEventTargetGroup(String groupName, |
---|
| 56 | IHierarchicalEventTarget parent, |
---|
| 57 | HierarchicalEventTargetModel<?> eventTargetModel) |
---|
| 58 | { |
---|
[1260] | 59 | super(new GroupSpecification(groupName), parent); |
---|
[2146] | 60 | super.setEventTargetModel(eventTargetModel); |
---|
[1260] | 61 | } |
---|
| 62 | |
---|
| 63 | /* (non-Javadoc) |
---|
| 64 | * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getPlatform() |
---|
| 65 | */ |
---|
| 66 | @Override |
---|
| 67 | public String getPlatform() { |
---|
| 68 | return "none"; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | /* (non-Javadoc) |
---|
| 72 | * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getStringIdentifier() |
---|
| 73 | */ |
---|
| 74 | @Override |
---|
| 75 | public String getStringIdentifier() { |
---|
| 76 | return ((GroupSpecification) super.getSpecification()).name; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | /* (non-Javadoc) |
---|
| 80 | * @see java.lang.Object#toString() |
---|
| 81 | */ |
---|
| 82 | @Override |
---|
| 83 | public String toString() { |
---|
| 84 | return getStringIdentifier(); |
---|
| 85 | } |
---|
| 86 | |
---|
[1490] | 87 | /* (non-Javadoc) |
---|
[2146] | 88 | * @see IHierarchicalEventTarget#updateSpecification(IEventTargetSpec) |
---|
[1876] | 89 | */ |
---|
| 90 | @Override |
---|
[2146] | 91 | public void updateSpecification(IEventTargetSpec furtherSpec) { |
---|
| 92 | // do nothing |
---|
[1876] | 93 | } |
---|
| 94 | |
---|
[1260] | 95 | /** |
---|
| 96 | * <p> |
---|
[2146] | 97 | * returns the list of event targets belonging to this group. |
---|
[1260] | 98 | * </p> |
---|
[1274] | 99 | * |
---|
[2146] | 100 | * @return the event targets belonging to this group |
---|
[1274] | 101 | * |
---|
[1260] | 102 | */ |
---|
[2146] | 103 | public List<IHierarchicalEventTarget> getGroupedEventTargets() { |
---|
| 104 | return Collections.unmodifiableList(groupedEventTargets); |
---|
[1260] | 105 | } |
---|
| 106 | |
---|
| 107 | /** |
---|
[1274] | 108 | * <p> |
---|
[2146] | 109 | * allows adding a new event target to the group |
---|
[1274] | 110 | * </p> |
---|
| 111 | * |
---|
[2146] | 112 | * @param eventTarget the new member of the group |
---|
[1260] | 113 | */ |
---|
[2146] | 114 | void addToGroup(IHierarchicalEventTarget eventTarget) { |
---|
| 115 | this.groupedEventTargets.add(eventTarget); |
---|
[1260] | 116 | } |
---|
| 117 | |
---|
| 118 | /** |
---|
| 119 | * <p> |
---|
[2146] | 120 | * internally required event target specification for an event target group. This is just a |
---|
| 121 | * wrapper for a name of an event target group |
---|
[1260] | 122 | * </p> |
---|
| 123 | * |
---|
| 124 | * @author Patrick Harms |
---|
| 125 | */ |
---|
[2146] | 126 | private static class GroupSpecification implements IEventTargetSpec { |
---|
[1260] | 127 | |
---|
[1274] | 128 | /** |
---|
| 129 | * <p> |
---|
| 130 | * default serial version UID |
---|
| 131 | * </p> |
---|
| 132 | */ |
---|
[1260] | 133 | private static final long serialVersionUID = 1L; |
---|
[1274] | 134 | |
---|
[1260] | 135 | /** |
---|
[1274] | 136 | * <p> |
---|
[2146] | 137 | * the name of the event target group represented by this specification |
---|
[1274] | 138 | * </p> |
---|
[1260] | 139 | */ |
---|
| 140 | private String name; |
---|
| 141 | |
---|
| 142 | /** |
---|
| 143 | * <p> |
---|
| 144 | * instantiates the group specification with the given name. Two group specifications |
---|
| 145 | * are only similar, if their names match. |
---|
| 146 | * </p> |
---|
| 147 | * |
---|
| 148 | * @param name the name of the group |
---|
| 149 | */ |
---|
| 150 | private GroupSpecification(String name) { |
---|
| 151 | super(); |
---|
| 152 | this.name = name; |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | /* (non-Javadoc) |
---|
[2146] | 156 | * @see IEventTargetSpec#getSimilarity(IEventTargetSpec) |
---|
[1260] | 157 | */ |
---|
| 158 | @Override |
---|
[2146] | 159 | public boolean getSimilarity(IEventTargetSpec other) { |
---|
[1260] | 160 | return |
---|
| 161 | (other instanceof GroupSpecification) && |
---|
| 162 | name.equals(((GroupSpecification) other).name); |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | } |
---|