Debian Codegraph @

src/dr/inference/loggers/ArrayLogFormatter.java

raw symbols SCIP
1 /*
2 * ArrayLogFormatter.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 dr.inference.trace.Trace;
29 import dr.inference.trace.TraceType;
30
31 import java.util.ArrayList;
32 import java.util.List;
33
34 /**
35 * @author Alexei Drummond
36 */
37 public class ArrayLogFormatter implements LogFormatter {
38
39 String heading;
40 String[] labels = null;
41 List<String> lines = new ArrayList<String>();
42 List<Trace> traces = new ArrayList<Trace>();
43 boolean echo = false;
44
45 public ArrayLogFormatter(boolean echo) {
46 this.echo = echo;
47 }
48
49 public void startLogging(String title) {
50 }
51
52 public void logHeading(String heading) {
53 this.heading = heading;
54 echo(heading);
55 }
56
57 public void logLine(String line) {
58 lines.add(line);
59 echo(line);
60 }
61
62 public void logLabels(String[] labels) {
63 if (this.labels == null) {
64 this.labels = labels;
65 for (String label : labels) {
66 traces.add(new Trace(label, TraceType.REAL));
67 }
68 echo(labels);
69 } else throw new RuntimeException("logLabels() method should only be called once!");
70 }
71
72 public void logValues(String[] values) {
73 for (int i = 0; i < values.length; i++) {
74 // Double v = Double.parseDouble(values[i]);
75 traces.get(i).add(Double.parseDouble(values[i]));
76 }
77 echo(values);
78 }
79
80 public void stopLogging() {
81 }
82
83 public List<Trace> getTraces() {
84 return traces;
85 }
86
87 private void echo(String s) {
88 if (echo) System.out.println(s);
89 }
90
91 private void echo(String[] strings) {
92 if (echo) {
93 for (String s : strings) {
94 System.out.print(s + "\t");
95 }
96 System.out.println();
97 }
98 }
99 }