classdef(Abstract, Hidden) AbstractList < handle
    %ABSTRACTLIST Abstract defintion for econModeler list classes
    
    %Copyright 2017 The MathWorks, Inc.
    
    properties(Access = protected)
        Session
        List
    end
    
    methods(Access = protected)
         function this = AbstractList(session)
            this.Session = session;
            this.List = [];
        end
        
        function remove(this, name)
            currentNames = get(this.List,'Name');
            idx = strcmp(name,currentNames);
            this.List(idx) = [];
        end
        
        function names = getNames(this)
            names = cell(1,length(this.List));
            for n = 1:length(this.List)
                names{n} = this.List(n).Name;
            end
        end
    end
    
    methods(Abstract, Access = {?internal.EconModeler.econModelerSession,...
            ?internal.EconModeler.AbstractList})
        add(this, s, e)
        clearAll(this);
    end
    
    methods(Access = {?internal.EconModeler.econModelerSession,...
            ?internal.EconModeler.AbstractList})
        function bool = isNameInList(this,str)
            if isempty(this.List)
                bool = false;
            else
                currentNames = this.getNames();
                bool = any(strcmp(str,currentNames));
            end
        end
        
        function item = getItem(this,identifier)
            if isempty(this.List)
                item = [];
                return;
            end
            if isnumeric(identifier)
                if isempty(this.List) || any(identifier < 1) || any(identifier > length(this.List))
                    item = [];
                    return;
                end
                item = this.List(identifier);
            else
                item = this.List(strcmp(identifier,{this.List.Name}));
            end 
        end
        
        function items = getAllItems(this)
            items = this.List;
        end
    end
end

