classdef (Hidden) ParameterMap < matlab.mixin.Copyable
    %ParameterMap - Base class for all protocol Parameter Maps
    % This provides a wrapper around com.mathworks.toolbox.distcomp.remote.ParameterMap
    % to process and restrict the inputs.

    % Copyright 2016 The MathWorks, Inc.
    
    properties
        ConfigMap;
    end
    
    methods (Access = protected)
        function obj = ParameterMap()
            obj.ConfigMap = com.mathworks.toolbox.distcomp.remote.ParameterMap();
        end
        
        function convertedData = massageDataForJava(~, data)
            % Convert MATLAB data types to Java equivalents
            if ischar(data) && isrow(data)
                convertedData = java.lang.String(data);
            elseif isstring(data) && isscalar(data)
                convertedData = java.lang.String(data);
            elseif isnumeric(data) && isscalar(data)
                convertedData = java.lang.Double(data);
            elseif islogical(data) && isscalar(data)
                convertedData = java.lang.Boolean(data);
            else
                convertedData = data;
            end
        end
    end
    
    methods (Hidden, Abstract)
        hAddCredentialParameters(obj, credential);
    end
    
    methods
        function put(obj, sshKey, sshValue)
            % Add name value pair to config map
            import parallel.internal.cluster.SshParameterMap
            sshValue = obj.massageDataForJava(sshValue);
            obj.ConfigMap.put(sshKey, sshValue);
        end
    end
    
    methods(Access = protected)
        % Override copyElement method:
        function cpObj = copyElement(obj)
            % Make a shallow copy
            cpObj = copyElement@matlab.mixin.Copyable(obj);
            % Make a deep copy of the ConfigMap object
            cpObj.ConfigMap = obj.ConfigMap.createCopy();
        end
    end
end

