/*
- * Sone - CollectionAccessor.java - Copyright © 2010–2012 David Roden
+ * Sone - CollectionAccessor.java - Copyright © 2010–2013 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
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;
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.
*/
public class CollectionAccessor extends ReflectionAccessor {
- /**
- * {@inheritDoc}
- */
@Override
public Object get(TemplateContext templateContext, Object object, String member) {
if (object == null) {
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);
}