comparison src/org/eclipse/jetty/util/component/AggregateLifeCycle.java @ 910:9b65e8064f90

simplify AggregateLifeCycle
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 08 Oct 2016 21:30:32 -0600
parents e21ca9878a10
children 1d0c304e12b5
comparison
equal deleted inserted replaced
909:c60c1adfac3e 910:9b65e8064f90
134 /* ------------------------------------------------------------ */ 134 /* ------------------------------------------------------------ */
135 /** Is the bean contained in the aggregate. 135 /** Is the bean contained in the aggregate.
136 * @param bean 136 * @param bean
137 * @return True if the aggregate contains the bean 137 * @return True if the aggregate contains the bean
138 */ 138 */
139 public boolean contains(Object bean) 139 private boolean contains(Object bean)
140 { 140 {
141 for (Bean b:_beans) 141 for (Bean b:_beans)
142 if (b._bean==bean) 142 if (b._bean==bean)
143 return true; 143 return true;
144 return false;
145 }
146
147 /* ------------------------------------------------------------ */
148 /** Is the bean joined to the aggregate.
149 * @param bean
150 * @return True if the aggregate contains the bean and it is joined
151 */
152 public boolean isManaged(Object bean)
153 {
154 for (Bean b:_beans)
155 if (b._bean==bean)
156 return b._managed;
157 return false; 144 return false;
158 } 145 }
159 146
160 /* ------------------------------------------------------------ */ 147 /* ------------------------------------------------------------ */
161 /** 148 /**
212 /** Get dependent beans 199 /** Get dependent beans
213 * @return List of beans. 200 * @return List of beans.
214 */ 201 */
215 public Collection<Object> getBeans() 202 public Collection<Object> getBeans()
216 { 203 {
217 return getBeans(Object.class); 204 List<Object> beans = new ArrayList<Object>();
218 } 205 beans.addAll(_beans);
219
220 /* ------------------------------------------------------------ */
221 /** Get dependent beans of a specific class
222 * @see #addBean(Object)
223 * @param clazz
224 * @return List of beans.
225 */
226 public <T> List<T> getBeans(Class<T> clazz)
227 {
228 ArrayList<T> beans = new ArrayList<T>();
229 for (Bean b:_beans)
230 {
231 if (clazz.isInstance(b._bean))
232 beans.add((T)(b._bean));
233 }
234 return beans; 206 return beans;
235 } 207 }
236 208
237 209
238 /* ------------------------------------------------------------ */ 210 /* ------------------------------------------------------------ */
251 } 223 }
252 224
253 return null; 225 return null;
254 } 226 }
255 227
256 /* ------------------------------------------------------------ */
257 /**
258 * Remove all associated bean.
259 */
260 public void removeBeans ()
261 {
262 _beans.clear();
263 }
264
265 /* ------------------------------------------------------------ */ 228 /* ------------------------------------------------------------ */
266 /** 229 /**
267 * Remove an associated bean. 230 * Remove an associated bean.
268 */ 231 */
269 public boolean removeBean (Object o) 232 public boolean removeBean (Object o)