1 8 9 package net.sourceforge.chaperon.model.extended; 10 11 import net.sourceforge.chaperon.model.Violations; 12 13 17 public class Optional extends PatternList 18 { 19 public Optional() {} 20 21 public boolean isNullable() 22 { 23 return true; 24 } 25 26 31 public String toString() 32 { 33 StringBuffer buffer = new StringBuffer (); 34 35 if (getPatternCount()>0) 36 { 37 buffer.append(super.toString()); 38 buffer.append("?"); 39 } 40 41 return buffer.toString(); 42 } 43 44 public String toString(PatternSet previous, PatternSet next) 45 { 46 StringBuffer buffer = new StringBuffer (); 47 48 if (getPatternCount()>0) 49 { 50 buffer.append(super.toString(previous, next)); 51 buffer.append("?"); 52 } 53 54 return buffer.toString(); 55 } 56 57 64 public Object clone() throws CloneNotSupportedException 65 { 66 Optional clone = new Optional(); 67 68 for (int i = 0; i<getPatternCount(); i++) 69 clone.addPattern((Pattern)getPattern(i).clone()); 70 71 return clone; 72 } 73 74 79 public Violations validate() 80 { 81 Violations violations = new Violations(); 82 83 86 for (int i = 0; i<getPatternCount(); i++) 87 violations.addViolations(getPattern(i).validate()); 88 89 return violations; 90 } 91 } 92 | Popular Tags |