public boolean equals(Object o) {
   if (o == this) {
     return true;
   }
   if (!(o instanceof DiscoveryDescription)) {
     return false;
   }
   DiscoveryDescription descriptor = (DiscoveryDescription) o;
   return descriptor.getInstanceName().equals(getInstanceName());
 }
  public int compareTo(DiscoveryDescription sd) throws ClassCastException {
    if (sd == null) {
      throw new NullPointerException();
    }
    if (sd == this) {
      return 0;
    }

    return getInstanceName().compareTo(sd.getInstanceName());
  }
  /**
   * When we get a packet that should contain the string-based properties included in a
   * DiscoveryDescription object, we make sure that it follows the same format used in the toString
   * method.
   *
   * @param encodedInstanceName Instance name for the server that is URL encoded.
   * @param addressAsString The IP address of the server.
   * @param clientPortAsString The client port for the server.
   * @param nodePortAsString The node port for the server.
   * @return A new DiscoveryDescription object that represents the data from the given strings.
   * @see DiscoveryDescription#toString()
   */
  public static DiscoveryDescription parse(
      String encodedInstanceName,
      String addressAsString,
      String clientPortAsString,
      String nodePortAsString) {

    DiscoveryDescription descriptor = new DiscoveryDescription();

    // Put the instance name
    try {
      String name = URLDecoder.decode(encodedInstanceName, "UTF-8");
      if (name == null || name.length() == 0) {
        return null;
      }
      descriptor.setInstanceName(name);
    } catch (UnsupportedEncodingException uee) {
      uee.printStackTrace();
      return null;
    }

    // Put the address
    descriptor.setAddress(addressAsString);

    // Put the client and node ports
    try {
      int p = Integer.parseInt(clientPortAsString);
      descriptor.setClientPort(p);
      p = Integer.parseInt(nodePortAsString);
      descriptor.setNodePort(p);
    } catch (NumberFormatException nfe) {
      System.err.println("Unexpected exception: " + nfe);
      nfe.printStackTrace();
      return null;
    }

    return descriptor;
  }