/*****************************************************************************
 *                                                                           *
 *         Licensed Materials - Property of IBM                              *
 *                                                                           *
 *         "Restricted Materials of IBM"                                     *
 *                                                                           *
 *         5799-QRY                                                          *
 *                                                                           *
 *         (C) Copyright IBM Corp. 1998                                      *
 *                                                                           *
 *****************************************************************************/
package com.ibm.devtools.SIPNoTE;

/**
 * This class represents a single host to which the user is connected.
 * The host is made up of the machinename/address and the port number. </p>
 *
 * @author Bill Nagy
 * @version 1.0
 */
public class HostRecord
{
  String hostname;
  int port;

  /**
   * Constructs a hostrecord given a hostname and port.
   *
   * @param hostname New hostname for this record.
   * @param hostname New port for this record.
   */
  public HostRecord(String hostname, int port)
  {
    this.hostname = hostname;
    this.port = port;
  }

  /**
   * Returns the hostrecord as a string of the form hostname:port.
   *
   * @return String representation of this host entry.
   */
  public String toHostRecordString()
  {
    if (port != 0)
      return new String(hostname+":"+port);
    else
      return new String(hostname);
  }

  /**
   * Returns the hostname contained within the record.
   *
   * @return Hostname portion of this record.
   */
  public String getHostname()
  {
    return hostname;
  }
  
  /**
   * Returns the port contained within the record.
   *
   * @return Port number associated with this record.
   */
  public int getPort()
  {
    return port;
  }

  /**
   * Sets the hostname of the record.
   *
   * @param hostname New hostname for this record.
   */
  public void setHostname(String hostname)
  {
    this.hostname = hostname;
  }

  /**
   * Sets the port of the record.
   *
   * @param port New port for this record.
   */
  public void setPort(int port)
  {
    this.port = port;
  }

  /**
   * Overrides the standard equals method, so that we can compare
   * two hostrecords to see if they are equivalent.  One hostrecord
   * is equivalent to another if both the names and the ports match.
   *
   * @param arg Object to compare to.
   * @return Boolean representing whether or not the comparison was true.
   */
  public boolean equals(Object arg)
  {
    if ((arg != null) && (arg instanceof HostRecord))
      {
	HostRecord comparetorec = (HostRecord)arg;
	
	return ((this.hostname.equals(comparetorec.hostname))
	    && (this.port == comparetorec.port));
      }
    else
      return false;
  }
}
