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.eventcore; |
---|
16 | |
---|
17 | import java.util.Collections; |
---|
18 | import java.util.LinkedList; |
---|
19 | import java.util.List; |
---|
20 | |
---|
21 | /** |
---|
22 | * <p> |
---|
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. |
---|
27 | * </p> |
---|
28 | * |
---|
29 | * @author Patrick Harms |
---|
30 | */ |
---|
31 | public class HierarchicalEventTargetGroup extends AbstractDefaultHierarchicalEventTarget { |
---|
32 | |
---|
33 | /** |
---|
34 | * <p> |
---|
35 | * default serial version UID |
---|
36 | * </p> |
---|
37 | */ |
---|
38 | private static final long serialVersionUID = 1L; |
---|
39 | |
---|
40 | /** |
---|
41 | * the list of grouped event targets |
---|
42 | */ |
---|
43 | private List<IHierarchicalEventTarget> groupedEventTargets = |
---|
44 | new LinkedList<IHierarchicalEventTarget>(); |
---|
45 | |
---|
46 | /** |
---|
47 | * <p> |
---|
48 | * instantiates an event target group with a name and its optional parent event target |
---|
49 | * </p> |
---|
50 | * |
---|
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 |
---|
54 | */ |
---|
55 | public HierarchicalEventTargetGroup(String groupName, |
---|
56 | IHierarchicalEventTarget parent, |
---|
57 | HierarchicalEventTargetModel<?> eventTargetModel) |
---|
58 | { |
---|
59 | super(new GroupSpecification(groupName), parent); |
---|
60 | super.setEventTargetModel(eventTargetModel); |
---|
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 | |
---|
87 | /* (non-Javadoc) |
---|
88 | * @see IHierarchicalEventTarget#updateSpecification(IEventTargetSpec) |
---|
89 | */ |
---|
90 | @Override |
---|
91 | public void updateSpecification(IEventTargetSpec furtherSpec) { |
---|
92 | // do nothing |
---|
93 | } |
---|
94 | |
---|
95 | /** |
---|
96 | * <p> |
---|
97 | * returns the list of event targets belonging to this group. |
---|
98 | * </p> |
---|
99 | * |
---|
100 | * @return the event targets belonging to this group |
---|
101 | * |
---|
102 | */ |
---|
103 | public List<IHierarchicalEventTarget> getGroupedEventTargets() { |
---|
104 | return Collections.unmodifiableList(groupedEventTargets); |
---|
105 | } |
---|
106 | |
---|
107 | /** |
---|
108 | * <p> |
---|
109 | * allows adding a new event target to the group |
---|
110 | * </p> |
---|
111 | * |
---|
112 | * @param eventTarget the new member of the group |
---|
113 | */ |
---|
114 | void addToGroup(IHierarchicalEventTarget eventTarget) { |
---|
115 | this.groupedEventTargets.add(eventTarget); |
---|
116 | } |
---|
117 | |
---|
118 | /** |
---|
119 | * <p> |
---|
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 |
---|
122 | * </p> |
---|
123 | * |
---|
124 | * @author Patrick Harms |
---|
125 | */ |
---|
126 | private static class GroupSpecification implements IEventTargetSpec { |
---|
127 | |
---|
128 | /** |
---|
129 | * <p> |
---|
130 | * default serial version UID |
---|
131 | * </p> |
---|
132 | */ |
---|
133 | private static final long serialVersionUID = 1L; |
---|
134 | |
---|
135 | /** |
---|
136 | * <p> |
---|
137 | * the name of the event target group represented by this specification |
---|
138 | * </p> |
---|
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) |
---|
156 | * @see IEventTargetSpec#getSimilarity(IEventTargetSpec) |
---|
157 | */ |
---|
158 | @Override |
---|
159 | public boolean getSimilarity(IEventTargetSpec other) { |
---|
160 | return |
---|
161 | (other instanceof GroupSpecification) && |
---|
162 | name.equals(((GroupSpecification) other).name); |
---|
163 | } |
---|
164 | |
---|
165 | } |
---|
166 | |
---|
167 | } |
---|