com.beust.jcommander.converters.DefaultListConverter Maven / Gradle / Ivy
package com.beust.jcommander.converters;
import com.beust.jcommander.IStringConverter;
import com.beust.jcommander.internal.Lists;
import java.util.List;
/**
* A converter to obtain a list of elements.
* @param the element type
* @author simon04
*/
public class DefaultListConverter implements IStringConverter> {
private final IParameterSplitter splitter;
private final IStringConverter converter;
/**
* Constructs a new converter.
* @param splitter to split value into list of arguments
* @param converter to convert list of arguments to target element type
*/
public DefaultListConverter(IParameterSplitter splitter, IStringConverter converter) {
this.splitter = splitter;
this.converter = converter;
}
@Override
public List convert(String value) {
List result = Lists.newArrayList();
for (String param : splitter.split(value)) {
result.add(converter.convert(param));
}
return result;
}
}