-
- boolean checkForConflict(Node nodeToProcess) {
- HashMap<String, String> valueMap = new HashMap<String, String>(); // HashMap from varName to value
- HashMap<String, Integer> writerMap = new HashMap<String, Integer>(); // HashMap from varName to appNum
-
- // Update the valueMap and check if we have conflict in the setSet
- for (NameValuePair i : nodeToProcess.getSetSet()) {
- if (i.getIsManual()) // Manual input: we have no conflict
- continue; // If this manual write is the last write, this is actually a break
-
- if (valueMap.containsKey(i.getVarName())) {
- if (!valueMap.get(i.getVarName()).equals(i.getValue())) { // Check if their value is different we have a conflict
- errorMessage = createErrorMessage(i, valueMap, writerMap);
- return true;
- }
- else // We have two writers writing the same value
- writerMap.put(i.getVarName(), i.getAppNum()+writerMap.get(i.getVarName()));
- } else {
- valueMap.put(i.getVarName(), i.getValue());
- writerMap.put(i.getVarName(), i.getAppNum());
- }
- }
-
- // Comparing the outSet to setSet
- for (NameValuePair i : nodeToProcess.getOutSet()) {
- if (valueMap.containsKey(i.getVarName())) {
- String value = valueMap.get(i.getVarName());
- Integer writer = writerMap.get(i.getVarName());
- if ((value != null)&&(writer != null)) {
- if (!value.equals(i.getValue())&&!writer.equals(i.getAppNum())) { // We have different values
- errorMessage = createErrorMessage(i, valueMap, writerMap);
- return true;
- }
- }
- }
- }
-
- return false;
+
+ String createErrorMessage(Update u, Update u2) {
+ String message = "Conflict found between the two apps. "+u.getApp()+
+ " has written the value: "+u.getValue()+
+ " to the attribute: "+u.getAttribute()+" while "
+ +u2.getApp()+" is writing the value: "
+ +u2.getValue()+" to the same variable!";
+ System.out.println(message);
+ return message;