Seperate the end line and alarm type in Alarm.

This commit is contained in:
Kui LIU
2017-08-11 18:41:18 +02:00
parent 3c7ac0a721
commit 2d7cdae971
2 changed files with 31 additions and 9 deletions
@@ -8,7 +8,8 @@ public class Alarm {
private String buggyFileName;
private String fixedCommitId;
private String fixedFileName;
private Map<Integer, String> positions;
private Map<Integer, String> alarmTypes;
private Map<Integer, Integer> positions;
public Alarm(String buggyCommitId, String buggyFileName, String fixedCommitId, String fixedFileName) {
super();
@@ -34,11 +35,19 @@ public class Alarm {
return fixedFileName;
}
public Map<Integer, String> getPositions() {
public Map<Integer, String> getAlarmTypes() {
return alarmTypes;
}
public void setAlarmTypes(Map<Integer, String> alarmTypes) {
this.alarmTypes = alarmTypes;
}
public Map<Integer, Integer> getPositions() {
return positions;
}
public void setPositions(Map<Integer, String> positions) {
public void setPositions(Map<Integer, Integer> positions) {
this.positions = positions;
}
@@ -28,12 +28,13 @@ public class AlarmsReader {
String fixedInfo = line.substring(arrowIndex + 2);
String[] buggyElements = buggyInfo.split(":");
String[] fixedElements = fixedInfo.split(":");
String alarmType = buggyElements[0];
String projectName = buggyElements[1];
String buggyCommitId = buggyElements[2];
String buggyFile = buggyElements[3];
int startLine = Integer.parseInt(buggyElements[4]);
String endLineAndAlarmType = buggyElements[5] + ":" + buggyElements[0];
int endLine = Integer.parseInt(buggyElements[5]);
String fixCommitId = fixedElements[1];
String fixedFile = fixedElements[2];
@@ -50,11 +51,23 @@ public class AlarmsReader {
int index = alarms.indexOf(alarm);
if (index >= 0) {
Alarm tempAlarm = alarms.get(index);
Map<Integer, String> positions = tempAlarm.getPositions();
positions.put(startLine, endLineAndAlarmType);
Map<Integer, Integer> positions = tempAlarm.getPositions();
if (positions.containsKey(startLine)) {
int end = positions.get(startLine);
if (endLine < end) {
positions.put(startLine, endLine);
tempAlarm.getAlarmTypes().put(startLine, alarmType);
}
} else {
positions.put(startLine, endLine);
tempAlarm.getAlarmTypes().put(startLine, alarmType);
}
} else {
Map<Integer, String> positions = new HashMap<>();
positions.put(startLine, endLineAndAlarmType);
Map<Integer, String> alarmTypes = new HashMap<>();
alarmTypes.put(startLine, alarmType);
alarm.setAlarmTypes(alarmTypes);
Map<Integer, Integer> positions = new HashMap<>();
positions.put(startLine, endLine);
alarm.setPositions(positions);
alarms.add(alarm);
}