1 package gov.nasa.jpf.search; 20 21 import gov.nasa.jpf.Property; 22 import gov.nasa.jpf.VM; 23 24 import java.io.PrintWriter ; 25 26 30 public class PropertyMulticaster implements Property { 31 Property head, tail; 32 boolean headFailed, tailFailed; 33 34 public static Property add (Property oldProperty, Property newProperty) { 35 if (newProperty == null) { 36 return oldProperty; 37 } 38 if (oldProperty == null) { 39 return newProperty; 40 } 41 42 return new PropertyMulticaster(oldProperty, newProperty); 45 } 46 47 public static Property remove (Property oldProperty, Property removeProperty){ 48 if (oldProperty == removeProperty) { 49 return null; 50 } 51 if (oldProperty instanceof PropertyMulticaster){ 52 return ((PropertyMulticaster)oldProperty).remove( removeProperty); 53 } 54 55 return oldProperty; 56 } 57 58 protected Property remove (Property p) { 59 if (p == head) { 60 return tail; 61 } 62 if (p == tail){ 63 return head; 64 } 65 66 if (head instanceof PropertyMulticaster) { 67 if (tail instanceof PropertyMulticaster){ 68 return new PropertyMulticaster( ((PropertyMulticaster)head).remove(p), 69 ((PropertyMulticaster)tail).remove(p)); 70 } else { 71 return new PropertyMulticaster( ((PropertyMulticaster)head).remove(p), tail); 72 } 73 } else if (tail instanceof PropertyMulticaster) { 74 return new PropertyMulticaster( head, ((PropertyMulticaster)tail).remove(p)); 75 } 76 77 return this; 78 } 79 80 public PropertyMulticaster (Property h, Property t) { 81 head = h; 82 tail = t; 83 } 84 85 public boolean check (VM vm, Object arg) { 86 if (!head.check(vm,arg)){ 87 headFailed = true; 88 return false; 89 } 90 if (!tail.check(vm,arg)){ 91 tailFailed = true; 92 return false; 93 } 94 95 return true; 96 } 97 98 public String getErrorMessage () { 99 if (headFailed) { 100 return head.getErrorMessage(); 101 } else if (tailFailed){ 102 return tail.getErrorMessage(); 103 } 104 105 return null; 106 } 107 108 public void printOn (PrintWriter pw) { 109 if (headFailed){ 110 head.printOn(pw); 111 } else if (tailFailed) { 112 tail.printOn(pw); 113 } 114 } 115 } 116 | Popular Tags |