home *** CD-ROM | disk | FTP | other *** search
- package icontrols;
-
- import com.ms.wd.core.Closure;
-
- public class DelegateMulticaster {
- private static final int BOF = -1;
- private static final int EOF = -2;
- private static final int FIRST = 0;
- private Closure[] m_delegates = null;
- private int m_current = -1;
-
- public void addDelegate(Closure newDelegate) {
- if (this.m_delegates == null) {
- this.m_delegates = new Closure[]{newDelegate};
- } else {
- boolean added = false;
- int length = this.m_delegates.length;
-
- for(int i = 0; i < length; ++i) {
- if (this.m_delegates[i] == null) {
- this.m_delegates[i] = newDelegate;
- added = true;
- }
- }
-
- if (!added) {
- Closure[] temp = new Closure[length + 5];
- System.arraycopy(this.m_delegates, 0, temp, 0, length);
- temp[length] = newDelegate;
- this.m_delegates = temp;
- }
- }
-
- }
-
- public void reset() {
- this.m_current = -1;
- this.moveFirst();
- }
-
- private void moveNext() {
- if (this.m_current >= 0) {
- for(int i = this.m_current + 1; i < this.m_delegates.length; ++i) {
- if (this.m_delegates[i] != null) {
- this.m_current = i;
- return;
- }
- }
-
- this.m_current = -2;
- }
- }
-
- private void moveFirst() {
- if (this.m_current != -2) {
- for(int i = 0; i < this.m_delegates.length; ++i) {
- if (this.m_delegates[i] != null) {
- this.m_current = i;
- return;
- }
- }
-
- this.m_current = -2;
- }
- }
-
- public void removeDelegate(Closure removeDelegate) {
- if (this.m_delegates != null) {
- int length = this.m_delegates.length;
-
- for(int i = 0; i < length; ++i) {
- if (this.m_delegates[i].equals(removeDelegate)) {
- this.m_delegates[i] = null;
- }
- }
-
- }
- }
-
- public boolean isComplete() {
- if (this.m_current == -1 && this.m_delegates != null) {
- this.moveFirst();
- }
-
- return this.m_current == -2;
- }
-
- public Object invokeNext(Object[] args) {
- Object ret = null;
- if (this.m_current >= 0) {
- ret = this.m_delegates[this.m_current].invokeMethod(args);
- }
-
- this.moveNext();
- return ret;
- }
- }
-