@Test public void testStringCreation() { message = "string should be created appropriately"; Set<String> tagList = new HashSet<String>(); String actual = formatter.format(tagList); assertEquals(message, "", actual); tagList.add("TagName1"); tagList.add("TagName2"); tagList.add("TagName3"); actual = formatter.format(tagList); assertEquals(message, "TagName1, TagName2, TagName3", actual); }
@SuppressWarnings("unchecked") public String format(final Collection elements) { if (elements.size() == 0) { return ""; } final String seperator = DELIMITER + " "; StringBuilder builder = new StringBuilder(); Iterator iterator = elements.iterator(); while (iterator.hasNext()) { Object next = iterator.next(); if (next != null) { String name = next.toString().trim(); builder.append(name + seperator); } } String formattedString = builder.substring(0, builder.lastIndexOf(seperator)).trim(); return formattedString; }
CollectionFormat { @SuppressWarnings("unchecked") public String format(final Collection elements) { if (elements.size() == 0) { return ""; } final String seperator = DELIMITER + " "; StringBuilder builder = new StringBuilder(); Iterator iterator = elements.iterator(); while (iterator.hasNext()) { Object next = iterator.next(); if (next != null) { String name = next.toString().trim(); builder.append(name + seperator); } } String formattedString = builder.substring(0, builder.lastIndexOf(seperator)).trim(); return formattedString; } }
CollectionFormat { @SuppressWarnings("unchecked") public String format(final Collection elements) { if (elements.size() == 0) { return ""; } final String seperator = DELIMITER + " "; StringBuilder builder = new StringBuilder(); Iterator iterator = elements.iterator(); while (iterator.hasNext()) { Object next = iterator.next(); if (next != null) { String name = next.toString().trim(); builder.append(name + seperator); } } String formattedString = builder.substring(0, builder.lastIndexOf(seperator)).trim(); return formattedString; } CollectionFormat(); }
CollectionFormat { @SuppressWarnings("unchecked") public String format(final Collection elements) { if (elements.size() == 0) { return ""; } final String seperator = DELIMITER + " "; StringBuilder builder = new StringBuilder(); Iterator iterator = elements.iterator(); while (iterator.hasNext()) { Object next = iterator.next(); if (next != null) { String name = next.toString().trim(); builder.append(name + seperator); } } String formattedString = builder.substring(0, builder.lastIndexOf(seperator)).trim(); return formattedString; } CollectionFormat(); Collection<String> parse(final String toParse); @SuppressWarnings("unchecked") String format(final Collection elements); }
CollectionFormat { @SuppressWarnings("unchecked") public String format(final Collection elements) { if (elements.size() == 0) { return ""; } final String seperator = DELIMITER + " "; StringBuilder builder = new StringBuilder(); Iterator iterator = elements.iterator(); while (iterator.hasNext()) { Object next = iterator.next(); if (next != null) { String name = next.toString().trim(); builder.append(name + seperator); } } String formattedString = builder.substring(0, builder.lastIndexOf(seperator)).trim(); return formattedString; } CollectionFormat(); Collection<String> parse(final String toParse); @SuppressWarnings("unchecked") String format(final Collection elements); static final String DELIMITER; }