1 package gov.nasa.jpf; 20 21 25 public class SearchListenerMulticaster implements SearchListener { 26 27 SearchListener head; 28 SearchListener tail; 29 30 public static SearchListener add (SearchListener oldListener, SearchListener newListener) { 31 if (newListener == null) { 32 return oldListener; 33 } 34 if (oldListener == null) { 35 return newListener; 36 } 37 38 return new SearchListenerMulticaster(oldListener, newListener); 41 } 42 43 public static SearchListener remove (SearchListener oldListener, SearchListener removeListener){ 44 if (oldListener == removeListener) { 45 return null; 46 } 47 if (oldListener instanceof SearchListenerMulticaster){ 48 return ((SearchListenerMulticaster)oldListener).remove( removeListener); 49 } 50 51 return oldListener; 52 } 53 54 protected SearchListener remove (SearchListener listener) { 55 if (listener == head) { 56 return tail; 57 } 58 if (listener == tail){ 59 return head; 60 } 61 62 SearchListenerMulticaster h,t; 63 if (head instanceof SearchListenerMulticaster) { 64 h = (SearchListenerMulticaster)head; 65 if (tail instanceof SearchListenerMulticaster){ 66 t = (SearchListenerMulticaster)tail; 67 return new SearchListenerMulticaster( h.remove(listener),t.remove(listener)); 68 } else { 69 return new SearchListenerMulticaster( h.remove(listener), tail); 70 } 71 } else if (tail instanceof SearchListenerMulticaster) { 72 t = (SearchListenerMulticaster)tail; 73 return new SearchListenerMulticaster( head, t.remove(listener)); 74 } 75 76 return this; 77 } 78 79 80 public SearchListenerMulticaster (SearchListener h, SearchListener t) { 81 head = h; 82 tail = t; 83 } 84 85 public void stateAdvanced (Search search) { 86 head.stateAdvanced(search); 87 tail.stateAdvanced(search); 88 } 89 90 public void stateProcessed (Search search) { 91 head.stateProcessed(search); 92 tail.stateProcessed(search); 93 } 94 95 public void stateBacktracked (Search search) { 96 head.stateBacktracked(search); 97 tail.stateBacktracked(search); 98 } 99 100 public void stateRestored (Search search) { 101 head.stateRestored(search); 102 tail.stateRestored(search); 103 } 104 105 public void propertyViolated (Search search) { 106 head.propertyViolated(search); 107 tail.propertyViolated(search); 108 } 109 110 public void searchStarted(Search search) { 111 head.searchStarted(search); 112 tail.searchStarted(search); 113 } 114 115 public void searchFinished(Search search) { 116 head.searchFinished(search); 117 tail.searchFinished(search); 118 } 119 120 public void searchConstraintHit(Search search) { 121 head.searchConstraintHit(search); 122 tail.searchConstraintHit(search); 123 } 124 125 } 126 | Popular Tags |