Improvement of toString()
@@ -7,6 +7,7 @@ package net.finmath.marketdata.model.curves;
import java.io.Serializable;
import java.lang.ref.SoftReference;
+import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.time.LocalDate;
import java.util.ArrayList;
@@ -17,6 +18,7 @@ import java.util.concurrent.ConcurrentHashMap;
import net.finmath.interpolation.RationalFunctionInterpolation;
import net.finmath.marketdata.model.AnalyticModelInterface;
+import net.finmath.time.FloatingpointDate;
/**
* This class represents a curve build from a set of points in 2D.
@@ -428,14 +430,6 @@ public class Curve extends AbstractCurve implements Serializable, Cloneable {
this.curveCacheReference = null;
}
- public String toString() {
- String objectAsString = super.toString() + "\n";
- for (Point point : points) {
- objectAsString = objectAsString + point.time + "\t" + valueFromInterpolationEntity(point.value, point.time) + "\n";
- }
- return objectAsString;
- }
-
private double interpolationEntityFromValue(double value, double time) {
switch(interpolationEntity) {
case VALUE:
@@ -492,4 +486,23 @@ public class Curve extends AbstractCurve implements Serializable, Cloneable {
CurveBuilder curveBuilder = new CurveBuilder(this);
return curveBuilder;
}
+
+ @Override
+ public String toString() {
+ /*
+ * Pretty print curve (appended to standard toString)
+ */
+ StringBuilder curveTableString = new StringBuilder();
+ NumberFormat formatTime = new DecimalFormat("0.00000000E0"); // Floating point time is accurate to 3+5 digits.
+ for (Point point : points) {
+ curveTableString.append(formatTime.format(point.time) + "\t");
+ curveTableString.append(FloatingpointDate.getDateFromFloatingPointDate(getReferenceDate(), point.time) + "\t");
+ curveTableString.append(valueFromInterpolationEntity(point.value, point.time) + "\n");
+ }
+
+ return "Curve [points=" + points + ", pointsBeingParameters=" + pointsBeingParameters + ", interpolationMethod="
+ + interpolationMethod + ", extrapolationMethod=" + extrapolationMethod + ", interpolationEntity="
+ + interpolationEntity + ", rationalFunctionInterpolation=" + rationalFunctionInterpolation
+ + ", toString()=" + super.toString() + ",\n" + curveTableString + "]";
+ }
}
