1 6 7 package org.netbeans.mdr.test; 8 9 import java.util.HashMap ; 10 import java.util.Iterator ; 11 import java.util.LinkedList ; 12 import org.netbeans.api.mdr.events.MDRChangeEvent; 13 14 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 eventsMap = new HashMap (); 31 private LinkedList patternList = new LinkedList (); 32 33 34 public EventsList() { 35 } 36 37 public boolean checkPreEvents() { 38 return true; 39 } 40 41 public boolean checkEvents(String ptrn, int states) { 42 43 boolean changedFound = false; 44 boolean plannedFound = false; 45 boolean canceledFound = false; 46 Iterator iter = patternList.iterator(); 47 48 while (iter.hasNext()) { 50 51 PatternProps pp = (PatternProps) iter.next(); 52 54 Iterator eventsIter = eventsMap.values().iterator(); 55 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 plannedFound = true; 65 } 66 if (ptrn.equals(eprop.changedPattern) && (_CHANGED == (_CHANGED & states)) && 67 (pp.timeStamp <= eprop.changedTimestamp)) { 68 changedFound = true; 70 } 71 if (ptrn.equals(eprop.canceledPattern) && (_CANCELED == (_CANCELED & states)) && 72 (pp.timeStamp <= eprop.canceledTimestamp)) { 73 canceledFound = true; 75 } 76 } else { 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 ptrn, long ts) { 90 PatternProps pp = new PatternProps(ptrn, ts); 91 patternList.add(pp); 92 } 93 94 public void addPattern2(String ptrn, int states, long ts) { 95 96 98 PatternProps pp = new PatternProps(ptrn, ts, states); 99 patternList.add(pp); 100 } 101 102 public void addEvent(String pattern, MDRChangeEvent evnt, long ts, int stats) { 103 104 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 plannedPattern = ""; 130 public String canceledPattern = ""; 131 public String changedPattern = ""; 132 133 public long plannedTimestamp = 0L; 134 public long canceledTimestamp = 0L; 135 public long changedTimestamp = 0L; 136 137 public EventProps(String 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 ptr, long tsmp) { 152 changedPattern = ptr; 153 changedTimestamp = tsmp; 154 } 155 156 public void setPlanned(String ptr, long tsmp) { 157 plannedPattern = ptr; 158 plannedTimestamp = tsmp; 159 } 160 161 public void setCanceled(String ptr, long tsmp) { 162 canceledPattern = ptr; 163 canceledTimestamp = tsmp; 164 } 165 166 } 167 168 private class PatternProps { 169 170 public String pattern; 171 public long timeStamp; 172 public int states; 173 174 public PatternProps(String ptr, long ts) { 175 pattern = ptr; 176 timeStamp = ts; 177 states = 0; 178 } 179 180 public PatternProps(String ptr, long ts, int st) { 181 pattern = ptr; 182 timeStamp = ts; 183 states = st; 184 } 185 186 } 187 188 } 189 | Popular Tags |