1 17 package org.eclipse.emf.edit.provider; 18 19 20 import java.util.Collection ; 21 import java.util.HashSet ; 22 import java.util.Iterator ; 23 24 25 28 public class Disposable extends HashSet implements IDisposable 29 { 30 33 public Disposable() 34 { 35 } 36 37 40 public Disposable(Collection disposables) 41 { 42 super(disposables); 43 } 44 45 48 public void dispose() 49 { 50 for (Iterator disposables = iterator(); disposables.hasNext(); ) 51 { 52 IDisposable disposable = (IDisposable)disposables.next(); 53 disposable.dispose(); 54 } 55 clear(); 56 } 57 58 public boolean add(Object 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 collection) 71 { 72 boolean result = false; 73 for (Iterator objects = collection.iterator(); objects.hasNext(); ) 74 { 75 Object object = objects.next(); 76 if (add(object)) 77 { 78 result = true; 79 } 80 } 81 return result; 82 } 83 } 84 | Popular Tags |