function map = LabelMap(varargin)
%LabelMap(labelCellList,valueCellList) maps Label to Classvalues suitable for
%SVM

switch nargin
    case 2
        condition = varargin{2};
        label     = varargin{1};
        svmvalue  = 'auto';
    case 3
        condition = varargin{2};
        label     = varargin{1};
        svmvalue  = varargin{3};
    otherwise
        error('LabelMap:Constructor:wrongArgs','Wrong Arguments!');
end


%         if ~ (iscell(label) && iscell(condition))
%             error('LabelMap:Constructor:argsNoCell','Arguments have to be CellArrays. Vectors not yet supported. sorry.');
%         end
%         if(any(size(label) ~= size(value)))
%             error('LabelMap:Constructor:sizeDontMatch','Label List and Value List must be the same size!');
%         end

        map.ConditionToLabel = java.util.HashMap;
        map.LabelToCondition = java.util.HashMap;
        map.LabelToValue     = java.util.HashMap;
        map.ValueToLabel     = java.util.HashMap;
        
        
        % condition: {[a,b,c],[d,e,f],...}
        
        for conditionGroupCellID = 1:numel(condition) % cells
            conditionGroupVector = condition{conditionGroupCellID};

            for conditionID = 1:size(conditionGroupVector,2)
               conditionLabel = cell2mat(label(conditionGroupCellID));
               
               map.ConditionToLabel.put(conditionGroupVector(conditionID),conditionLabel);
               if ~map.LabelToCondition.containsKey(conditionLabel)
                   conditionset = java.util.HashSet;
                   map.LabelToCondition.put(conditionLabel,conditionset);
               end
              map.LabelToCondition.get(conditionLabel).add(conditionGroupVector(conditionID));
           end
        end
        
        for labelid = 1:numel(label)
            if map.LabelToValue.containsKey(label)
                continue;
            end
            
            if ~iscell(svmvalue) || strcmp(cell2mat(svmvalue),'auto')
               map.LabelToValue.put(cell2mat(label(labelid)),labelid);
               map.ValueToLabel.put(labelid,cell2mat(label(labelid)));
            else
               map.LabelToValue.put(cell2mat(label(labelid)),cell2mat(svmvalue(labelid)));
               map.ValueToLabel.put(cell2mat(svmvalue(labelid)),cell2mat(label(labelid)));
            end    
        end

        

%         for i = 1:max(size(label)) % cell array is 1:x or x:1, indexing is same
%             map.labelToValue.put(label{i},value{i});
%             map.valueToLabel.put(value{i},label{i});
%         end

        map = class(map,'LabelMap');


end