Update of /cvsroot/jrobin/src/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv9125/jrobin/core
Modified Files:
DsDef.java Sample.java Util.java XmlWriter.java
Log Message:
Consistent formatting of doubles for the entire core package
Index: DsDef.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/DsDef.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DsDef.java 4 Sep 2003 13:26:41 -0000 1.1
--- DsDef.java 16 Oct 2003 09:26:30 -0000 1.2
***************
*** 150,155 ****
public String dump() {
return "DS:" + dsName + ":" + dsType + ":" + heartbeat +
! ":" + Util.formatDouble(minValue, true) +
! ":" + Util.formatDouble(maxValue, true);
}
--- 150,155 ----
public String dump() {
return "DS:" + dsName + ":" + dsType + ":" + heartbeat +
! ":" + Util.formatDouble(minValue, "U") +
! ":" + Util.formatDouble(maxValue, "U");
}
Index: Sample.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/Sample.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Sample.java 9 Oct 2003 08:48:23 -0000 1.2
--- Sample.java 16 Oct 2003 09:26:30 -0000 1.3
***************
*** 227,231 ****
for(int i = 0; i < values.length; i++) {
buffer.append(":");
! buffer.append(Util.formatDouble(values[i], true));
}
return buffer.toString();
--- 227,231 ----
for(int i = 0; i < values.length; i++) {
buffer.append(":");
! buffer.append(Util.formatDouble(values[i], "U"));
}
return buffer.toString();
Index: Util.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/Util.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Util.java 29 Sep 2003 11:25:05 -0000 1.4
--- Util.java 16 Oct 2003 09:26:30 -0000 1.5
***************
*** 24,28 ****
--- 24,30 ----
import java.text.DecimalFormat;
+ import java.text.NumberFormat;
import java.util.Date;
+ import java.util.Locale;
/**
***************
*** 32,39 ****
*/
public class Util {
! private static String DOUBLE_FORMAT = "0.0000000000E00";
! private static final DecimalFormat df = new DecimalFormat(DOUBLE_FORMAT);
!
! private Util() { };
/**
--- 34,44 ----
*/
public class Util {
! // pattern RRDTool uses to format doubles in XML files
! static final String PATTERN = "0.0000000000E00";
! static final DecimalFormat df;
! static {
! df = (DecimalFormat) NumberFormat.getNumberInstance(Locale.ENGLISH);
! df.applyPattern(PATTERN);
! }
/**
***************
*** 80,89 ****
}
! static String formatDouble(double x, boolean translateNans) {
if(Double.isNaN(x)) {
! return translateNans? "U": "" + Double.NaN;
! }
! if(x >= Long.MIN_VALUE && x <= Long.MAX_VALUE && Math.round(x) == x) {
! return "" + (long) x;
}
return df.format(x);
--- 85,91 ----
}
! static String formatDouble(double x, String nanString) {
if(Double.isNaN(x)) {
! return nanString;
}
return df.format(x);
***************
*** 91,95 ****
static String formatDouble(double x) {
! return formatDouble(x, false);
}
--- 93,97 ----
static String formatDouble(double x) {
! return formatDouble(x, "" + Double.NaN);
}
***************
*** 110,114 ****
}
! public static double parseDouble(String valueStr) {
double value;
try {
--- 112,116 ----
}
! static double parseDouble(String valueStr) {
double value;
try {
***************
*** 116,120 ****
}
catch(NumberFormatException nfe) {
- // Arne Vandamme fixed bug on UNKN value from Windows
value = Double.NaN;
}
--- 118,121 ----
Index: XmlWriter.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/XmlWriter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** XmlWriter.java 15 Oct 2003 12:49:07 -0000 1.3
--- XmlWriter.java 16 Oct 2003 09:26:30 -0000 1.4
***************
*** 26,41 ****
import java.io.PrintWriter;
import java.util.Stack;
- import java.util.Locale;
- import java.text.DecimalFormat;
- import java.text.NumberFormat;
class XmlWriter {
static final String INDENT_STR = " ";
- static final String PATTERN = "0.0000000000E00";
- static final DecimalFormat df;
- static {
- df = (DecimalFormat) NumberFormat.getNumberInstance(Locale.ENGLISH);
- df.applyPattern(PATTERN);
- }
private PrintWriter writer;
--- 26,32 ----
***************
*** 72,85 ****
void writeTag(String tag, double value, String nanString) {
! if(Double.isNaN(value)) {
! writeTag(tag, nanString);
! }
! else {
! writeTag(tag, df.format(value));
! }
}
void writeTag(String tag, double value) {
! writeTag(tag, value, "" + Double.NaN);
}
--- 63,71 ----
void writeTag(String tag, double value, String nanString) {
! writeTag(tag, Util.formatDouble(value, nanString));
}
void writeTag(String tag, double value) {
! writeTag(tag, Util.formatDouble(value));
}
|