package com.vsct.dt.strowgr.admin.core.configuration;

import java.util.HashMap;
import java.util.Map;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.vsct.dt.strowgr.admin.Preconditions.checkStringNotEmpty;

public class IncomingEntryPointBackendServer {

    private final String id;
    private final String hostname;
    private final String ip;
    private final String port;

    private final HashMap<String, String> context;

    public IncomingEntryPointBackendServer(String id, String hostname, String ip, String port, Map<String, String> context) {
        this.id = checkStringNotEmpty(id, "Backend should have an id");
        this.hostname = checkStringNotEmpty(hostname, "Backend should have a hostname");
        this.ip = checkStringNotEmpty(ip, "Backend should have an ip");
        this.port = checkStringNotEmpty(port, "Backend should have a port");
        this.context = new HashMap<>(checkNotNull(context));
    }

    public String getHostname() {
        return hostname;
    }

    public String getId() {
        return id;
    }

    public String getIp() {
        return ip;
    }

    public String getPort() {
        return port;
    }

    public Map<String, String> getContext() {
        return new HashMap<>(context);
    }

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

        IncomingEntryPointBackendServer that = (IncomingEntryPointBackendServer) o;

        if (id != null ? !id.equals(that.id) : that.id != null) return false;
        if (hostname != null ? !hostname.equals(that.hostname) : that.hostname != null) return false;
        if (ip != null ? !ip.equals(that.ip) : that.ip != null) return false;
        if (port != null ? !port.equals(that.port) : that.port != null) return false;
        if (context != null ? !context.equals(that.context) : that.context != null) return false;

        return true;
    }

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

    @Override
    public String toString() {
        return "IncommingEntryPointBackendServer{" +
                "id='" + id + '\'' +
                ", hostname='" + hostname + '\'' +
                ", ip='" + ip + '\'' +
                ", port='" + port + '\'' +
                ", context=" + context +
                '}';
    }
}

@@ -397,22 +397,23 @@
 e final 
-String
+Integer
  port;%0A%0A
@@ -529,35 +529,19 @@
 ing 
-hostname, String ip, String
+ip, Integer
  por
@@ -659,24 +659,18 @@
    this.
-hostname
+ip
  = check
@@ -684,24 +684,18 @@
 otEmpty(
-hostname
+ip
 , %22Backe
@@ -710,25 +710,20 @@
 d have a
- hostname
+n ip
 %22);%0A    
@@ -730,70 +730,85 @@
     
-this.ip = checkStringNotEmpty(ip, %22Backend should have an ip%22)
+// TODO remove unnecessary hostname attribute%0A        this.hostname = this.ip
 ;%0A  
@@ -830,30 +830,23 @@
  = check
-StringNotEmpty
+NotNull
 (port, %22
@@ -1124,30 +1124,31 @@
 %0A    public 
-String
+Integer
  getPort() %7B
@@ -1861,20 +1861,23 @@
         
-if (
+return 
 context 
@@ -1886,17 +1886,16 @@
  null ? 
-!
 context.
@@ -1934,52 +1934,17 @@
 ext 
-!
+=
 = null
-) return false;%0A%0A        return true
 ;
+%0A
 %0A   

Remove hostname from backend. only ip address is required