Skip to content

Package: AssignmentFileParser

AssignmentFileParser

nameinstructionbranchcomplexitylinemethod
AssignmentFileParser(RouterConfiguration, Buffer)
M: 0 C: 35
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
createVA(String, AbstractVariableDefinition, String, Position)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getAssignmentFile()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getState()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getVariableAssignmentList()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
parse()
M: 0 C: 66
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
setState(AbstractAssignmentState)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /**
2: *
3: */
4: package parser;
5:
6: import java.util.ArrayList;
7: import java.util.HashMap;
8: import java.util.Map;
9:
10: import basic.Buffer;
11: import model.Comment;
12: import model.Position;
13: import model.RouterConfiguration;
14: import model.assignment.AssignmentFile;
15: import model.assignment.VariableAssignment;
16: import parser.states.assignmentstates.AbstractAssignmentState;
17: import parser.states.assignmentstates.AssignmentInitialState;
18: import parser.tempparserobjects.TempVariableAssignment;
19: import symbols.AbstractSymbol;
20: import symbols.EndSymbol;
21:
22: /**
23: * @author hfw410wi - Mark Wittig
24: *
25: */
26: public final class AssignmentFileParser extends AbstractFileParser {
27:
28:         /**
29:          * The associated RouterConfiguration.
30:          */
31:         private final RouterConfiguration rc;
32:
33:         /**
34:          * state of the parser.
35:          */
36:         private transient AbstractAssignmentState state;
37:
38:         /**
39:          * Temporary Object, which is used to fill the final object when every information is collected.
40:          */
41:         private final transient TempVariableAssignment tVA;
42:
43:         /**
44:          * List of VariableAssignments.
45:          */
46:         private final transient Map<String, VariableAssignment> vAL;
47:
48:         /**
49:          * The final AssignmentFile.
50:          */
51:         private final transient AssignmentFile assignmentFile;
52:
53:         /**
54:          * The AssignmentFileParser will automatically generate a AssignmentFile after instantiation
55:          * which can be obtained via getAssignmentFile().
56:          *
57:          * @param rc
58:          * The {@link RouterConfiguration} to use.
59:          * @param buffer
60:          * Buffer<Symbol>
61:          * @throws ParserException
62:          * ParserException
63:          * @throws InterruptedException
64:          * InterruptedException
65:          */
66:         public AssignmentFileParser(final RouterConfiguration rc, final Buffer<AbstractSymbol> buffer)
67:                         throws InterruptedException, ParserException {
68:                 super(buffer);
69:                 this.rc = rc;
70:                 this.state = new AssignmentInitialState();
71:                 this.tVA = new TempVariableAssignment();
72:                 this.vAL = new HashMap<String, VariableAssignment>();
73:                 setFinished(false);
74:                 setComments(new ArrayList<Comment>());
75:                 this.assignmentFile = parse();
76:         }
77:
78:         /**
79:          *
80:          * @throws InterruptedException
81:          * InterruptedException
82:          * @throws ParserException
83:          * ParserException
84:          * @return AssignmentFile
85:          */
86:         private AssignmentFile parse() throws InterruptedException, ParserException {
87:
88:•                while (!this.isFinished()) {
89:•                        if (this.tVA.isReady()) {
90:                                 this.getVariableAssignmentList().put(this.tVA.getName(),
91:                                                 createVA(this.tVA.getName(), this.tVA.getVariableDefinition(),
92:                                                                 this.tVA.getValue(), this.tVA.getPosition()));
93:                                 this.tVA.setReady(false);
94:                         }
95:•                        if (this.getBuffer().peek() instanceof EndSymbol) {
96:                                 this.setFinished(true);
97:                         } else {
98:                                 final AbstractAssignmentState currentState = this.getState();
99:                                 currentState.parse(this.rc, this.tVA, this.getBuffer(), this);
100:
101:                         }
102:                 }
103:
104:                 return new AssignmentFile(getVariableAssignmentList(), getComments());
105:         }
106:
107:         /**
108:          * yet another totally senseless function for PMD to be quiet. Suppresses "Avoid instantiating
109:          * new objects inside loops" warning.
110:          *
111:          * @param nameOfAssignment
112:          * nameOfAssignment
113:          * @param definition
114:          * definition
115:          * @param value
116:          * value
117:          * @param position
118:          * position
119:          * @return VariableAssignment
120:          */
121:         private VariableAssignment createVA(final String nameOfAssignment,
122:                         final model.definition.AbstractVariableDefinition definition, final String value,
123:                         final Position position) {
124:                 return new VariableAssignment(nameOfAssignment, definition, value, position);
125:
126:         }
127:
128:         /**
129:          * @return the state
130:          */
131:         private AbstractAssignmentState getState() {
132:                 return this.state;
133:         }
134:
135:         /**
136:          * @param state
137:          * the state to set
138:          */
139:         public void setState(final AbstractAssignmentState state) {
140:                 this.state = state;
141:         }
142:
143:         /**
144:          *
145:          * @return HashMap<String, VariableAssignment>
146:          */
147:         private Map<String, VariableAssignment> getVariableAssignmentList() {
148:                 return this.vAL;
149:         }
150:
151:         /**
152:          * Returns the desired AssignmentFile which is automatically created right after instantiation.
153:          *
154:          * @return the assignmentFile
155:          */
156:         public AssignmentFile getAssignmentFile() {
157:                 return this.assignmentFile;
158:         }
159:
160: }