@Test public void testGetAllTags() { Assert.assertEquals(new DiscussionNoteData().getAllTags(Locale.ENGLISH).length, 0); Assert.assertEquals(new DiscussionNoteData().getAllTags(null).length, 0); String[] tags = { "a", "aB", "cc", "dd", "elf", "drei", "vier", "z", "A", "Z" }; DiscussionNoteData parent = new DiscussionNoteData(); parent.setTags(generateTags(tags)); for (int i = 0; i < RandomUtils.nextInt(20) + 10; i++) { DiscussionNoteData comment = new DiscussionNoteData(); comment.setTags(generateTags(tags)); parent.getComments().add(comment); } String[] allTags = parent.getAllTags(Locale.ENGLISH); Assert.assertTrue(allTags.length <= tags.length); Collator collator = Collator.getInstance(Locale.ENGLISH); for (int i = 0; i < allTags.length - 1; i++) { Assert.assertTrue(collator.compare(allTags[i], allTags[i + 1]) < 0); } Assert.assertTrue(collator.compare(allTags[0], allTags[allTags.length - 1]) < 0); HashSet<String> predefinedTags = new HashSet<String>(); predefinedTags.addAll(Arrays.asList(tags)); HashSet<String> foundTags = new HashSet<String>(); for (int i = 0; i < allTags.length; i++) { String tag = allTags[i]; Assert.assertTrue(predefinedTags.contains(tag)); Assert.assertFalse(foundTags.contains(tag)); foundTags.add(tag); } }
public String[] getAllTags(Locale locale) { locale = locale != null ? locale : Locale.ENGLISH; if (allTags == null) { Collection<String> tags = new TreeSet<String>(Collator.getInstance(locale)); extractTags(this, tags); if (comments != null) { for (NoteData child : comments) { extractTags(child, tags); } } allTags = tags.toArray(new String[tags.size()]); } return allTags; }
DiscussionNoteData extends NoteData { public String[] getAllTags(Locale locale) { locale = locale != null ? locale : Locale.ENGLISH; if (allTags == null) { Collection<String> tags = new TreeSet<String>(Collator.getInstance(locale)); extractTags(this, tags); if (comments != null) { for (NoteData child : comments) { extractTags(child, tags); } } allTags = tags.toArray(new String[tags.size()]); } return allTags; } }
DiscussionNoteData extends NoteData { public String[] getAllTags(Locale locale) { locale = locale != null ? locale : Locale.ENGLISH; if (allTags == null) { Collection<String> tags = new TreeSet<String>(Collator.getInstance(locale)); extractTags(this, tags); if (comments != null) { for (NoteData child : comments) { extractTags(child, tags); } } allTags = tags.toArray(new String[tags.size()]); } return allTags; }  }
DiscussionNoteData extends NoteData { public String[] getAllTags(Locale locale) { locale = locale != null ? locale : Locale.ENGLISH; if (allTags == null) { Collection<String> tags = new TreeSet<String>(Collator.getInstance(locale)); extractTags(this, tags); if (comments != null) { for (NoteData child : comments) { extractTags(child, tags); } } allTags = tags.toArray(new String[tags.size()]); } return allTags; }  String[] getAllTags(Locale locale); List<NoteData> getComments(); void setComments(List<NoteData> comments); }
DiscussionNoteData extends NoteData { public String[] getAllTags(Locale locale) { locale = locale != null ? locale : Locale.ENGLISH; if (allTags == null) { Collection<String> tags = new TreeSet<String>(Collator.getInstance(locale)); extractTags(this, tags); if (comments != null) { for (NoteData child : comments) { extractTags(child, tags); } } allTags = tags.toArray(new String[tags.size()]); } return allTags; }  String[] getAllTags(Locale locale); List<NoteData> getComments(); void setComments(List<NoteData> comments);  }