package com.hammurapi.convert;

import java.util.Iterator;
import java.util.concurrent.Callable;

import com.hammurapi.common.Context;

public class SingletonConverterPart implements ConverterPart {

	@Override
	public <S, T> T convert(S source, Class<T> targetType, Context context, Converter master) throws ConversionException {
		if (source instanceof Iterable) {
			Iterator it = ((Iterable) source).iterator();
			if (it.hasNext()) {
				Object value = it.next();
				if (!it.hasNext()) {
					return master.convert(value, targetType, context);
				}
			}
		}
		return null;
	}

}
