/**
 * MediaSniper 3.0 (2008-08-02)
 * Copyright 2007 - 2008 Zach Scrivena
 * zachscrivena@gmail.com
 * http://mediasniper.sourceforge.net/
 *
 * Simple program for downloading media files from popular websites.
 *
 * 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 as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * 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 org.freeshell.zs.mediasniper;


/**
 * Represent a table cell that contains a progress bar.
 */
class TableProgressCell
        implements Comparable<TableProgressCell>
{
    /** corresponding Download object */
    final Download download;

    /** progress text */
    String text = "";

    /** progress percent */
    int percent = -1;


    /**
    * Constructor.
    *
    * @param ac
    *      corresponding Download object
    */
    TableProgressCell(
            final Download download)
    {
        this.download = download;
    }


    /**
    * Compare this table cell content to the specified table cell content,
    * by value first, and then by text.
    */
    public int compareTo(
            TableProgressCell o)
    {
        if (percent == o.percent)
        {
            return text.compareToIgnoreCase(o.text);
        }
        else if (percent < o.percent)
        {
            return -1;
        }
        else
        {
            return 1;
        }
    }


    /**
    * Check for equality between this table cell content and the
    * specified table cell content, using only the value and text fields.
    */
    @Override
    public boolean equals(
            Object o)
    {
        if (o instanceof TableProgressCell)
        {
            final TableProgressCell c = (TableProgressCell) o;
            return (percent == c.percent) && text.equals(c.text);
        }
        else
        {
            return false;
        }
    }


    /**
    * Generate a hash code for this table cell content, using the value and text fields.
    */
    @Override
    public
    int hashCode()
    {
        int hash = 7;
        hash = 83 * hash + (text != null ? text.hashCode() : 0);
        hash = 83 * hash + percent;
        return hash;
    }
}