package de.ivu.elect.jee.security;

import java.io.Serializable;

/**
 *  on 07.02.2017.
 */
public class IpHostname implements Serializable{

  public static final IpHostname UNBEKANNT = new IpHostname(null, null, null, null);

  private final String ip;
  private final String hostname;

  private final String ipRemoteAddr;
  private final String hostnameRemoteAddr;

  public IpHostname(String ip, String hostname, String ipRemoteAddr, String hostnameRemoteAddr) {
    this.ip = ip;
    this.hostname = hostname;
    this.ipRemoteAddr = ipRemoteAddr;
    this.hostnameRemoteAddr = hostnameRemoteAddr;
  }

  public String getIp() {
    return ip;
  }

  public String getHostname() {
    return hostname;
  }

  public String getIpRemoteAddr() {
    return ipRemoteAddr;
  }

  public String getHostnameRemoteAddr() {
    return hostnameRemoteAddr;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    IpHostname that = (IpHostname) o;

    if (ip != null ? !ip.equals(that.ip) : that.ip != null) return false;
    if (hostname != null ? !hostname.equals(that.hostname) : that.hostname != null) return false;
    if (ipRemoteAddr != null ? !ipRemoteAddr.equals(that.ipRemoteAddr) : that.ipRemoteAddr != null) return false;
    return hostnameRemoteAddr != null ? hostnameRemoteAddr.equals(that.hostnameRemoteAddr) : that.hostnameRemoteAddr == null;
  }

  @Override
  public int hashCode() {
    int result = ip != null ? ip.hashCode() : 0;
    result = 31 * result + (hostname != null ? hostname.hashCode() : 0);
    result = 31 * result + (ipRemoteAddr != null ? ipRemoteAddr.hashCode() : 0);
    result = 31 * result + (hostnameRemoteAddr != null ? hostnameRemoteAddr.hashCode() : 0);
    return result;
  }

  @Override
  public String toString() {
    return "IpHostname{" +
        "ip='" + ip + '\'' +
        ", hostname='" + hostname + '\'' +
        ", ipRemoteAddr='" + ipRemoteAddr + '\'' +
        ", hostnameRemoteAddr='" + hostnameRemoteAddr + '\'' +
        '}';
  }
}

