IMHandle.java :  » Google-tech » objectify-appengine » com » google » appengine » api » datastore » Java Open Source

Java Open Source » Google tech » objectify appengine 
objectify appengine » com » google » appengine » api » datastore » IMHandle.java
package com.google.appengine.api.datastore;

import java.io.Serializable;

/**
 * GWT emulation class.
 */
@SuppressWarnings("serial")
public class IMHandle implements Serializable, Comparable<IMHandle>
{
  public static enum Scheme
  {
    sip, unknown, xmpp
  }

  private final String protocol;
  private final String address;

  public IMHandle(Scheme scheme, String address)
  {
    if (scheme == null)
    {
      throw new NullPointerException("scheme must not be null");
    }
    else
    {
      validateAddress(address);
      protocol = scheme.name();
      this.address = address;
    }
  }

  @SuppressWarnings("unused")
  private IMHandle()
  {
    protocol = null;
    address = null;
  }

  private static void validateAddress(String address)
  {
    if (address == null)
      throw new NullPointerException("address must not be null");
  }

  public String getProtocol()
  {
    return protocol;
  }

  public String getAddress()
  {
    return address;
  }

  public boolean equals(Object o)
  {
    if (this == o)
      return true;
    if (o == null || getClass() != o.getClass())
      return false;
    IMHandle imHandle = (IMHandle) o;
    if (!address.equals(imHandle.address))
      return false;
    return protocol.equals(imHandle.protocol);
  }

  public int hashCode()
  {
    int result = protocol.hashCode();
    result = 31 * result + address.hashCode();
    return result;
  }

  public int compareTo(IMHandle o)
  {
    return toString().compareTo(o.toString());
  }

  public String toString()
  {
    return protocol + " " + address;
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.