/* ======================================================================
   Parts Copyright 2006 University of Leeds, Oxford University, University of the Highlands and Islands.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

====================================================================== */

package org.bodington.server.userimport.oucsir;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.bodington.util.TextUtils;

class OUCSCourse implements Validator, Map.Entry
{
    private String code;
    private String description;
    
    public OUCSCourse(String code, String description)
    {
        this.code = code;
        this.description = description;
    }
    
    public OUCSCourse()
    {
        super();
    }
    
    /**
     * @return the code
     */
    public String getCode()
    {
        return code;
    }
    /**
     * @param code the code to set
     */
    public void setCode(String code)
    {
        if (this.code != null)
            throw new IllegalStateException("code already set");
        this.code = code;
    }
    /**
     * @return the description
     */
    public String getDescription()
    {
        return description;
    }
    /**
     * @param description the description to set
     */
    public void setDescription(String description)
    {
        if (this.description != null)
            throw new IllegalStateException("description already set");
        this.description = description;
    }
    
    public String toString()
    {
        return "Code: "+ code+ " Description: "+ description;
    }

    public String problems()
    {
        List errors = new LinkedList();
        if (code == null || code.length() < 1)
            errors.add("code cannot be empty");
        if (description == null || description.length() < 1)
            errors.add("description cannot be empty");
        return (errors.size() > 0) ? TextUtils.join(errors.iterator(), "\n") : null;
    }

    public Object getKey()
    {
        return getCode();
    }

    public Object getValue()
    {
        return this;
    }

    public Object setValue(Object value)
    {
        throw new UnsupportedOperationException();
    }
}
