KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > mdr > test > EventsList


1 /*
2  * EventsList.java
3  *
4  * Created on August 2, 2002, 4:33 PM
5  */

6
7 package org.netbeans.mdr.test;
8
9 import java.util.HashMap JavaDoc;
10 import java.util.Iterator JavaDoc;
11 import java.util.LinkedList JavaDoc;
12 import org.netbeans.api.mdr.events.MDRChangeEvent;
13
14 /**
15  *
16  * @author mk97936
17  */

18 public class EventsList {
19     
20     public static final int _PLANNED = 128;
21     public static final int _CHANGED = 256;
22     public static final int _CANCELED = 512;
23     
24     public static final int _CREATE = 1024;
25     public static final int _DELETE = 2048;
26     public static final int _SET = 4096;
27     public static final int _ADD = 8192;
28     public static final int _REMOVE = 16384;
29     
30     private HashMap JavaDoc eventsMap = new HashMap JavaDoc();
31     private LinkedList JavaDoc patternList = new LinkedList JavaDoc();
32     
33     /** Creates a new instance of EventsList */
34     public EventsList() {
35     }
36     
37     public boolean checkPreEvents() {
38         return true;
39     }
40     
41     public boolean checkEvents(String JavaDoc ptrn, int states) {
42         
43         boolean changedFound = false;
44         boolean plannedFound = false;
45         boolean canceledFound = false;
46         Iterator JavaDoc iter = patternList.iterator();
47         
48         //System.out.println("---> Searched pattern: " + ptrn);
49
while (iter.hasNext()) {
50             
51             PatternProps pp = (PatternProps) iter.next();
52             //System.out.println("------> Saved pattern: " + pp.pattern + ", " + pp.timeStamp);
53

54             Iterator JavaDoc eventsIter = eventsMap.values().iterator();
55             //System.out.println("---------> Number of saved events: " + eventsMap.size());
56
while (eventsIter.hasNext()) {
57                 
58                 EventProps eprop = (EventProps) eventsIter.next();
59                
60                 if (ptrn != null) {
61                     if (ptrn.equals(eprop.plannedPattern) && (_PLANNED == (_PLANNED & states)) &&
62                         (pp.timeStamp <= eprop.plannedTimestamp)) {
63                         //System.out.println("------------> Planned event: " + eprop.plannedPattern + ", " + eprop.plannedTimestamp);
64
plannedFound = true;
65                     }
66                     if (ptrn.equals(eprop.changedPattern) && (_CHANGED == (_CHANGED & states)) &&
67                         (pp.timeStamp <= eprop.changedTimestamp)) {
68                         //System.out.println("------------> Changed event: " + eprop.changedPattern + ", " + eprop.changedTimestamp);
69
changedFound = true;
70                     }
71                     if (ptrn.equals(eprop.canceledPattern) && (_CANCELED == (_CANCELED & states)) &&
72                         (pp.timeStamp <= eprop.canceledTimestamp)) {
73                         //System.out.println("------------> Canceled event: " + eprop.canceledPattern + ", " + eprop.canceledTimestamp);
74
canceledFound = true;
75                     }
76                 } else { // ptrn == null => delete event
77

78                 }
79             }
80         }
81         
82         if (changedFound && (_CHANGED == (_CHANGED & states))) return true;
83             else if (plannedFound && (_PLANNED == (_PLANNED & states))) return true;
84             else if (plannedFound && (_CANCELED == (_CANCELED & states))) return true;
85             else return false;
86         
87     }
88     
89     public void addPattern(String JavaDoc ptrn, long ts) {
90         PatternProps pp = new PatternProps(ptrn, ts);
91         patternList.add(pp);
92     }
93     
94     public void addPattern2(String JavaDoc ptrn, int states, long ts) {
95         
96         //System.out.println("adding pattern: " + ptrn + "; " + states + "; " + ts);
97

98         PatternProps pp = new PatternProps(ptrn, ts, states);
99         patternList.add(pp);
100     }
101     
102     public void addEvent(String JavaDoc pattern, MDRChangeEvent evnt, long ts, int stats) {
103         
104         //System.out.println("adding event: " + pattern + "; " + evnt + "; " + ts + "; " + stats );
105

106         if (!eventsMap.containsKey(evnt)) {
107             EventProps ep = new EventProps(pattern, ts, stats);
108             eventsMap.put(evnt, ep);
109         } else {
110             EventProps ep = (EventProps) eventsMap.get(evnt);
111             if (_PLANNED == (stats & _PLANNED)) {
112                 ep.setPlanned(pattern, ts);
113             } else if (_CHANGED == (stats & _CHANGED)) {
114                 ep.setChanged(pattern, ts);
115             } else if (_CANCELED == (stats & _CANCELED)) {
116                 ep.setCanceled(pattern, ts);
117             }
118         }
119         
120     }
121     
122     public void clear() {
123         eventsMap.clear();
124         patternList.clear();
125     }
126     
127     private class EventProps {
128         
129         public String JavaDoc plannedPattern = "";
130         public String JavaDoc canceledPattern = "";
131         public String JavaDoc changedPattern = "";
132         
133         public long plannedTimestamp = 0L;
134         public long canceledTimestamp = 0L;
135         public long changedTimestamp = 0L;
136         
137         public EventProps(String JavaDoc ptr, long tsmp, int stats) {
138             
139             if (_CHANGED == (stats & _CHANGED)) {
140                 changedPattern = ptr;
141                 changedTimestamp = tsmp;
142             } else if (_PLANNED == (stats & _PLANNED)) {
143                 plannedPattern = ptr;
144                 plannedTimestamp = tsmp;
145             } else if (_CANCELED == (stats & _CANCELED)) {
146                 canceledPattern = ptr;
147                 canceledTimestamp = tsmp;
148             }
149         }
150         
151         public void setChanged(String JavaDoc ptr, long tsmp) {
152             changedPattern = ptr;
153             changedTimestamp = tsmp;
154         }
155         
156         public void setPlanned(String JavaDoc ptr, long tsmp) {
157             plannedPattern = ptr;
158             plannedTimestamp = tsmp;
159         }
160         
161         public void setCanceled(String JavaDoc ptr, long tsmp) {
162             canceledPattern = ptr;
163             canceledTimestamp = tsmp;
164         }
165         
166     }
167     
168     private class PatternProps {
169         
170         public String JavaDoc pattern;
171         public long timeStamp;
172         public int states;
173         
174         public PatternProps(String JavaDoc ptr, long ts) {
175             pattern = ptr;
176             timeStamp = ts;
177             states = 0;
178         }
179         
180         public PatternProps(String JavaDoc ptr, long ts, int st) {
181             pattern = ptr;
182             timeStamp = ts;
183             states = st;
184         }
185         
186     }
187     
188 }
189
Popular Tags