1 8 9 package net.sourceforge.chaperon.model.pattern; 10 11 import net.sourceforge.chaperon.model.Violations; 12 13 20 public class PatternGroup extends PatternList 21 { 22 25 public PatternGroup() {} 26 27 32 public String toString() 33 { 34 StringBuffer buffer = new StringBuffer (); 35 36 buffer.append("("); 37 38 for (int i = 0; i<getPatternCount(); i++) 39 buffer.append(getPattern(i).toString()); 40 41 buffer.append(")"); 42 43 if ((getMinOccurs()==1) && (getMaxOccurs()==1)) 44 { 45 } 47 else if ((getMinOccurs()==0) && (getMaxOccurs()==1)) 48 buffer.append("?"); 49 else if ((getMinOccurs()==0) && (getMaxOccurs()==Integer.MAX_VALUE)) 50 buffer.append("*"); 51 else if ((getMinOccurs()==1) && (getMaxOccurs()==Integer.MAX_VALUE)) 52 buffer.append("+"); 53 else 54 { 55 buffer.append("{"); 56 buffer.append(String.valueOf(getMinOccurs())); 57 buffer.append(","); 58 buffer.append(String.valueOf(getMaxOccurs())); 59 buffer.append("}"); 60 } 61 62 return buffer.toString(); 63 } 64 65 72 public Object clone() throws CloneNotSupportedException 73 { 74 PatternGroup clone = new PatternGroup(); 75 76 clone.setMinOccurs(getMinOccurs()); 77 clone.setMaxOccurs(getMaxOccurs()); 78 79 for (int i = 0; i<getPatternCount(); i++) 80 clone.addPattern((Pattern)getPattern(i).clone()); 81 82 return clone; 83 } 84 85 90 public Violations validate() 91 { 92 Violations violations = new Violations(); 93 94 if (getPatternCount()<1) 95 violations.addViolation("Pattern group doesn't contain elements", getLocation()); 96 97 for (int i = 0; i<getPatternCount(); i++) 98 violations.addViolations(getPattern(i).validate()); 99 100 return violations; 101 } 102 } 103 | Popular Tags |