[New] Added StringHelper.getStringAsSet()

This commit is contained in:
Robert von Burg 2020-10-23 14:35:01 +02:00
parent 5c5487efdc
commit a44876770c
1 changed files with 15 additions and 0 deletions

View File

@ -15,6 +15,7 @@
*/
package li.strolch.utils.helper;
import static java.util.stream.Collectors.toSet;
import static li.strolch.utils.helper.ByteHelper.setBit;
import java.io.UnsupportedEncodingException;
@ -22,6 +23,8 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.MessageFormat;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Stream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -873,6 +876,18 @@ public class StringHelper {
return value.trim();
}
/**
* Parses the given string as a comma separated value, returning as a set
*
* @param csv
* the comma separated value
*
* @return the set from parsing the value
*/
public static Set<String> getStringAsSet(String csv) {
return Stream.of(trimOrEmpty(csv).split(",")).map(String::trim).filter(s -> s.length() > 0).collect(toSet());
}
/**
* Return a pseudo unique id which is incremented on each call. The id is initialized from the current time
*