From: David ‘Bombe’ Roden Date: Fri, 1 Apr 2011 09:25:04 +0000 (+0200) Subject: Override Object.toString() to get a reasonable String representation. X-Git-Tag: 0.6^2~36 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=2507337d897f29254e8a831fa161d110140d23e1;p=Sone.git Override Object.toString() to get a reasonable String representation. --- 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(); + } + }