src/share/classes/java/util/Observable.java

Print this page
rev 4788 : Fix bunch of generics warnings


  44  * notifications on separate threads, or may guarantee that their
  45  * subclass follows this order, as they choose.
  46  * <p>
  47  * Note that this notification mechanism has nothing to do with threads
  48  * and is completely separate from the <tt>wait</tt> and <tt>notify</tt>
  49  * mechanism of class <tt>Object</tt>.
  50  * <p>
  51  * When an observable object is newly created, its set of observers is
  52  * empty. Two observers are considered the same if and only if the
  53  * <tt>equals</tt> method returns true for them.
  54  *
  55  * @author  Chris Warth
  56  * @see     java.util.Observable#notifyObservers()
  57  * @see     java.util.Observable#notifyObservers(java.lang.Object)
  58  * @see     java.util.Observer
  59  * @see     java.util.Observer#update(java.util.Observable, java.lang.Object)
  60  * @since   JDK1.0
  61  */
  62 public class Observable {
  63     private boolean changed = false;
  64     private Vector obs;
  65 
  66     /** Construct an Observable with zero Observers. */
  67 
  68     public Observable() {
  69         obs = new Vector();
  70     }
  71 
  72     /**
  73      * Adds an observer to the set of observers for this object, provided
  74      * that it is not the same as some observer already in the set.
  75      * The order in which notifications will be delivered to multiple
  76      * observers is not specified. See the class comment.
  77      *
  78      * @param   o   an observer to be added.
  79      * @throws NullPointerException   if the parameter o is null.
  80      */
  81     public synchronized void addObserver(Observer o) {
  82         if (o == null)
  83             throw new NullPointerException();
  84         if (!obs.contains(o)) {
  85             obs.addElement(o);
  86         }
  87     }
  88 
  89     /**




  44  * notifications on separate threads, or may guarantee that their
  45  * subclass follows this order, as they choose.
  46  * <p>
  47  * Note that this notification mechanism has nothing to do with threads
  48  * and is completely separate from the <tt>wait</tt> and <tt>notify</tt>
  49  * mechanism of class <tt>Object</tt>.
  50  * <p>
  51  * When an observable object is newly created, its set of observers is
  52  * empty. Two observers are considered the same if and only if the
  53  * <tt>equals</tt> method returns true for them.
  54  *
  55  * @author  Chris Warth
  56  * @see     java.util.Observable#notifyObservers()
  57  * @see     java.util.Observable#notifyObservers(java.lang.Object)
  58  * @see     java.util.Observer
  59  * @see     java.util.Observer#update(java.util.Observable, java.lang.Object)
  60  * @since   JDK1.0
  61  */
  62 public class Observable {
  63     private boolean changed = false;
  64     private Vector<Observer> obs;
  65 
  66     /** Construct an Observable with zero Observers. */
  67 
  68     public Observable() {
  69         obs = new Vector<>();
  70     }
  71 
  72     /**
  73      * Adds an observer to the set of observers for this object, provided
  74      * that it is not the same as some observer already in the set.
  75      * The order in which notifications will be delivered to multiple
  76      * observers is not specified. See the class comment.
  77      *
  78      * @param   o   an observer to be added.
  79      * @throws NullPointerException   if the parameter o is null.
  80      */
  81     public synchronized void addObserver(Observer o) {
  82         if (o == null)
  83             throw new NullPointerException();
  84         if (!obs.contains(o)) {
  85             obs.addElement(o);
  86         }
  87     }
  88 
  89     /**