com.beust.jcommander.converters.DefaultListConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jcommander Show documentation
Show all versions of jcommander Show documentation
Command line parsing library for Java
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;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy