package io.fabianterhorst.fastlayout.converters;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fabianterhorst on 18.05.16.
 */
public class LayoutConverters {

    List<LayoutConverter> converters;

    public LayoutConverters() {
    }

    public void setAll(List<LayoutConverter> converters) {
        this.converters = converters;
    }

    public LayoutAttribute convert(Object attributeValue, String attributeName) {
        LayoutAttribute layoutAttribute = null;
        for (LayoutConverter layoutConverter : converters) {
            if (layoutAttribute == null) {
                layoutAttribute = layoutConverter.convert(attributeValue, attributeName);
                if(layoutAttribute != null && layoutAttribute.getType() == LayoutAttribute.Type.ASSIGNED) {
                    break;
                }
            }
        }
        return layoutAttribute;
    }

    public List<LayoutAttribute> finish() {
        List<LayoutAttribute> finished = new ArrayList<>();
        for (LayoutConverter layoutConverter : converters) {
            List<LayoutAttribute> currentlyFinished = layoutConverter.finish();
            if(currentlyFinished != null) {
                finished.addAll(currentlyFinished);
            }
        }
        return finished;
    }
}

@@ -178,24 +178,32 @@
 ters %7B%0A%0A    
+private 
 List%3CLayoutC

make converters field in LayoutConverters private