1 32 33 package com.jeantessier.metrics; 34 35 import java.io.*; 36 import java.util.*; 37 38 public abstract class Printer implements MeasurementVisitor { 39 private PrintWriter out; 40 41 private boolean showEmptyMetrics = false; 42 private boolean showHiddenMeasurements = false; 43 private String indentText = " "; 44 private int indentLevel = 0; 45 46 public Printer(PrintWriter out) { 47 this.out = out; 48 } 49 50 public String getIndentText() { 51 return indentText; 52 } 53 54 public void setIndentText(String indentText) { 55 this.indentText = indentText; 56 } 57 58 public boolean isShowEmptyMetrics() { 59 return showEmptyMetrics; 60 } 61 62 public void setShowEmptyMetrics(boolean showEmptyMetrics) { 63 this.showEmptyMetrics = showEmptyMetrics; 64 } 65 66 public boolean isShowHiddenMeasurements() { 67 return showHiddenMeasurements; 68 } 69 70 public void setShowHiddenMeasurements(boolean showHiddenMeasurements) { 71 this.showHiddenMeasurements = showHiddenMeasurements; 72 } 73 74 protected Printer append(boolean b) { 75 out.print(b); 76 return this; 77 } 78 79 protected Printer append(char c) { 80 out.print(c); 81 return this; 82 } 83 84 protected Printer append(char[] s) { 85 out.print(s); 86 return this; 87 } 88 89 protected Printer append(double d) { 90 out.print(d); 91 return this; 92 } 93 94 protected Printer append(float f) { 95 out.print(f); 96 return this; 97 } 98 99 protected Printer append(int i) { 100 out.print(i); 101 return this; 102 } 103 104 protected Printer append(long l) { 105 out.print(l); 106 return this; 107 } 108 109 protected Printer append(Object obj) { 110 out.print(obj); 111 return this; 112 } 113 114 protected Printer append(String s) { 115 out.print(s); 116 return this; 117 } 118 119 protected Printer indent() { 120 for (int i=0; i<indentLevel; i++) { 121 append(getIndentText()); 122 } 123 124 return this; 125 } 126 127 protected Printer eol() { 128 out.println(); 129 return this; 130 } 131 132 protected void raiseIndent() { 133 indentLevel++; 134 } 135 136 protected void lowerIndent() { 137 indentLevel--; 138 } 139 140 public void visitMetrics(Collection metrics) { 141 Iterator i = metrics.iterator(); 142 while(i.hasNext()) { 143 visitMetrics((Metrics) i.next()); 144 } 145 } 146 147 public abstract void visitMetrics(Metrics metrics); 148 149 public void visitRatioMeasurement(RatioMeasurement measurement) { 150 visitMeasurement(measurement); 151 } 152 153 public void visitNbSubMetricsMeasurement(NbSubMetricsMeasurement measurement) { 154 visitMeasurement(measurement); 155 } 156 157 public void visitCounterMeasurement(CounterMeasurement measurement) { 158 visitMeasurement(measurement); 159 } 160 161 public void visitContextAccumulatorMeasurement(ContextAccumulatorMeasurement measurement) { 162 visitMeasurement(measurement); 163 } 164 165 public void visitNameListMeasurement(NameListMeasurement measurement) { 166 visitMeasurement(measurement); 167 } 168 169 public void visitSubMetricsAccumulatorMeasurement(SubMetricsAccumulatorMeasurement measurement) { 170 visitMeasurement(measurement); 171 } 172 173 public void visitSumMeasurement(SumMeasurement measurement) { 174 visitMeasurement(measurement); 175 } 176 177 protected abstract void visitMeasurement(Measurement measurement); 178 } 179 | Popular Tags |