aQute.bnd.build.model.conversions.SimpleListConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of biz.aQute.bndlib Show documentation
Show all versions of biz.aQute.bndlib Show documentation
bndlib: A Swiss Army Knife for OSGi
package aQute.bnd.build.model.conversions;
import java.util.ArrayList;
import java.util.List;
import aQute.bnd.osgi.Constants;
import aQute.libg.qtokens.QuotedTokenizer;
public class SimpleListConverter implements Converter,String> {
private Converter< ? extends R, ? super String> itemConverter;
public static Converter,String> create(Converter itemConverter) {
return new SimpleListConverter(itemConverter);
}
public static Converter,String> create() {
return new SimpleListConverter(new NoopConverter());
}
private SimpleListConverter(Converter< ? extends R, ? super String> itemConverter) {
this.itemConverter = itemConverter;
}
public List convert(String input) throws IllegalArgumentException {
if (input == null)
return null;
List result = new ArrayList();
if (input == null || Constants.EMPTY_HEADER.equalsIgnoreCase(input.trim()))
return result;
QuotedTokenizer qt = new QuotedTokenizer(input, ",");
String token = qt.nextToken();
while (token != null) {
result.add(itemConverter.convert(token.trim()));
token = qt.nextToken();
}
return result;
}
@Override
public List error(String msg) {
List l = new ArrayList();
l.add(itemConverter.error(msg));
return l;
}
}