/*
 * @(#)MailExchangerComparator.java
 *
 * Copyright (c) 2001-2002 JScape
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * JScape. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 * the terms of the license agreement you entered into with JScape.
 */

package com.jscape.inet.dns.record;


import java.util.Comparator;


/**
 * Implements methods for sorting MailExchanger records by preference.
 */
public class MailExchangerComparator
        implements Comparator {

    /**
     * Compares preference of two (2) MailExchanger instances.
     *
     * @param obj1 a <code>MailExchanger</code>
     * @param obj2 a <code>MailExchanger</code>
     *
     * @return -1 if obj1 &lt; obj2, 1 if obj1 &gt; obj2, 0 if equal
     *
     * @see MailExchanger
     */
    public int compare(Object obj1, Object obj2) {
        if (obj1 instanceof MailExchanger && obj2 instanceof MailExchanger) {


            MailExchanger ex1 = (MailExchanger) obj1;
            MailExchanger ex2 = (MailExchanger) obj2;

            if (ex1.getPreference() < ex2.getPreference()) {
                
                /* instance lt received */
                return -1;
            } else if (ex1.getPreference() > ex2.getPreference()) {
                
                /* instance gt received */
                return 1;
            } /* instance == received */
        }
        return 0;
    }
}

