From e067e7616e4465c3f45c57eb3f66444215d089bb Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 9 Nov 2013 16:34:38 +0100 Subject: [PATCH] Use Joiner and TO_NICE_NAME to concatenate the Sone names. --- .../pterodactylus/sone/template/CollectionAccessor.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/template/CollectionAccessor.java b/src/main/java/net/pterodactylus/sone/template/CollectionAccessor.java index e6b1dfc..b9fb346 100644 --- a/src/main/java/net/pterodactylus/sone/template/CollectionAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/CollectionAccessor.java @@ -17,6 +17,10 @@ package net.pterodactylus.sone.template; +import static com.google.common.base.Joiner.on; +import static com.google.common.collect.FluentIterable.from; +import static net.pterodactylus.sone.data.Sone.TO_NICE_NAME; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -27,6 +31,8 @@ import net.pterodactylus.util.template.Accessor; import net.pterodactylus.util.template.ReflectionAccessor; import net.pterodactylus.util.template.TemplateContext; +import com.google.common.base.Joiner; + /** * {@link Accessor} for {@link Collection}s that adds a couple of specialized * properties that only work for collections that contain the right types. @@ -55,14 +61,7 @@ public class CollectionAccessor extends ReflectionAccessor { sones.add((Sone) sone); } Collections.sort(sones, Sone.NICE_NAME_COMPARATOR); - StringBuilder soneNames = new StringBuilder(); - for (Sone sone : sones) { - if (soneNames.length() > 0) { - soneNames.append(", "); - } - soneNames.append(SoneAccessor.getNiceName(sone)); - } - return soneNames.toString(); + return on(", ").join(from(sones).transform(TO_NICE_NAME)); } return super.get(templateContext, object, member); } -- 2.7.4