/** * Takes a set of labels represented as a string and parses them out. Any invalid labels will be * transformed to that they become valid. * * @param labelsString the string to parse. * @param factory class that will convert a string to the object required * @return the collection of labels contained within the string. */ public static <Y> Set<Y> buildFromString(CreateFromString<Y> factory, final String labelsString) { if (StringUtils.isBlank(labelsString)) { return Collections.emptySet(); } final String[] labelArray = StringUtils.split(labelsString, LabelsField.SEPARATOR_CHAR); final Set<Y> labels = new LinkedHashSet<Y>(); for (String label : labelArray) { final String cleanLabel = LabelParser.getCleanLabel(label); if (cleanLabel != null) { labels.add(factory.create(cleanLabel)); } } return labels; }