/* ======================================================================
   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 OUCSCollege implements Validator, Map.Entry
{

    private String code;
    private String nickname;
    private String name;
    
    public OUCSCollege(String code, String nickname, String name)
    {
        this.code = code;
        this.nickname = nickname;
        this.name = name;
    }
    
    public OUCSCollege()
    {
        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 name
     */
    public String getName()
    {
        return name;
    }
    /**
     * @param name the name to set
     */
    public void setName(String name)
    {
        if (this.name != null)
            throw new IllegalStateException("name already set");
        this.name = name;
    }
    /**
     * @return the nickname
     */
    public String getNickname()
    {
        return nickname;
    }
    /**
     * @param nickname the nickname to set
     */
    public void setNickname(String nickname)
    {
        if (this.nickname != null)
            throw new IllegalStateException("nickname already set");
        this.nickname = nickname;
    }
     
    public String toString()
    {
        return "Code: "+ code+ " Nickname: "+ nickname+ " Name "+ name;
    }

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

    public Object getKey()
    {
        return code;
    }

    public Object getValue()
    {
        return this;
    }

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