Skip to content

Commit 7d9313f

Browse files
committed
Update JSON file parser to support input streams
1 parent 155cf1b commit 7d9313f

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

swan_assist/src/main/java/de/fraunhofer/iem/swan/assist/data/JSONFileLoader.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,20 @@ public static void loadInitialFile() {
7373
}
7474

7575
/**
76-
* Compares new JSON file with original file and updates list with merged results
76+
* Compares new JSON file with original file and updates list with merged results. Loads new file
77+
* is a JSON file was not selected.
7778
* @param newFilePath File path of new configuration file
7879
*/
7980
public static void loadUpdatedFile(String newFilePath) {
8081

81-
JSONFileComparator fileComparator = new JSONFileComparator(congFile, newFilePath);
82-
methods = fileComparator.compareJSONFile();
83-
setConfigurationFile(newFilePath);
82+
if(isFileSelected()){
83+
JSONFileComparator fileComparator = new JSONFileComparator(congFile, newFilePath);
84+
methods = fileComparator.compareJSONFile();
85+
setConfigurationFile(newFilePath);
86+
}else{
87+
setConfigurationFile(newFilePath);
88+
loadInitialFile();
89+
}
8490
}
8591

8692
/**
@@ -215,8 +221,6 @@ public static boolean methodExists(String methodSignature) {
215221
return methods.containsKey(methodSignature);
216222
}
217223

218-
//Returns method for the specified signature
219-
220224
/**
221225
* Returns an instance of the method
222226
* @param methodSignature Method Signature of requested method.
@@ -227,8 +231,6 @@ public static MethodWrapper getMethod(String methodSignature) {
227231
return methods.get(methodSignature);
228232
}
229233

230-
//Remove method from list
231-
232234
/**
233235
* Remove method from list
234236
* @param method Method to be removed

swan_assist/src/main/java/de/fraunhofer/iem/swan/assist/data/JSONFileParser.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
import de.fraunhofer.iem.swan.assist.util.Constants;
1515
import de.fraunhofer.iem.swan.data.Method;
1616

17+
import java.io.InputStreamReader;
1718
import java.util.HashMap;
1819
import java.util.ResourceBundle;
20+
import java.util.Set;
1921

2022
/**
2123
* Parses JSON file and returns methods.
@@ -32,6 +34,13 @@ public JSONFileParser(String path) {
3234
congFilePath = path;
3335
}
3436

37+
/**
38+
* Default constructor
39+
*/
40+
public JSONFileParser() {
41+
42+
}
43+
3544
/**
3645
* Returns file path for configuration file
3746
* @return File path as a string.
@@ -54,12 +63,30 @@ public void setCongFilePath(String congFilePath) {
5463
*/
5564
public HashMap<String, MethodWrapper> parseJSONFileMap() {
5665

57-
HashMap<String, MethodWrapper> methods = new HashMap<String, MethodWrapper>();
5866
Parser parser = new Parser(congFilePath);
67+
parser.parse(congFilePath);
68+
69+
return parseMethods(parser.methods());
70+
}
71+
72+
/**
73+
* Parses file and returns method.
74+
* @return HashMap of methods
75+
*/
76+
public HashMap<String, MethodWrapper> parseJSONFileStream(InputStreamReader streamReader) {
77+
78+
Parser parser = new Parser();
79+
parser.parseStream(streamReader);
80+
return parseMethods(parser.methods());
81+
}
82+
83+
private HashMap<String, MethodWrapper> parseMethods(Set<Method> methodsSet){
84+
5985
ResourceBundle resource = ResourceBundle.getBundle("dialog_messages");
86+
HashMap<String, MethodWrapper> methods = new HashMap<String, MethodWrapper>();
6087

6188
try {
62-
for (Method method : parser.parseFile(congFilePath)) {
89+
for (Method method :methodsSet ) {
6390

6491
MethodWrapper methodWrapper = new MethodWrapper(method);
6592

0 commit comments

Comments
 (0)