package net.fortuna.ical4j.model;

import net.fortuna.ical4j.model.parameter.XParameter;
import org.apache.commons.codec.DecoderException;

import java.net.URISyntaxException;
import java.util.Collections;
import java.util.List;

/**
 * Created by fortuna on 8/09/14.
 */
public class ParameterBuilder extends AbstractContentBuilder {

    private final List<ParameterFactory<?>> factories;

    private String name;

    private String value;

    public ParameterBuilder() {
        this(Collections.emptyList());
    }

    public ParameterBuilder(List<ParameterFactory<? extends Parameter>> factories) {
        this.factories = factories;
    }

    public ParameterBuilder name(String name) {
        // parameter names are case-insensitive, but convert to upper case to simplify further processing
        this.name = name.toUpperCase();
        return this;
    }

    public ParameterBuilder value(String value) {
        this.value = value;
        return this;
    }

    /**
     * @return a new parameter instance
     */
    public Parameter build() throws URISyntaxException {
        Parameter parameter = null;
        String decodedValue;
        try {
            decodedValue = ParameterCodec.INSTANCE.decode(value);
        } catch (DecoderException e) {
            decodedValue = value;
        }
        for (ParameterFactory<?> factory : factories) {
            if (factory.supports(name)) {
                parameter = factory.createParameter(decodedValue);
                break;
            }
        }

        if (parameter == null) {
            if (isExperimentalName(name)) {
                parameter = new XParameter(name, decodedValue);
            }
            else if (allowIllegalNames()) {
                parameter = new XParameter(name, decodedValue);
            }
            else {
                throw new IllegalArgumentException(String.format("Unsupported parameter name: %s", name));
            }
        }
        return parameter;
    }
}

@@ -186,27 +186,25 @@
 va.util.
-Collections
+ArrayList
 ;%0Aimport
@@ -485,29 +485,23 @@
 his(
-Collections.empt
+new Arra
 yList
+%3C%3E
 ());
@@ -585,32 +585,32 @@
 %3E%3E factories) %7B%0A
-
         this.fac
@@ -628,32 +628,488 @@
 ctories;%0A    %7D%0A%0A
+    /**%0A     * Set the list of parameter factories supporting this builder instance.%0A     * @param factories a list of parameter factories%0A     * @return the builder instance%0A     * @deprecated preference the constructor option for specifying factories%0A     */%0A    @Deprecated%0A    public ParameterBuilder factories(List%3CParameterFactory%3C?%3E%3E factories) %7B%0A        this.factories.clear();%0A        this.factories.addAll(factories);%0A        return this;%0A    %7D%0A%0A
     public Param

Revert method removal for backwards compatibility