blob: 00bf9ac26591fc66fef948cb72f38a7299248d98 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
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 <T> the element type
* @author simon04
*/
public class DefaultListConverter<T> implements IStringConverter<List<T>> {
private final IParameterSplitter splitter;
private final IStringConverter<T> 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<T> converter) {
this.splitter = splitter;
this.converter = converter;
}
@Override
public List<T> convert(String value) {
List<T> result = Lists.newArrayList();
for (String param : splitter.split(value)) {
result.add(converter.convert(param));
}
return result;
}
}
|