1 8 9 package net.sourceforge.chaperon.model.extended; 10 11 import net.sourceforge.chaperon.model.Violations; 12 13 import java.io.Serializable ; 14 15 21 public abstract class Pattern implements Serializable , Cloneable 22 { 23 private String location = null; 24 private static int internalPatternCount = 0; 25 public final int index = internalPatternCount++; 26 private Definition definition = null; 27 private PatternSet ancestors = new PatternSet(); 28 private PatternSet successors = new PatternSet(); 29 private PatternSet ascendingAncestors = new PatternSet(); 30 private PatternSet ascendingSuccessors = new PatternSet(); 31 private PatternSet descendingAncestors = new PatternSet(); 32 private PatternSet descendingSuccessors = new PatternSet(); 33 34 public abstract boolean isNullable(); 35 36 public abstract PatternSet getFirstSet(); 37 38 public abstract PatternSet getLastSet(); 39 40 public abstract boolean contains(char c); 41 42 public abstract char[] getLimits(); 43 44 public abstract boolean contains(char minimum, char maximum); 45 46 public abstract String getSymbol(); 47 48 public PatternSet getAllPattern() 49 { 50 PatternSet set = new PatternSet(); 51 set.addPattern(this); 52 return set; 53 } 54 55 public void setDefinition(Definition definition) 56 { 57 this.definition = definition; 58 } 59 60 public Definition getDefinition() 61 { 62 return definition; 63 } 64 65 public PatternIterator getAncestors() 66 { 67 return ancestors.getPattern(); 68 } 69 70 public boolean hasAncestor(Pattern pattern) 71 { 72 for (PatternIterator ancestor = ancestors.getPattern(); ancestor.hasNext();) 73 if (ancestor.next()==pattern) 74 return true; 75 76 return false; 77 } 78 79 public boolean addSuccessor(Pattern pattern) 80 { 81 return successors.addPattern(pattern)|pattern.ancestors.addPattern(this); 82 } 83 84 public PatternIterator getSuccessors() 85 { 86 return successors.getPattern(); 87 } 88 89 public boolean hasSuccessor(Pattern pattern) 90 { 91 for (PatternIterator successor = successors.getPattern(); successor.hasNext();) 92 if (successor.next()==pattern) 93 return true; 94 95 return false; 96 } 97 98 public PatternIterator getAscendingAncestors() 99 { 100 return ascendingAncestors.getPattern(); 101 } 102 103 public boolean hasAscendingAncestor(Pattern pattern) 104 { 105 for (PatternIterator ancestor = ascendingAncestors.getPattern(); ancestor.hasNext();) 106 if (ancestor.next()==pattern) 107 return true; 108 109 return false; 110 } 111 112 public boolean addAscendingSuccessor(Pattern pattern) 113 { 114 return ascendingSuccessors.addPattern(pattern)|pattern.ascendingAncestors.addPattern(this); 115 } 116 117 public PatternIterator getAscendingSuccessors() 118 { 119 return ascendingSuccessors.getPattern(); 120 } 121 122 public boolean hasAscendingSuccessor(Pattern pattern) 123 { 124 for (PatternIterator successor = ascendingSuccessors.getPattern(); successor.hasNext();) 125 if (successor.next()==pattern) 126 return true; 127 128 return false; 129 } 130 131 public PatternIterator getDescendingAncestors() 132 { 133 return descendingAncestors.getPattern(); 134 } 135 136 public boolean hasDescendingAncestor(Pattern pattern) 137 { 138 for (PatternIterator ancestor = descendingAncestors.getPattern(); ancestor.hasNext();) 139 if (ancestor.next()==pattern) 140 return true; 141 142 return false; 143 } 144 145 public boolean addDescendingSuccessor(Pattern pattern) 146 { 147 return descendingSuccessors.addPattern(pattern)|pattern.descendingAncestors.addPattern(this); 148 } 149 150 public PatternIterator getDescendingSuccessors() 151 { 152 return descendingSuccessors.getPattern(); 153 } 154 155 public boolean hasDescendingSuccessor(Pattern pattern) 156 { 157 for (PatternIterator successor = descendingSuccessors.getPattern(); successor.hasNext();) 158 if (successor.next()==pattern) 159 return true; 160 161 return false; 162 } 163 164 public void update() 165 { 166 ancestors.clear(); 167 successors.clear(); 168 ascendingAncestors.clear(); 169 ascendingSuccessors.clear(); 170 descendingAncestors.clear(); 171 descendingSuccessors.clear(); 172 } 173 174 181 public abstract Object clone() throws CloneNotSupportedException ; 182 183 188 public void setLocation(String location) 189 { 190 this.location = location; 191 } 192 193 198 public String getLocation() 199 { 200 return location; 201 } 202 203 208 public abstract Violations validate(); 209 210 public String toString(PatternSet previous, PatternSet next) 211 { 212 if ((previous!=null) && (previous.contains(this))) 213 { 214 if ((next!=null) && (next.contains(this))) 215 return "."+toString()+"."; 216 else 217 return toString()+"."; 218 } 219 else if ((next!=null) && (next.contains(this))) 220 return "."+toString(); 221 222 return toString(); 223 } 224 } 225 | Popular Tags |