Debian Codegraph @

src/dr/inference/loggers/LogColumn.java

raw symbols SCIP
1 /*
2 * LogColumn.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.inference.loggers;
27
28 import java.io.Serializable;
29
30 /**
31 * An interface for a column in a log.
32 *
33 * @author Andrew Rambaut
34 * @author Alexei Drummond
35 * @version $Id: LogColumn.java,v 1.5 2005/05/24 20:25:59 rambaut Exp $
36 */
37
38 public interface LogColumn extends Serializable {
39
40 /**
41 * Set the label (heading) for this column
42 *
43 * @param label the column label
44 */
45 void setLabel(String label);
46
47 /**
48 * @return the label (heading) for this column
49 */
50 String getLabel();
51
52 /**
53 * Set the minimum width in characters for this column
54 *
55 * @param minimumWidth the minimum width in characters
56 */
57 void setMinimumWidth(int minimumWidth);
58
59 /**
60 * @return the minimum width in characters for this column
61 */
62 int getMinimumWidth();
63
64 /**
65 * Returns a string containing the current value for this column with
66 * appropriate formatting.
67 *
68 * @return the formatted string.
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 }