From 445675e50d824e5899007fe7afccd769dfcf0d10 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 1 Apr 2011 20:39:14 +0200 Subject: [PATCH] =?utf8?q?Don=E2=80=99t=20use=20profile=20fields=20of=20se?= =?utf8?q?nders=20when=20generating=20a=20string=20from=20a=20Post.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../net/pterodactylus/sone/web/SearchPage.java | 36 +++++++++++++++++----- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/web/SearchPage.java b/src/main/java/net/pterodactylus/sone/web/SearchPage.java index 5cdd563..b10162e 100644 --- a/src/main/java/net/pterodactylus/sone/web/SearchPage.java +++ b/src/main/java/net/pterodactylus/sone/web/SearchPage.java @@ -79,7 +79,7 @@ public class SearchPage extends SoneTemplatePage { List phrases = parseSearchPhrases(query); Set sones = webInterface.getCore().getSones(); - Set> soneHits = getHits(sones, phrases, SoneStringGenerator.GENERATOR); + Set> soneHits = getHits(sones, phrases, SoneStringGenerator.COMPLETE_GENERATOR); Set posts = new HashSet(); for (Sone sone : sones) { @@ -239,8 +239,28 @@ public class SearchPage extends SoneTemplatePage { */ private static class SoneStringGenerator implements StringGenerator { - /** A static instance of the Sone string generator. */ - public static final SoneStringGenerator GENERATOR = new SoneStringGenerator(); + /** A static instance of a complete Sone string generator. */ + public static final SoneStringGenerator COMPLETE_GENERATOR = new SoneStringGenerator(true); + + /** + * A static instance of a Sone string generator that will only use the + * name of the Sone. + */ + public static final SoneStringGenerator NAME_GENERATOR = new SoneStringGenerator(false); + + /** Whether to generate a string from all data of a Sone. */ + private final boolean complete; + + /** + * Creates a new Sone string generator. + * + * @param complete + * {@code true} to use the profile’s fields, {@code false} to + * not to use the profile‘s fields + */ + private SoneStringGenerator(boolean complete) { + this.complete = complete; + } /** * {@inheritDoc} @@ -259,8 +279,10 @@ public class SearchPage extends SoneTemplatePage { if (soneProfile.getLastName() != null) { soneString.append(' ').append(soneProfile.getLastName()); } - for (Field field : soneProfile.getFields()) { - soneString.append(' ').append(field.getValue()); + if (complete) { + for (Field field : soneProfile.getFields()) { + soneString.append(' ').append(field.getValue()); + } } return soneString.toString(); } @@ -284,10 +306,10 @@ public class SearchPage extends SoneTemplatePage { StringBuilder postString = new StringBuilder(); postString.append(post.getText()); if (post.getRecipient() != null) { - postString.append(' ').append(SoneStringGenerator.GENERATOR.generateString(post.getRecipient())); + postString.append(' ').append(SoneStringGenerator.NAME_GENERATOR.generateString(post.getRecipient())); } for (Reply reply : webInterface.getCore().getReplies(post)) { - postString.append(' ').append(SoneStringGenerator.GENERATOR.generateString(reply.getSone())); + postString.append(' ').append(SoneStringGenerator.NAME_GENERATOR.generateString(reply.getSone())); postString.append(' ').append(reply.getText()); } return postString.toString(); -- 2.7.4