CheckPointing.java [src/csip/utils] Revision: default Date:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package csip.utils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
Timed check pointing.
@author od
*/
public class CheckPointing {
static final String ROW = "[%1$tH:%1$tM:%1$tS.%1$tL] delta: %2$5d ms - %3$s\n";
List<CP> cps = new ArrayList<>();
private static class CP {
Date time;
String msg;
CP(Date time, String msg) {
this.time = time;
this.msg = msg;
}
}
public void check(String msg) {
cps.add(new CP(new Date(), msg));
}
@Override
public String toString() {
StringBuilder s = new StringBuilder();
for (int i = 0; i < cps.size(); i++) {
CP cp = cps.get(i);
long diff = (i > 0) ? cp.time.getTime() - cps.get(i - 1).time.getTime() : 0;
s.append(String.format(ROW, cp.time, diff, cp.msg));
}
return s.toString();
}
}