From: David ‘Bombe’ Roden Date: Wed, 5 Sep 2012 12:13:56 +0000 (+0200) Subject: Add method to get the plain text of a part. X-Git-Tag: 0.8.3^2~53^2~1 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=3ab8b115466818f44ac5e35870cec3a4287b9281;p=Sone.git Add method to get the plain text of a part. --- diff --git a/src/main/java/net/pterodactylus/sone/text/LinkPart.java b/src/main/java/net/pterodactylus/sone/text/LinkPart.java index 1b47080..202b9db 100644 --- a/src/main/java/net/pterodactylus/sone/text/LinkPart.java +++ b/src/main/java/net/pterodactylus/sone/text/LinkPart.java @@ -77,21 +77,26 @@ public class LinkPart implements Part { } /** - * Returns the text of this part. + * Returns the title of this part. * - * @return The text of this part + * @return The title of this part */ - public String getText() { - return text; + public String getTitle() { + return title; } + // + // PART METHODS + // + /** - * Returns the title of this part. + * Returns the text of this part. * - * @return The title of this part + * @return The text of this part */ - public String getTitle() { - return title; + @Override + public String getText() { + return text; } } diff --git a/src/main/java/net/pterodactylus/sone/text/Part.java b/src/main/java/net/pterodactylus/sone/text/Part.java index 76e80ef..79c59dc 100644 --- a/src/main/java/net/pterodactylus/sone/text/Part.java +++ b/src/main/java/net/pterodactylus/sone/text/Part.java @@ -26,6 +26,12 @@ package net.pterodactylus.sone.text; */ public interface Part { - /* no methods. */ + /** + * Returns the text contained in this part. This should return plain text + * without any format information. + * + * @return The plain text of this part + */ + public String getText(); } diff --git a/src/main/java/net/pterodactylus/sone/text/PartContainer.java b/src/main/java/net/pterodactylus/sone/text/PartContainer.java index e456cd9..a8a7e85 100644 --- a/src/main/java/net/pterodactylus/sone/text/PartContainer.java +++ b/src/main/java/net/pterodactylus/sone/text/PartContainer.java @@ -81,6 +81,22 @@ public class PartContainer implements Part, Iterable { } // + // PART METHODS + // + + /** + * {@inheritDoc} + */ + @Override + public String getText() { + StringBuilder partText = new StringBuilder(); + for (Part part : parts) { + partText.append(part.getText()); + } + return partText.toString(); + } + + // // ITERABLE METHODS // diff --git a/src/main/java/net/pterodactylus/sone/text/PlainTextPart.java b/src/main/java/net/pterodactylus/sone/text/PlainTextPart.java index 09c1fba..2c29ee2 100644 --- a/src/main/java/net/pterodactylus/sone/text/PlainTextPart.java +++ b/src/main/java/net/pterodactylus/sone/text/PlainTextPart.java @@ -38,7 +38,7 @@ public class PlainTextPart implements Part { } // - // ACCESSORS + // PART METHODS // /** @@ -46,6 +46,7 @@ public class PlainTextPart implements Part { * * @return The text of this part */ + @Override public String getText() { return text; } diff --git a/src/main/java/net/pterodactylus/sone/text/PostPart.java b/src/main/java/net/pterodactylus/sone/text/PostPart.java index c416c57..6241b7a 100644 --- a/src/main/java/net/pterodactylus/sone/text/PostPart.java +++ b/src/main/java/net/pterodactylus/sone/text/PostPart.java @@ -52,4 +52,16 @@ public class PostPart implements Part { return post; } + // + // PART METHODS + // + + /** + * {@inheritDoc} + */ + @Override + public String getText() { + return post.getText(); + } + } diff --git a/src/main/java/net/pterodactylus/sone/text/SonePart.java b/src/main/java/net/pterodactylus/sone/text/SonePart.java index 475c091..37f098b 100644 --- a/src/main/java/net/pterodactylus/sone/text/SonePart.java +++ b/src/main/java/net/pterodactylus/sone/text/SonePart.java @@ -18,6 +18,7 @@ package net.pterodactylus.sone.text; import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.template.SoneAccessor; /** * {@link Part} implementation that stores a reference to a {@link Sone}. @@ -52,4 +53,16 @@ public class SonePart implements Part { return sone; } + // + // PART METHODS + // + + /** + * {@inheritDoc} + */ + @Override + public String getText() { + return SoneAccessor.getNiceName(sone); + } + }