Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

Subject.java

00001 class Subject 
00002 {
00003      protected boolean changed;
00004      protected Vector obs;
00005      
00006      public Subject()
00007      {
00008           this.changed = false;
00009           this.obs = new Vector();
00010      }
00011      
00012      public synchronized void addObserver (Watcher o)
00013      {
00014           if (!this.obs.contains(o))
00015           {
00016                this.obs.addElement(o);
00017           }
00018      }
00019      
00020      public synchronized void deleteObserver (Watcher o)
00021      {
00022           this.obs.removeElement(o);
00023      }
00024      
00025      public void changeState ()
00026      {
00027           this.setChanged();
00028           this.notifyObservers();
00029      }
00030      
00031      protected synchronized void setChanged ()
00032      {
00033           this.changed = true;
00034      }
00035      
00036      public void notifyObservers ()
00037      {
00038           this.notifyObservers(null);
00039      }
00040      
00041      protected synchronized void clearChanged ()
00042      {
00043           this.changed = false;
00044      }
00045      
00046      public synchronized int countObservers ()
00047      {
00048           return this.obs.size();
00049      }
00050      
00051      public synchronized void deleteObservers ()
00052      {
00053           this.obs.removeAllElements();
00054      }
00055      
00056      public synchronized boolean hasChanged ()
00057      {
00058           return this.changed;
00059      }
00060      
00061      public void notifyObservers (java.lang.Object arg)
00062      {
00063           java.lang.Object[] arrLocal;
00064           synchronized (this)
00065           {
00066                if (!this.changed)
00067                {
00068                     return;
00069                }
00070                arrLocal = this.obs.toArray();
00071                this.changed = false;
00072           }
00073           if (this.obs.size() != arrLocal.length)
00074           {
00075           }
00076           for (int i = (arrLocal.length - 1); i >= 0; i = (i - 1))
00077           {
00078                ((Watcher) arrLocal[i]).update(this,arg);
00079           }
00080      }
00081 }

Generated at Thu Feb 7 06:55:58 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001