1 8 9 package net.sourceforge.chaperon.model.pattern; 10 11 import net.sourceforge.chaperon.model.Violations; 12 13 19 public class Concatenation extends PatternList 20 { 21 24 public Concatenation() {} 25 26 31 public String toString() 32 { 33 StringBuffer buffer = new StringBuffer (); 34 35 for (int i = 0; i<getPatternCount(); i++) 36 buffer.append(getPattern(i).toString()); 37 38 if ((getMinOccurs()==1) && (getMaxOccurs()==1)) 39 { 40 } 42 else if ((getMinOccurs()==0) && (getMaxOccurs()==1)) 43 buffer.append("?"); 44 else if ((getMinOccurs()==0) && (getMaxOccurs()==Integer.MAX_VALUE)) 45 buffer.append("*"); 46 else if ((getMinOccurs()==1) && (getMaxOccurs()==Integer.MAX_VALUE)) 47 buffer.append("+"); 48 else 49 { 50 buffer.append("{"); 51 buffer.append(String.valueOf(getMinOccurs())); 52 buffer.append(","); 53 buffer.append(String.valueOf(getMaxOccurs())); 54 buffer.append("}"); 55 } 56 57 return buffer.toString(); 58 } 59 60 67 public Object clone() throws CloneNotSupportedException 68 { 69 Concatenation clone = new Concatenation(); 70 71 clone.setMinOccurs(getMinOccurs()); 72 clone.setMaxOccurs(getMaxOccurs()); 73 74 for (int i = 0; i<getPatternCount(); i++) 75 clone.addPattern((Pattern)getPattern(i).clone()); 76 77 return clone; 78 } 79 80 85 public Violations validate() 86 { 87 Violations violations = new Violations(); 88 89 if (getPatternCount()==0) 90 violations.addViolation("Concatenation doesn't contain any elements", getLocation()); 91 92 for (int i = 0; i<getPatternCount(); i++) 93 violations.addViolations(getPattern(i).validate()); 94 95 return violations; 96 } 97 } 98 | Popular Tags |