From 2507337d897f29254e8a831fa161d110140d23e1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 1 Apr 2011 11:25:04 +0200 Subject: [PATCH] Override Object.toString() to get a reasonable String representation. --- .../java/net/pterodactylus/sone/text/PartContainer.java | 16 ++++++++++++++++ .../java/net/pterodactylus/sone/text/TemplatePart.java | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/text/PartContainer.java b/src/main/java/net/pterodactylus/sone/text/PartContainer.java index 7399859..05bfb3e 100644 --- a/src/main/java/net/pterodactylus/sone/text/PartContainer.java +++ b/src/main/java/net/pterodactylus/sone/text/PartContainer.java @@ -18,6 +18,7 @@ package net.pterodactylus.sone.text; import java.io.IOException; +import java.io.StringWriter; import java.io.Writer; import java.util.ArrayList; import java.util.List; @@ -62,4 +63,19 @@ public class PartContainer implements Part { } } + // + // OBJECT METHODS + // + + @Override + public String toString() { + StringWriter stringWriter = new StringWriter(); + try { + render(stringWriter); + } catch (IOException ioe1) { + /* should never throw, ignore. */ + } + return stringWriter.toString(); + } + } diff --git a/src/main/java/net/pterodactylus/sone/text/TemplatePart.java b/src/main/java/net/pterodactylus/sone/text/TemplatePart.java index 1ac1fdd..b948f10 100644 --- a/src/main/java/net/pterodactylus/sone/text/TemplatePart.java +++ b/src/main/java/net/pterodactylus/sone/text/TemplatePart.java @@ -18,6 +18,7 @@ package net.pterodactylus.sone.text; import java.io.IOException; +import java.io.StringWriter; import java.io.Writer; import net.pterodactylus.util.template.Template; @@ -89,4 +90,19 @@ public class TemplatePart implements Part, net.pterodactylus.util.template.Part template.render(templateContext.mergeContext(template.getInitialContext()), writer); } + // + // OBJECT METHODS + // + + @Override + public String toString() { + StringWriter stringWriter = new StringWriter(); + try { + render(stringWriter); + } catch (IOException ioe1) { + /* should never throw, ignore. */ + } + return stringWriter.toString(); + } + } -- 2.7.4