我有 summariseData() 方法并调用了很多时间来检索值。但第一次是工作文件,但第二次执行值在 HashMap 中增加。
void summarizeData() {
HashMap outerMap = new HashMap();
ArrayList list = new ArrayList(dataClass.getData());
for (int indx = 0; indx < list.size(); indx++) {
System.out.println("indx : " + indx);
Resultset rs = new Resultset();
rs = (Resultset) list.get(indx);
if (rs != null) {
int id = rs.getTestCaseNumber();
if (id > 0) {
Object isExists = outerMap.get(id);
if (isExists != null) {
//System.out.println("found entry so updating");
Resultset inRs = new Resultset();
inRs = (Resultset) isExists;
if (inRs != null) {
int totExec = inRs.getTestExecution();
int totPass = inRs.getTestCasePass();
int totFail = inRs.getTestCaseFail();
// System.out.println("totE :" + totExec + " totP:" + totPass + " totF:" + totFail);
int newRsStat = rs.getTestCasePass();
if (newRsStat == 1) {
totPass++;
inRs.setTestCasePass(totPass);
} else {
totFail++;
inRs.setTestCaseFail(totFail);
}
totExec++;
// System.out.println("id : "+id+" totPass: "+totPass+" totFail:"+totFail);
// System.out.println("key : " + id + " val : " + inRs.getTestCaseNumber() + " " + inRs.getTestCasePass() + " " + inRs.getTestCaseFail());
inRs.setTestExecution(totExec);
outerMap.put(id, inRs);
}
} else {
// System.out.println("not exist so new entry" + " totE:" + rs.getTestExecution() + " totP:" + rs.getTestCasePass() + " totF:" + rs.getTestCaseFail());
outerMap.put(id, rs);
}
}
} else {
System.out.println("rs null");
}
}
第一次执行时的输出:
indx : 0
indx : 1
indx : 2
indx : 3
indx : 4
indx : 5
indx : 6
indx : 7
indx : 8
indx : 9
indx : 10
totE :1 totP:1 totF:0
indx : 11
totE :1 totP:1 totF:0
indx : 12
totE :1 totP:1 totF:0
indx : 13
totE :1 totP:1 totF:0
indx : 14
totE :1 totP:1 totF:0
indx : 15
totE :1 totP:1 totF:0
indx : 16
totE :1 totP:1 totF:0
indx : 17
totE :1 totP:1 totF:0
indx : 18
totE :1 totP:1 totF:0
indx : 19
totE :1 totP:1 totF:0
第二次执行时的输出:
indx : 0
indx : 1
indx : 2
indx : 3
indx : 4
indx : 5
indx : 6
indx : 7
indx : 8
indx : 9
indx : 10
totE :2 totP:2 totF:0
indx : 11
totE :2 totP:2 totF:0
indx : 12
totE :2 totP:2 totF:0
indx : 13
totE :2 totP:2 totF:0
indx : 14
totE :2 totP:2 totF:0
indx : 15
totE :2 totP:2 totF:0
indx : 16
totE :2 totP:2 totF:0
indx : 17
totE :2 totP:2 totF:0
indx : 18
totE :2 totP:2 totF:0
indx : 19
totE :2 totP:2 totF:0
而我每次执行都需要相同的输出。