|
From: <dir...@us...> - 2009-07-23 11:05:50
|
Revision: 2098
http://shox.svn.sourceforge.net/shox/?rev=2098&view=rev
Author: dirk_held
Date: 2009-07-23 11:05:31 +0000 (Thu, 23 Jul 2009)
Log Message:
-----------
Move the creation of the FileEvaluationLogger object to the
end-of-line handling, when the title elements are actually present.
Modified Paths:
--------------
trunk/src/net/sf/shox/simulator/util/StatUtil.java
Modified: trunk/src/net/sf/shox/simulator/util/StatUtil.java
===================================================================
--- trunk/src/net/sf/shox/simulator/util/StatUtil.java 2009-07-23 10:22:32 UTC (rev 2097)
+++ trunk/src/net/sf/shox/simulator/util/StatUtil.java 2009-07-23 11:05:31 UTC (rev 2098)
@@ -37,12 +37,40 @@
// to replace all spaces with an underline "_".
private int index; // the next position, where a statistical element is written to.
private FileEvaluationLogger log; // If set, dump values to a csv-file too.
+ private String file = "";
+ private char separator = ' ';
/**
* @param vals enter here the number of statistic values.
+ * @param file use "", to not create an additional CSV-file, or a valid filename otherwise.
+ * @param separator the separating char between two columns of the CSV-file.
*/
+ public StatUtil(int vals, String file, char separator) {
+ init(vals, file, separator);
+ }
+
+ /**
+ * @param vals enter here the number of statistic values.
+ */
public StatUtil(int vals) {
- this.vals = ++vals;
+ init(vals, "", ' ');
+ }
+
+ /**
+ * method to actually initialize the object.
+ *
+ * @param vals the number of statistic values.
+ * @param file the CSV-file, if any (== "" for no CSV-file).
+ * @param separator the column-separator for the former file.
+ */
+ private void init(@SuppressWarnings("hiding") int vals,
+ @SuppressWarnings("hiding") String file,
+ @SuppressWarnings("hiding") char separator) {
+
+ this.vals = ++vals;
+ this.file = file;
+ this.separator = separator;
+
val = new Object[vals]; // This array will hold all your generated values
title = new String[vals]; // for each column, add a title, but not forget
@@ -53,16 +81,6 @@
log = null;
}
- /**
- * Method to add a CSV-file to dump all values to too.
- *
- * @param file the file-name for the to be created CSV-file, like statistics.csv
- * @param separator the char between two columns like ' '
- */
- public void addCSVfile(String file, char separator) {
- log = new FileEvaluationLogger(separator, file, title);
- }
-
/** do not forget to close the CSV-file, after the last line was added. */
public void closeCSVfile() {
if (log != null) {
@@ -139,6 +157,10 @@
if (index == vals) {
resetIndex();
+ if ((log == null) && (file.length() > 0)) {
+ log = new FileEvaluationLogger(separator, file, title);
+ }
+
if (log != null) {
log.write((Object[]) val);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|