1 8 9 package net.sourceforge.chaperon.model.extended; 10 11 import net.sourceforge.chaperon.model.Violations; 12 13 19 public class Definition extends PatternList 20 { 21 private String symbol = null; 22 private String location = null; 23 24 27 public Definition() {} 28 29 34 public Definition(String symbol) 35 { 36 setSymbol(symbol); 37 } 38 39 44 public void setSymbol(String symbol) 45 { 46 if (symbol==null) 47 throw new NullPointerException (); 48 49 this.symbol = symbol; 50 } 51 52 57 public String getSymbol() 58 { 59 return symbol; 60 } 61 62 67 public void setLocation(String location) 68 { 69 this.location = location; 70 } 71 72 77 public String getLocation() 78 { 79 return location; 80 } 81 82 87 public Violations validate() 88 { 89 Violations violations = new Violations(); 90 91 if (symbol==null) 92 violations.addViolation("No symbol is for the left side defined", location); 93 94 if (getPatternCount()==0) 95 violations.addViolation("No pattern are for the right side defined", location); 96 97 for (int i = 0; i<getPatternCount(); i++) 98 violations.addViolations(getPattern(i).validate()); 99 100 return violations; 101 } 102 103 110 public boolean equals(Object o) 111 { 112 if (o==this) 113 return true; 114 115 if (o instanceof Definition) 116 { 117 Definition definition = (Definition)o; 118 119 return (symbol.equals(definition.symbol)) && (super.equals(o)); 120 } 121 122 return false; 123 } 124 125 130 public String toString(PatternSet previous, PatternSet next) 131 { 132 StringBuffer buffer = new StringBuffer (); 133 134 buffer.append(symbol); 135 buffer.append(" := "); 136 buffer.append(super.toString(previous, next)); 137 138 return buffer.toString(); 139 } 140 141 146 public Object clone() throws CloneNotSupportedException 147 { 148 Definition clone = new Definition(); 149 150 clone.symbol = symbol; 151 152 for (int i = 0; i<getPatternCount(); i++) 153 clone.addPattern((Pattern)getPattern(i).clone()); 154 155 clone.location = location; 156 157 return clone; 158 } 159 } 160 | Popular Tags |