function deleteKeyValuePair(h, Type, varargin)
%DELETEKEYVALUEPAIR - Add a key-value pair to one of the internal vectors

% Copyright 2011-2019 The MathWorks, Inc.
    
  %check the args to make sure they all conform to the expected format
  [args_ok, Keys] = locCheckArgs(Type, varargin{:});
  if ~(args_ok)
      DAStudio.error('RTW:buildInfo:badMethodArguments',...
                     'RTW.BuildInfo.deleteKeyValuePair');
  end

  % if any of the Keys are already in the list, remove them.
  switch (Type)
      case 'BuildArg'
        cur_keys = get(h.BuildArgs,'Key');
        idx = ~ismember(cur_keys,Keys);
        h.BuildArgs = h.BuildArgs(idx);
       case 'Token'
        cur_keys = get(h.Tokens,'Key');
        idx = ~ismember(cur_keys,Keys);
        h.Tokens = h.Tokens(idx);
   end
 
function [args_ok, Keys] = locCheckArgs(Type, varargin)

  args_ok = false;
  Keys    = {};
  
  %only 2 arguments can be passed in.
  if (nargin ~= 2)
      return;
  end

  % the first arg is the type of Key Value pair, and affects which list
  % it will get added to.
  validKeys = {'BuildArg' 'Token'};
  if ~ischar(Type) || ~any(strcmp(Type, validKeys))
      return;
  end
  
  % the next arg is the Key or list of keys
  if ~iscellstr(varargin{1})
      if ~ischar(varargin{1})
          % this is an incompatible data type
          return;
      end
      Keys = varargin(1);
  else
      Keys = varargin{1};
  end

  % remove any duplicate entries if the list is longer than 1
  if (length(Keys) > 1)

      Keys = RTW.unique(Keys);
      
      % finally, check for empty Keys.  If the Token is empty, the
      % whole entry should be removed.
      idx = ~strcmp(Keys,'');
      Keys   = Keys(idx);
  end

  % if we got here the args are OK
  args_ok  = true;

