7 protected static int labelWidth = 24;
8 protected static int indentation = 3;
9 protected static int floatPrecision = 4;
10 protected static int valueWidth = 0;
12 protected String label;
13 protected String value;
14 protected List<Report> subReports;
16 public static final String NEWLINE = System.getProperty(
"line.separator");
26 Report.labelWidth = labelWidth;
29 public static void setIndentation(
int indentation) {
30 Report.indentation = indentation;
33 public static void setFloatPrecision(
int floatPrecision) {
34 Report.floatPrecision = floatPrecision;
43 Report.valueWidth = valueWidth;
48 public Report(String label, String value) {
50 this.value = (value ==
null) ?
null : String.format(
"%" + (valueWidth == 0 ?
"" : valueWidth) +
"s", value);
51 subReports =
new ArrayList<Report>();
54 public Report(String label,
int value) {
55 this(label, String.format(
"%d", value));
58 public Report(String label,
double value) {
59 this(label, String.format(
"%." + floatPrecision +
"g", value));
62 public Report(String label,
int[] value) {
63 this(label, formatVector(value));
66 public Report(String label,
double[] value) {
67 this(label, formatVector(value));
70 public Report(String label,
boolean value) {
71 this(label, value ?
"yes" :
"no");
74 public Report(String label) {
77 subReports =
new ArrayList<Report>();
86 public void add(Report subReport) {
87 subReports.add(subReport);
92 public void add(String label, String value) {
93 add(
new Report(label, value));
96 public void add(String label,
int value) {
97 add(
new Report(label, value));
100 public void add(String label,
double value) {
101 add(
new Report(label, value));
104 public void add(String label,
boolean value) {
105 add(
new Report(label, value));
108 public void add(String label,
int[] value) {
109 add(
new Report(label, value));
112 public void add(String label,
double[] value) {
113 add(
new Report(label, value));
116 public void add(String label) {
117 add(
new Report(label));
122 public String toString() {
126 public String toString(
int baseIndentation) {
129 if (baseIndentation > 0)
130 s += String.format(
"%" + baseIndentation +
"s",
"");
132 s += String.format(
"%" + (labelWidth == 0 ?
"" : labelWidth) +
"s %s", label +
":", value);
137 if (!subReports.isEmpty()) {
138 for (Report report : subReports)
139 s += report.toString(baseIndentation + indentation);
144 protected static String formatVector(
int[] value) {
146 for (
int i = 0; i < value.length; i++) {
149 s += String.format(
"%d", value[i]);
154 protected static String formatVector(
double[] value) {
156 for (
int i = 0; i < value.length; i++) {
159 s += String.format(
"%." + floatPrecision +
"g", value[i]);