KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > edit > provider > Disposable


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: Disposable.java,v 1.2 2005/06/08 06:17:05 nickb Exp $
16  */

17 package org.eclipse.emf.edit.provider;
18
19
20 import java.util.Collection JavaDoc;
21 import java.util.HashSet JavaDoc;
22 import java.util.Iterator JavaDoc;
23
24
25 /**
26  * This implements {@link IDisposable} as a set IDisposables that can in turn be disposed.
27  */

28 public class Disposable extends HashSet JavaDoc implements IDisposable
29 {
30   /**
31    * This creates an empty instance.
32    */

33   public Disposable()
34   {
35   }
36
37   /**
38    * This creates an instance with containing all the given disposables.
39    */

40   public Disposable(Collection JavaDoc disposables)
41   {
42     super(disposables);
43   }
44
45   /**
46    * This is called to dispose the disposables.
47    */

48   public void dispose()
49   {
50     for (Iterator JavaDoc disposables = iterator(); disposables.hasNext(); )
51     {
52       IDisposable disposable = (IDisposable)disposables.next();
53       disposable.dispose();
54     }
55     clear();
56   }
57
58   public boolean add(Object JavaDoc object)
59   {
60     if (object instanceof IDisposable)
61     {
62       return super.add(object);
63     }
64     else
65     {
66       return false;
67     }
68   }
69
70   public boolean addAll(Collection JavaDoc collection)
71   {
72     boolean result = false;
73     for (Iterator JavaDoc objects = collection.iterator(); objects.hasNext(); )
74     {
75       Object JavaDoc object = objects.next();
76       if (add(object))
77       {
78         result = true;
79       }
80     }
81     return result;
82   }
83 }
84
Popular Tags