/*
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (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.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 *
 * The Original Code is Protege-2000.
 *
 * The Initial Developer of the Original Code is Stanford University. Portions
 * created by Stanford University are Copyright (C) 2007.  All Rights Reserved.
 *
 * Protege was developed by Stanford Medical Informatics
 * (http://www.smi.stanford.edu) at the Stanford University School of Medicine
 * with support from the National Library of Medicine, the National Science
 * Foundation, and the Defense Advanced Research Projects Agency.  Current
 * information about Protege can be obtained at http://protege.stanford.edu.
 *
 */

package edu.stanford.smi.protege.ui;

import java.util.*;

import edu.stanford.smi.protege.model.*;
import edu.stanford.smi.protege.util.*;

/**
 * A comparator for frames that only does a case insensitive comparison of the frame names.
 *
 * @author    Ray Fergerson <fergerson@smi.stanford.edu>
 */
public class FrameNameComparator implements Comparator {

    public int compare(Object o1, Object o2) {
        int result;
        if (o1 instanceof Instance && o2 instanceof Instance) {
            String t1 = ((Frame) o1).getName();
            String t2 = ((Frame) o2).getName();
            // frame names should never be null unless the frame has been deleted.
            if (t1 == null) {
                result = (t2 == null) ? 0 : +1;
            } else if (t2 == null) {
                result = -1;
            } else {
                result = t1.compareToIgnoreCase(t2);
            }
        } else {
            Log.getLogger().warning("Invalid types: " + o1 + " " + o2);
            result = 0;
        }
        return result;
    }
}
