/*
 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for additional information regarding
 * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the License. You may obtain a
 * copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package org.apache.geode.distributed.internal.membership.gms.membership;

import java.net.InetSocketAddress;

import org.apache.commons.validator.routines.InetAddressValidator;

public class HostAddress {
  private InetSocketAddress socketInetAddress;
  private String hostname;
  private int port;
  private boolean isIpString;

  public HostAddress(InetSocketAddress loc, String locStr) {
    this.socketInetAddress = loc;
    this.hostname = locStr;
    this.port = loc.getPort();
    this.isIpString = InetAddressValidator.getInstance().isValid(locStr);
  }

  public boolean isIpString() {
    return isIpString;
  }

  /**
   * if host is ipString then it will return the cached InetSocketAddress Otherwise it will create
   * the new instance of InetSocketAddress
   * 
   * @return
   */
  public InetSocketAddress getSocketInetAddress() {
    if (this.isIpString) {
      return this.socketInetAddress;
    } else {
      InetSocketAddress isa = new InetSocketAddress(hostname, this.socketInetAddress.getPort());
      return isa;
    }
  }



  public String getHostName() {
    return hostname;
  }


  public int getPort() {
    return port;
  }

  /**
   * If component has retry logic then use this method to get the InetSocketAddress address
   * AutoConnectionSourceImpl for client has retry logic; This way client will not make DNS query
   * each time
   * 
   * @return InetSocketAddress
   */
  public InetSocketAddress getSocketInetAddressNoLookup() {
    return this.socketInetAddress;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + (isIpString ? 1231 : 1237);
    result = prime * result + ((socketInetAddress == null) ? 0 : socketInetAddress.hashCode());
    result = prime * result + ((hostname == null) ? 0 : hostname.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    HostAddress other = (HostAddress) obj;
    if (isIpString != other.isIpString)
      return false;
    if (socketInetAddress == null) {
      if (other.socketInetAddress != null)
        return false;
    } else if (!socketInetAddress.equals(other.socketInetAddress))
      return false;
    if (hostname == null) {
      if (other.hostname != null)
        return false;
    } else if (!hostname.equals(other.hostname))
      return false;
    return true;
  }

  @Override
  public String toString() {
    return "LocatorAddress [locatorSocketInetAddress=" + socketInetAddress + ", lochostname="
        + hostname + ", isIpString=" + isIpString + "]";
  }



}

@@ -783,17 +783,16 @@
 se.%0A */%0A
-%0A
 package 
@@ -988,16 +988,17 @@
 dress %7B%0A
+%0A
   privat
@@ -999,16 +999,22 @@
 private 
+final 
 InetSock
@@ -1052,16 +1052,22 @@
 private 
+final 
 String h
@@ -1085,16 +1085,22 @@
 private 
+final 
 int port
@@ -1111,16 +1111,22 @@
 private 
+final 
 boolean 
@@ -1583,27 +1583,8 @@
 ess%0A
-   * %0A   * @return%0A
    *
@@ -1724,31 +1724,14 @@
     
-InetSocketAddress isa =
+return
  new
@@ -1798,26 +1798,8 @@
 ));%0A
-      return isa;%0A
     
@@ -1805,18 +1805,16 @@
  %7D%0A  %7D%0A%0A
-%0A%0A
   public
@@ -1863,17 +1863,16 @@
 e;%0A  %7D%0A%0A
-%0A
   public
@@ -2306,22 +2306,16 @@
 ) %7B%0A    
-final 
 int prim
@@ -2430,17 +2430,16 @@
 esult + 
-(
 (socketI
@@ -2452,25 +2452,24 @@
 ress == null
-)
  ? 0 : socke
@@ -2524,17 +2524,16 @@
 esult + 
-(
 (hostnam
@@ -2541,17 +2541,16 @@
  == null
-)
  ? 0 : h
@@ -3323,16 +3323,9 @@
 ss %5B
-locatorS
+s
 ocke
@@ -3364,19 +3364,16 @@
 ss + %22, 
-loc
 hostname
@@ -3374,24 +3374,16 @@
 stname=%22
-%0A       
  + hostn
@@ -3385,16 +3385,24 @@
 hostname
+%0A       
  + %22, is
@@ -3437,12 +3437,10 @@
 %22;%0A  %7D%0A%0A
-%0A%0A
 %7D%0A

remove empty @return javadoc