keySet, final String listPrefix) {
if (keySet.isEmpty()) {
return 0;
}
final String[] array = new String[keySet.size()];
keySet.toArray(array);
return findNextFreeListCounter(array, listPrefix);
}
/**
* Normalize a CSV encoded list of value of an key/value pair.
*
*
* This method removes all whitespace at the begin or the end of CSV values and remove newLine
* signs at the end of value. The ',' is used as list delimiter
*
*
* @param value CSV encoded input data
* @return normalized CSV encoded data or null if {value} is null or empty
*/
public static String normalizeCsvValueString(final String value) {
String normalizedCodes = null;
if (StringUtils.isNotEmpty(value)) {
final String[] codes = value.split(CSV_DELIMITER);
for (final String el : codes) {
if (normalizedCodes == null) {
normalizedCodes = StringUtils.chomp(el.trim());
} else {
normalizedCodes += "," + StringUtils.chomp(el.trim());
}
}
}
return normalizedCodes;
}
/**
* Check a String if it is a comma separated list of values.
*
*
* This method uses the ',' as list delimiter.
*
*
* @param value CSV encoded input data
* @return true if the input data contains a ',' and has more then 1 list element, otherwise false
*/
public static boolean isCsvValueString(final String value) {
if (StringUtils.isNotEmpty(value)) {
final String[] codes = value.split(CSV_DELIMITER);
if (codes.length >= 2
&& StringUtils.isNotEmpty(codes[1].trim())) {
return true;
}
}
return false;
}
/**
* Convert a CSV list to a List of CSV values.
*
* This method removes all whitespace at the begin or the end of CSV values and remove newLine
* signs at the end of value. The ',' is used as list delimiter
*
* @param csv CSV encoded input data
* @return List of CSV normalized values, but never null
*/
@Nonnull
public static List getListOfCsvValues(@Nullable final String csv) {
final List list = new ArrayList<>();
if (StringUtils.isNotEmpty(csv)) {
final String[] values = csv.split(CSV_DELIMITER);
for (final String el : values) {
list.add(el.trim());
}
}
return list;
}
/**
* Convert a List of String elements to a Map of Key/Value pairs.
* Every List element used as a key/value pair and the '=' sign represents the delimiter between
* key and value
*
* @param elements List of key/value elements
* @return Map of Key / Value pairs, but never null
*/
public static Map convertListToMap(final List elements) {
final Map map = new HashMap<>();
for (final String el : elements) {
if (el.contains(KEYVVALUEDELIMITER)) {
final String[] split = el.split(KEYVVALUEDELIMITER);
map.put(split[0], split[1]);
} else {
log.debug("Key/Value Mapper: '" + el + "' contains NO '='. Ignore it.");
}
}
return map;
}
/**
* This method remove all newline delimiter (\n or \r\n) from input data.
*
* @param value Input String
* @return Input String without newline characters
*/
public static String removeAllNewlineFromString(final String value) {
return value.replaceAll("(\\t|\\r?\\n)+", "");
}
}