Skip to content

Package: VariableAssignment$1

VariableAssignment$1

nameinstructionbranchcomplexitylinemethod
visit(AnonVariableType)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
visit(NamedVariableType)
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
{...}
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: package model.assignment;
2:
3: import java.awt.Component;
4:
5: import model.Position;
6: import model.type.AbstractVariableTypeVisitor;
7: import model.type.AnonVariableType;
8: import model.type.NamedVariableType;
9: import model.type.ReferenceIsUnresolvedException;
10: import model.type.TypeDoesNotExistException;
11: import model.type.TypeExceptions;
12: import model.type.ValueNotInRangeOfTypeException;
13: import networkconfigurator.CompareVaNameVisitor;
14: import networkconfigurator.DetailBarVisitor;
15: import networkconfigurator.DetailDrawVisitor;
16: import networkconfigurator.PropertyBarEntry;
17: import networkconfigurator.PropertyDrawEntry;
18: import networkconfigurator.actions.ItemGetNameVisitor;
19: import networkconfigurator.actions.ItemSetNameVisitor;
20:
21: /**
22: * VariableAssignment represents an entry in the "\config\<package>.txt" files.
23: *
24: * @author HFW410RA - Philipp Rammos
25: *
26: */
27: public class VariableAssignment extends java.util.Observable
28:                 implements PropertyBarEntry, PropertyDrawEntry {
29:         /**
30:          * Represents value of the variable.
31:          */
32:         private String value;
33:         /**
34:          * Represents the type of the variable.
35:          */
36:         private final model.definition.AbstractVariableDefinition definition;
37:         /**
38:          * Represents the name of the variable. name.equals(definition.getName())=true, if it is an
39:          * SingleVariable.
40:          */
41:         private final String nameOfAssignment;
42:
43:         /**
44:          * Position where the entry is written.
45:          */
46:         private final Position position;
47:
48:         /**
49:          * Constructor, just sets the fields.
50:          *
51:          * @param definition
52:          * VariableDefinition to set (field)
53:          * @param value
54:          * Value to set (field)
55:          * @param nameOfAssignment
56:          * The name to set.
57:          * @param position
58:          * The position to set.
59:          */
60:         public VariableAssignment(final String nameOfAssignment,
61:                         final model.definition.AbstractVariableDefinition definition, final String value,
62:                         final Position position) {
63:                 this.nameOfAssignment = nameOfAssignment;
64:                 this.definition = definition;
65:                 this.value = value;
66:                 this.position = position;
67:         }
68:
69:         @Override
70:         public boolean equals(final Object obj) {
71:                 return obj instanceof VariableAssignment
72:                                 && ((VariableAssignment) obj).getNameOfAssignment()
73:                                                 .equals(this.getNameOfAssignment())
74:                                 && ((VariableAssignment) obj).getDefinition().equals(this.getDefinition())
75:                                 && ((VariableAssignment) obj).getValue().equals(this.getValue())
76:                                 && ((VariableAssignment) obj).getPosition().equals(this.getPosition());
77:         }
78:
79:         @Override
80:         public int hashCode() {
81:                 return this.getNameOfAssignment().hashCode() + this.getDefinition().hashCode()
82:                                 + this.getValue().hashCode() + this.getPosition().hashCode();
83:         }
84:
85:         /**
86:          * Try to set a new value to the variable (field). If the value is not in range of the given
87:          * type of the variable, a ValueNotInRangeOfTypeException is thrown. checkValue(String name) is
88:          * called.
89:          *
90:          * @param value
91:          * The value to set.
92:          * @throws ValueNotInRangeOfTypeException
93:          * The value is not in the range of the given type.
94:          * @throws IllegalArgumentException
95:          * see java.lang.IllegalArgumentException.
96:          * @throws TypeExceptions
97:          * The TypeExceptions.
98:          * @throws TypeDoesNotExistException
99:          * The TypeDoesNotExistException.
100:          * @throws CycleInHierarchyDetectedException
101:          * The CycleInHierarchyDetectedException.
102:          */
103:         public void setValue(final String value) throws ValueNotInRangeOfTypeException,
104:                         IllegalArgumentException, TypeDoesNotExistException, TypeExceptions {
105:                 if (!this.checkValue(value)) {
106:                         throw new ValueNotInRangeOfTypeException(
107:                                         this.getDefinition().getType().getErrorMessage());
108:                 }
109:                 this.value = value;
110:                 this.setChanged();
111:                 this.notifyObservers();
112:                 this.getDefinition().getType().accept(new AbstractVariableTypeVisitor() {
113:
114:                         @Override
115:                         public void visit(final NamedVariableType namedVariableType)
116:                                         throws IllegalArgumentException, ReferenceIsUnresolvedException {
117:                                 namedVariableType.checkTypeExtensionConditions();
118:                         }
119:
120:                         @Override
121:                         public void visit(final AnonVariableType anonVariable) {
122:                                 // Do nothing
123:
124:                         }
125:                 });
126:         }
127:
128:         /**
129:          * Returns the field row. No side effects.
130:          *
131:          * @return this.row
132:          */
133:         public Position getPosition() {
134:                 return this.position;
135:         }
136:
137:         /**
138:          * Returns the field value. No side effects.
139:          *
140:          * @return this.value
141:          */
142:         public String getValue() {
143:                 return this.value;
144:         }
145:
146:         /**
147:          * Returns the field definition. No side effects.
148:          *
149:          * @return this.definition
150:          */
151:         public model.definition.AbstractVariableDefinition getDefinition() {
152:                 return this.definition;
153:         }
154:
155:         /**
156:          * Checks if an value is the range of a type regex.
157:          *
158:          * @param valueToCheck
159:          * the value to check if it matches the regular expression
160:          * @return Returns true if and only if the value matches the regular expression
161:          * @throws IllegalArgumentException
162:          * @throws ReferenceIsUnresolvedException
163:          * is thrown if a part of the RegEx is unresolved
164:          * @throws IllegalArgumentException
165:          * see java.lang.IllegalArgumentException
166:          * @throws CycleInHierarchyDetectedException
167:          */
168:         public boolean checkValue(final String valueToCheck)
169:                         throws IllegalArgumentException, ReferenceIsUnresolvedException {
170:                 return this.definition.getType().matches(valueToCheck);
171:                 // final RegExp completeRegEx = new RegExp(this.definition.getType().toStringResolved());
172:                 // final Automaton automatonRegEx = completeRegEx.toAutomaton();
173:                 // return automatonRegEx.run(valueToCheck);
174:         }
175:
176:         /**
177:          * Returns the field name. No side effects.
178:          *
179:          * @return this.name
180:          */
181:         public String getNameOfAssignment() {
182:                 return this.nameOfAssignment;
183:         }
184:
185:         /**
186:          * Returns the line to print.
187:          *
188:          * @return Returns a string value, representing a line to print.
189:          */
190:         public String print() {
191:
192:                 return this.getNameOfAssignment() + basic.PrinterConstants.SPACE
193:                                 + scanner.ScannerConstants.EQUALSIGN + basic.PrinterConstants.SPACE
194:                                 + basic.PrinterConstants.SINGLEQUOT + this.getValue()
195:                                 + basic.PrinterConstants.SINGLEQUOT;
196:         }
197:
198:         @Override
199:         public Component accept(final DetailBarVisitor visitor) {
200:                 return visitor.visit(this);
201:         }
202:
203:         @Override
204:         public void accept(final DetailDrawVisitor visitor) {
205:                 visitor.visit(this);
206:         }
207:
208:         @Override
209:         public boolean accept(final CompareVaNameVisitor visitor) {
210:                 return visitor.visit(this);
211:         }
212:
213:         @Override
214:         public String accept(final ItemGetNameVisitor visitor) {
215:                 return visitor.visit(this);
216:         }
217:
218:         @Override
219:         public void accept(final ItemSetNameVisitor visitor) throws IllegalArgumentException,
220:                         ValueNotInRangeOfTypeException, TypeDoesNotExistException, TypeExceptions {
221:                 visitor.visit(this);
222:         }
223:
224:         // /**
225:         // * Konstruktor für "Lokale Variablen", also solche, die in Ext-Skripten definiert werden. Hat
226:         // * KEINE Auswirkungen auf die "Globalen" Variablen.
227:         // *
228:         // * @param name
229:         // * Der Name.
230:         // * @param value
231:         // * Der Wert.
232:         // */
233:         // public VariableAssignment(final String name, final String value) {
234:         // this.nameOfAssignment = name;
235:         // this.value = value;
236:         // this.definition = null;
237:         // this.position = null;
238:         // }
239:
240: }