/**
 * Copyright (C) 2006-2018 Talend Inc. - www.talend.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.talend.sdk.component.studio.model.parameter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import lombok.NoArgsConstructor;

/**
 * Utility class for ElementParameter value conversion. It is used to convert string values from repository to
 * appropriate types
 * used in ElementParameter
 */
@NoArgsConstructor(access = lombok.AccessLevel.PRIVATE)
public final class ValueConverter {

    /**
     * Pattern used to find first and last square bracket in the string
     */
    private static final Pattern BRACKETS_PATTERN = Pattern.compile("^\\[|\\]$");

    /**
     * Pattern used to find first and last curly bracket in the string
     */
    private static final Pattern CURLY_BRACKETS_PATTERN = Pattern.compile("^\\{|\\}$");

    /**
     * Converts String to List of Maps (table element parameter representation)
     * It assumes {@code str} has correct format (it doesn't check it)
     * 
     * TODO: quick implementation. May have bugs
     * 
     * @param str String value to be converted to list
     * @return list value
     */
    public static List<Map<String, Object>> toTable(final String str) {
        if (str == null || str.isEmpty()) {
            return new ArrayList<>();
        }
        ArrayList<Map<String, Object>> table = new ArrayList<>();
        String trimmed = trimBrackets(str);
        String[] records = trimmed.split("\\}, \\{");
        for (String record : records) {
            record = trimCurlyBrackets(record);
            String[] entries = record.split(", ");
            Map<String, Object> element = new HashMap<String, Object>();
            for (String entry : entries) {
                String[] keyValue = entry.split("=");
                String key = keyValue[0];
                String value = keyValue[1];
                element.put(key, value);
            }
            table.add(element);
        }
        return table;
    }

    /**
     * Trims first symbol if it is '[' and last one if it is ']'
     * 
     * @param str String to trim
     * @return trimmed string
     */
    private static String trimBrackets(final String str) {
        return BRACKETS_PATTERN.matcher(str).replaceAll("");
    }

    /**
     * Trims first symbol if it is '{' and last one if it is '}'
     * 
     * @param str String to trim
     * @return trimmed string
     */
    private static String trimCurlyBrackets(final String str) {
        return CURLY_BRACKETS_PATTERN.matcher(str).replaceAll("");
    }

}

@@ -1844,35 +1844,23 @@
 if (
-str == null %7C%7C str.
+isL
 is
+t
 Empty(
+str
 )) %7B
@@ -2585,32 +2585,352 @@
 n table;%0A    %7D%0A%0A
+    /**%0A     * Checks whether String representation of the list is empty or not%0A     * %0A     * @param list String representation of the list%0A     * @return true, if it is empty%0A     */%0A    private static boolean isListEmpty(final String list) %7B%0A        return list == null %7C%7C list.isEmpty() %7C%7C %22%5B%5D%22.equals(list);%0A    %7D%0A%0A
     /**%0A     * T

fix ValueConverter for '[]' input