Skip to content

Package: TypeFileManager

TypeFileManager

nameinstructionbranchcomplexitylinemethod
TypeFileManager()
M: 0 C: 23
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
addAssignmentFileManager(String, AssignmentFileManager)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
addTypeFile(TypeFile)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
checkCycle()
M: 4 C: 11
73%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 3 C: 1
25%
M: 0 C: 1
100%
extend()
M: 15 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getAllAssignments()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getAlltypes()
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%
getAssignmentValue(NamedVariableType)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getTypeByName(String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getTypeFileList()
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%
initAllAssignments()
M: 33 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
resolve()
M: 0 C: 15
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%

Coverage

1: package model.type;
2:
3: import java.util.ArrayList;
4: import java.util.HashMap;
5: import java.util.Map;
6: import java.util.Map.Entry;
7:
8: import model.assignment.AssignmentFile;
9: import model.assignment.VariableAssignment;
10:
11: /**
12: * Class to manage all NamedVariableTypes inside the TypeFile-Objects.
13: *
14: * @author HFW416 Marek
15: *
16: */
17: public class TypeFileManager {
18:         /**
19:          * List of all TypeFiles.
20:          */
21:         private final ArrayList<TypeFile> typeFileList;
22:         /**
23:          * Combined HashMap of all NamedVariableTypes provided by the TypeFile-Objects.
24:          */
25:         private final Map<String, NamedVariableType> alltypes;
26:
27:         /**
28:          * Stores all AssigmentFileManagers with the "path" of the RouterConfiguration it belongs to as
29:          * key.
30:          */
31:         private final HashMap<String, AssignmentFileManager> aFMMap =
32:                         new HashMap<String, AssignmentFileManager>();
33:
34:         /**
35:          * Stores all Assignments.
36:          */
37:         private final Map<String, VariableAssignment> allAssignments =
38:                         new HashMap<String, VariableAssignment>();
39:
40:         /**
41:          * Constructor for TypeFileManager. Inits the typeFileList and the allTypes HashMap.
42:          */
43:         public TypeFileManager() {
44:                 this.typeFileList = new ArrayList<TypeFile>();
45:                 this.alltypes = new HashMap<String, NamedVariableType>();
46:         }
47:
48:         /**
49:          * Adds a TypeFile to the list and provides the TypeFile with a Reference to the
50:          * TypeFileManager.
51:          *
52:          * @param typeFile
53:          * The TypeFile to add.
54:          */
55:         public void addTypeFile(final TypeFile typeFile) {
56:                 this.typeFileList.add(typeFile);
57:                 typeFile.setTypeFileManager(this);
58:                 this.alltypes.putAll(typeFile.getTypes());
59:         }
60:
61:         /**
62:          * Combines all the HashMaps of the TypeFiles and resolves all the NamedVariableTypes in them
63:          * afterwards.
64:          *
65:          * @throws TypeDoesNotExistException
66:          * if some referenced type is not found.
67:          * @throws TypeExceptions
68:          * if a cycle is detected or the reference is unresolved.
69:          */
70:         public void resolve() throws TypeDoesNotExistException, TypeExceptions {
71:•                for (TypeFile tp : this.typeFileList) {
72:                         tp.resolveTypes();
73:                 }
74:         }
75:
76:         /**
77:          * detects cycles in typeList.
78:          *
79:          * @throws TypeExceptions
80:          * if a cycle is detected or the reference is unresolved.
81:          * @throws TypeDoesNotExistException
82:          * if some referenced type is not found.
83:          */
84:         public void checkCycle() throws TypeExceptions, TypeDoesNotExistException {
85:•                for (TypeFile tp : this.typeFileList) {
86:                         tp.cycleListdetect();
87:                 }
88:         }
89:
90:         /**
91:          * Extend all the type extension.
92:          *
93:          * @throws TypeDoesNotExistException
94:          * if some referenced type is not found.
95:          * @throws TypeExceptions
96:          * if a cycle is detected or the reference is unresolved.
97:          */
98:         public void extend() throws TypeDoesNotExistException, TypeExceptions {
99:•                for (TypeFile tp : this.typeFileList) {
100:                         tp.convertExtension();
101:                 }
102:         }
103:
104:         /**
105:          * Getter for the allTypes HashMap.
106:          *
107:          * @return the allTypes HashMap
108:          */
109:         public Map<String, NamedVariableType> getAlltypes() {
110:                 return alltypes;
111:         }
112:
113:         /**
114:          * Getter for the TypeFileList.
115:          *
116:          * @return the typeFileList.
117:          */
118:         public ArrayList<TypeFile> getTypeFileList() {
119:                 return typeFileList;
120:         }
121:
122:         /**
123:          * Get the value of the variable.
124:          *
125:          * @param namedVariableType
126:          * The NamedVariableType.
127:          * @return the value of the variable.
128:          */
129:         public String getAssignmentValue(final NamedVariableType namedVariableType) {
130:                 return this.getAllAssignments().get(namedVariableType.getName()).getValue();
131:         }
132:
133:         /**
134:          * Adds a AssigmentFileManager to the aFMMap.
135:          *
136:          * @param aFM
137:          * AssignmentFileManager
138:          * @param path
139:          * String of RouterConfiguration path.
140:          */
141:         public void addAssignmentFileManager(final String path, final AssignmentFileManager aFM) {
142:                 this.aFMMap.put(path, aFM);
143:         }
144:
145:         /**
146:          * Stores all assignments once at the beginning of initialization.
147:          */
148:         public void initAllAssignments() {
149:                 // TODO Separate for each configuration
150:•                for (Entry<String, AssignmentFileManager> entry : this.aFMMap.entrySet()) {
151:•                        for (AssignmentFile assignmentFile : entry.getValue().getAssignmentFiles()) {
152:                                 this.getAllAssignments().putAll(assignmentFile.getAssignments());
153:                         }
154:                 }
155:         }
156:
157:         /**
158:          * Get the allAssignments.
159:          *
160:          * @return get allAssignments.
161:          */
162:         public Map<String, VariableAssignment> getAllAssignments() {
163:                 return allAssignments;
164:         }
165:
166:         public AbstractType getTypeByName(String name) {
167:                 return this.alltypes.get(name);
168:         }
169:         // TODO: Maybe initAllTypeFiless
170: }