1 8 9 package net.sourceforge.chaperon.model.extended; 10 11 import net.sourceforge.chaperon.model.Violations; 12 13 17 public class ZeroOrMore extends PatternList 18 { 19 public ZeroOrMore() {} 20 21 public boolean isNullable() 22 { 23 return true; 24 } 25 26 public void update() 27 { 28 super.update(); 29 30 PatternSet firstSet = getFirstSet(); 31 for (PatternIterator i = getLastSet().getPattern(); i.hasNext();) 32 { 33 Pattern lastPattern = i.next(); 34 for (PatternIterator j = firstSet.getPattern(); j.hasNext();) 35 { 36 Pattern firstPattern = j.next(); 37 lastPattern.addSuccessor(firstPattern); 38 } 39 } 40 } 41 42 47 public String toString() 48 { 49 StringBuffer buffer = new StringBuffer (); 50 51 if (getPatternCount()>0) 52 { 53 buffer.append(super.toString()); 54 buffer.append("*"); 55 } 56 57 return buffer.toString(); 58 } 59 60 public String toString(PatternSet previous, PatternSet next) 61 { 62 StringBuffer buffer = new StringBuffer (); 63 64 if (getPatternCount()>0) 65 { 66 buffer.append(super.toString(previous, next)); 67 buffer.append("*"); 68 } 69 70 return buffer.toString(); 71 } 72 73 80 public Object clone() throws CloneNotSupportedException 81 { 82 ZeroOrMore clone = new ZeroOrMore(); 83 84 for (int i = 0; i<getPatternCount(); i++) 85 clone.addPattern((Pattern)getPattern(i).clone()); 86 87 return clone; 88 } 89 90 95 public Violations validate() 96 { 97 Violations violations = new Violations(); 98 99 102 for (int i = 0; i<getPatternCount(); i++) 103 violations.addViolations(getPattern(i).validate()); 104 105 return violations; 106 } 107 } 108 | Popular Tags |