@Test public void emptyResultForNoItems() { assertEquals("", FormatJoinHelper.INSTANCE.apply(Collections.emptySet(), options)); }
@Override public Object apply(Collection<?> context, Options options) { if (context == null || context.isEmpty()) { return ""; } String separator = options.hash("sep", ","); String format = options.hash("format", null); Function<Object, String> formatter = format != null ? each -> String.format(format, each) : Object::toString; return context.stream() .map(formatter) .collect(joining(separator)); }
FormatJoinHelper implements Helper<Collection<?>> { @Override public Object apply(Collection<?> context, Options options) { if (context == null || context.isEmpty()) { return ""; } String separator = options.hash("sep", ","); String format = options.hash("format", null); Function<Object, String> formatter = format != null ? each -> String.format(format, each) : Object::toString; return context.stream() .map(formatter) .collect(joining(separator)); } }
FormatJoinHelper implements Helper<Collection<?>> { @Override public Object apply(Collection<?> context, Options options) { if (context == null || context.isEmpty()) { return ""; } String separator = options.hash("sep", ","); String format = options.hash("format", null); Function<Object, String> formatter = format != null ? each -> String.format(format, each) : Object::toString; return context.stream() .map(formatter) .collect(joining(separator)); }  }
FormatJoinHelper implements Helper<Collection<?>> { @Override public Object apply(Collection<?> context, Options options) { if (context == null || context.isEmpty()) { return ""; } String separator = options.hash("sep", ","); String format = options.hash("format", null); Function<Object, String> formatter = format != null ? each -> String.format(format, each) : Object::toString; return context.stream() .map(formatter) .collect(joining(separator)); }  @Override Object apply(Collection<?> context, Options options); }
FormatJoinHelper implements Helper<Collection<?>> { @Override public Object apply(Collection<?> context, Options options) { if (context == null || context.isEmpty()) { return ""; } String separator = options.hash("sep", ","); String format = options.hash("format", null); Function<Object, String> formatter = format != null ? each -> String.format(format, each) : Object::toString; return context.stream() .map(formatter) .collect(joining(separator)); }  @Override Object apply(Collection<?> context, Options options); static final String NAME; }