All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aQute.bnd.build.model.conversions.SimpleListConverter Maven / Gradle / Ivy

There is a newer version: 7.0.0
Show newest version
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;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy