| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.inference.loggers; |
| 27 |
|
| 28 |
import java.io.Serializable; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public interface LogColumn extends Serializable { |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
void setLabel(String label); |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
String getLabel(); |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
void setMinimumWidth(int minimumWidth); |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
int getMinimumWidth(); |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
String getFormatted(); |
| 71 |
|
| 72 |
public abstract class Abstract implements LogColumn { |
| 73 |
|
| 74 |
private String label; |
| 75 |
private int minimumWidth; |
| 76 |
|
| 77 |
public Abstract(String label) { |
| 78 |
|
| 79 |
setLabel(label); |
| 80 |
minimumWidth = -1; |
| 81 |
} |
| 82 |
|
| 83 |
public void setLabel(String label) { |
| 84 |
if (label == null) throw new IllegalArgumentException("column label is null"); |
| 85 |
this.label = label; |
| 86 |
} |
| 87 |
|
| 88 |
public String getLabel() { |
| 89 |
StringBuffer buffer = new StringBuffer(label); |
| 90 |
|
| 91 |
if (minimumWidth > 0) { |
| 92 |
while (buffer.length() < minimumWidth) { |
| 93 |
buffer.append(' '); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
return buffer.toString(); |
| 98 |
} |
| 99 |
|
| 100 |
public void setMinimumWidth(int minimumWidth) { |
| 101 |
this.minimumWidth = minimumWidth; |
| 102 |
} |
| 103 |
|
| 104 |
public int getMinimumWidth() { |
| 105 |
return minimumWidth; |
| 106 |
} |
| 107 |
|
| 108 |
public final String getFormatted() { |
| 109 |
StringBuffer buffer = new StringBuffer(getFormattedValue()); |
| 110 |
|
| 111 |
if (minimumWidth > 0) { |
| 112 |
while (buffer.length() < minimumWidth) { |
| 113 |
buffer.append(' '); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
return buffer.toString(); |
| 118 |
} |
| 119 |
|
| 120 |
protected abstract String getFormattedValue(); |
| 121 |
} |
| 122 |
|
| 123 |
public class Default extends Abstract { |
| 124 |
|
| 125 |
private Object object; |
| 126 |
|
| 127 |
public Default(String label, Object object) { |
| 128 |
super(label); |
| 129 |
this.object = object; |
| 130 |
} |
| 131 |
|
| 132 |
protected String getFormattedValue() { |
| 133 |
return object.toString(); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
} |