package com.stratio.connector.commons.util;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Array;

import static com.stratio.connector.commons.util.TypeDecisor.*;
/**
 * Created by jmgomez on 25/03/15.
 */
public class PropertyValueRecovered {



    /**
     * The Log.
     */
    private transient static final Logger logger = LoggerFactory.getLogger(PropertyValueRecovered.class);

    /**
     * This method recovered the array of properties.
     *
     * @param properties the string which represents the properties to recovered.
     * @param type the type to recovered.
     * @return the properties.
     */

    public static <T>  T[] recoveredValueASArray(Class<T> type, String properties) {


        String[] stringParseProperties = properties.replaceAll("\\s+", "").replaceAll("\\[", "").replaceAll("]", "").split(",");
        T[] returnValue = (T[]) Array.newInstance(type,0); //we ensure not return null values.
        if (isString(type)){
            returnValue = (T[])stringParseProperties;
        } else if (isBoolean(type)){
            Boolean[] tempReturnValue = new Boolean[stringParseProperties.length];
            for (int i=0;i<stringParseProperties.length;i++){
                tempReturnValue[i] = Boolean.parseBoolean(stringParseProperties[i]);
            }
            returnValue = (T[])tempReturnValue;
        }else{
            String message = String.format("The type $s is not supported for conversion.",type);
            logger.error(message);
            throw new RuntimeException(String.format(message));
        }


        return returnValue;
    }


    /**
     * This method recovered the property.
     *
     * @param properties the string which represents the properties to recovered.
     * @param type the type to recovered.
     * @return the properties.
     */
    public static <T>  T recoveredValue(Class<T> type, String properties){
        return recoveredValueASArray(type,properties)[0];
    }

}
@@ -736,16 +736,103 @@
 ies) %7B%0A%0A
+        logger.info(String.format(%22Recovered propeties %5B$s%5D as %5B$s%5D%22,properties,type));
 %0A       
@@ -1678,24 +1678,181 @@
 %0A        %7D%0A%0A
+        if (logger.isDebugEnabled())%7B%0A            logger.debug(String.format(%22The property as converted to $s%22, Arrays.deepToString(returnValue)));%0A        %7D
 %0A        ret

add log