home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / COMMON / TOOLS / VB / CABINETS / MSDAO350.CAB / icontrols / DelegateMulticaster.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-01-08  |  2.0 KB  |  98 lines

  1. package icontrols;
  2.  
  3. import com.ms.wd.core.Closure;
  4.  
  5. public class DelegateMulticaster {
  6.    private static final int BOF = -1;
  7.    private static final int EOF = -2;
  8.    private static final int FIRST = 0;
  9.    private Closure[] m_delegates = null;
  10.    private int m_current = -1;
  11.  
  12.    public void addDelegate(Closure newDelegate) {
  13.       if (this.m_delegates == null) {
  14.          this.m_delegates = new Closure[]{newDelegate};
  15.       } else {
  16.          boolean added = false;
  17.          int length = this.m_delegates.length;
  18.  
  19.          for(int i = 0; i < length; ++i) {
  20.             if (this.m_delegates[i] == null) {
  21.                this.m_delegates[i] = newDelegate;
  22.                added = true;
  23.             }
  24.          }
  25.  
  26.          if (!added) {
  27.             Closure[] temp = new Closure[length + 5];
  28.             System.arraycopy(this.m_delegates, 0, temp, 0, length);
  29.             temp[length] = newDelegate;
  30.             this.m_delegates = temp;
  31.          }
  32.       }
  33.  
  34.    }
  35.  
  36.    public void reset() {
  37.       this.m_current = -1;
  38.       this.moveFirst();
  39.    }
  40.  
  41.    private void moveNext() {
  42.       if (this.m_current >= 0) {
  43.          for(int i = this.m_current + 1; i < this.m_delegates.length; ++i) {
  44.             if (this.m_delegates[i] != null) {
  45.                this.m_current = i;
  46.                return;
  47.             }
  48.          }
  49.  
  50.          this.m_current = -2;
  51.       }
  52.    }
  53.  
  54.    private void moveFirst() {
  55.       if (this.m_current != -2) {
  56.          for(int i = 0; i < this.m_delegates.length; ++i) {
  57.             if (this.m_delegates[i] != null) {
  58.                this.m_current = i;
  59.                return;
  60.             }
  61.          }
  62.  
  63.          this.m_current = -2;
  64.       }
  65.    }
  66.  
  67.    public void removeDelegate(Closure removeDelegate) {
  68.       if (this.m_delegates != null) {
  69.          int length = this.m_delegates.length;
  70.  
  71.          for(int i = 0; i < length; ++i) {
  72.             if (this.m_delegates[i].equals(removeDelegate)) {
  73.                this.m_delegates[i] = null;
  74.             }
  75.          }
  76.  
  77.       }
  78.    }
  79.  
  80.    public boolean isComplete() {
  81.       if (this.m_current == -1 && this.m_delegates != null) {
  82.          this.moveFirst();
  83.       }
  84.  
  85.       return this.m_current == -2;
  86.    }
  87.  
  88.    public Object invokeNext(Object[] args) {
  89.       Object ret = null;
  90.       if (this.m_current >= 0) {
  91.          ret = this.m_delegates[this.m_current].invokeMethod(args);
  92.       }
  93.  
  94.       this.moveNext();
  95.       return ret;
  96.    }
  97. }
  98.