/**
 * GmailAssistant 1.1 (2008-03-16)
 * Copyright 2008 Zach Scrivena
 * zachscrivena@gmail.com
 * http://gmailassistant.sourceforge.net/
 *
 * Notifier for multiple Gmail accounts.
 *
 * TERMS AND CONDITIONS:
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package gmailassistant;


/**
 * Identifier for a mail.
 */
class MailId
{
    /** name of the IMAP folder containing this mail message */
    final String imapFolderName;

    /** IMAP UID for this mail message (unique within the folder) */
    final long imapMessageUid;


    /**
    * Constructor.
    *
    * @param imapFolderName
    *      name of the IMAP folder containing this mail message
    * @param imapMessageUid
    *      IMAP UID for this mail message (unique within the folder)
    */
    MailId(
            final String imapFolderName,
            final long imapMessageUid)
    {
        this.imapFolderName = imapFolderName;
        this.imapMessageUid = imapMessageUid;
    }


    /**
    * Check for equality between this mail ID and the specified mail ID.
    */
    @Override
    public boolean equals(
            Object obj)
    {
        if (obj instanceof MailId)
        {
            final MailId o = (MailId) obj;
            return (this.imapFolderName.equals(o.imapFolderName) &&
                    (this.imapMessageUid == o.imapMessageUid));
        }
        else
        {
            return false;
        }
    }


    /**
    * Generate a hash code for this mail ID.
    */
    @Override
    public int hashCode()
    {
        int hash = 7;
        hash = 61 * hash + (this.imapFolderName != null ? this.imapFolderName.hashCode() : 0);
        hash = 61 * hash + (int) (this.imapMessageUid ^ (this.imapMessageUid >>> 32));
        return hash;
    }
}