gt:             if (recipientParamStart == -1) {
context: /*
   * To change this license header, choose License Headers in Project Properties.
   * To change this template file, choose Tools | Templates
   * and open the template in the editor.
   */
  package org.geb.core;
  
  import java.net.URISyntaxException;
  import java.util.Objects;
  import java.util.logging.Logger;
  
  /**
   *
   * @author irakli
   */
  public class EndpointAddress {
  
      private static final Logger LOG = Logger.getLogger(EndpointAddress.class.getName());
  
      public static EndpointAddress createInstance(final String address)
              throws URISyntaxException {
          Objects.requireNonNull(address);
  
          return new AddressDecoder(address).decode();
      }
  
      private final String protocol;
      private final String protocolAddress;
      private final String recipient;
      private final String recipientParam;
  
      public EndpointAddress(final String protocol,
                             final String protocolAddress,
                             final String recipient,
                             final String recipientParam) {
          Objects.requireNonNull(protocol);
          Objects.requireNonNull(protocolAddress);
  
          this.protocol = protocol;
          this.protocolAddress = protocolAddress;
          this.recipient = recipient;
          this.recipientParam = recipientParam;
      }
  
      public String getProtocol() {
          return protocol;
      }
  
      public String getProtocolAddress() {
          return protocolAddress;
      }
  
      public String getRecipient() {
          return recipient;
      }
  
      public String getRecipientParam() {
          return recipientParam;
      }
  
      public String toURI() {
          final StringBuilder builder = new StringBuilder(1024);
          builder.append(protocol);
          builder.append("://");
          builder.append(protocolAddress);
  
          if (recipient != null) {
              builder.append("/");
              builder.append(recipient);
  
              if (recipientParam != null) {
                  builder.append("/");
                  builder.append(recipientParam);
  
              }
          }
  
          return builder.toString();
      }
  
      public String toURN() {
          final StringBuilder builder = new StringBuilder(1024);
          builder.append("urn:");
          builder.append(protocol);
          builder.append(":");
          builder.append(protocolAddress);
  
          if (recipient != null) {
              builder.append("?");
              builder.append(recipient);
  
              if (recipientParam != null) {
                  builder.append("/");
                  builder.append(recipientParam);
  
              }
          }
  
          return builder.toString();
      }
  
      @Override
      public int hashCode() {
          int hash = 5;
          hash = 37 * hash + Objects.hashCode(this.protocol);
          hash = 37 * hash + Objects.hashCode(this.protocolAddress);
          hash = 37 * hash + Objects.hashCode(this.recipient);
          hash = 37 * hash + Objects.hashCode(this.recipientParam);
          return hash;
      }
  
      @Override
      public boolean equals(Object obj) {
          if (obj == null) {
              return false;
          }
          if (getClass() != obj.getClass()) {
              return false;
          }
          final EndpointAddress other = (EndpointAddress) obj;
          if (!Objects.equals(this.protocol,
                              other.protocol)) {
              return false;
          }
          if (!Objects.equals(this.protocolAddress,
                              other.protocolAddress)) {
              return false;
          }
          if (!Objects.equals(this.recipient,
                              other.recipient)) {
              return false;
          }
          if (!Objects.equals(this.recipientParam,
                              other.recipientParam)) {
              return false;
          }
          return true;
      }
  
      @Override
      public String toString() {
          return "EndpointAddress{" + "protocol=" + protocol + ", protocolAddress=" + protocolAddress + ", recipient=" + recipient + ", recipientParam=" + recipientParam + '}';
      }
  
      private static class AddressDecoder {
  
          private final String address;
          private int protocolStart;
          private int protocolEnd;
          private int protocolAddressStart;
          private int protocolAddressEnd;
          private int recipientStart;
          private int recipientEnd;
          private int recipientParamStart;
  
          AddressDecoder(final String address) {
              Objects.requireNonNull(address);
  
              this.address = address;
          }
  
          public EndpointAddress decode()
                  throws URISyntaxException {
              if (address.startsWith("urn:")) {
                  protocolStart = "urn:".length();
  
                  return decodeFromURN();
              } else {
                  protocolStart = 0;
  
                  return decodeFromURI();
              }
          }
  
          private EndpointAddress decodeFromURN()
                  throws URISyntaxException {
              final String protocol = findProtocol();
              final String protocolAddress = findProtocolAddressInURN();
              final String recipient = findRecipient();
              final String recipientParam = findRecipientParam();
  
              return new EndpointAddress(protocol,
                                         protocolAddress,
                                         recipient,
                                         recipientParam);
          }
  
          private EndpointAddress decodeFromURI()
                  throws URISyntaxException {
              final String protocol = findProtocol();
              final String protocolAddress = findProtocolAddressInURI();
              final String recipient = findRecipient();
              final String recipientParam = findRecipientParam();
  
              return new EndpointAddress(protocol,
                                         protocolAddress,
                                         recipient,
                                         recipientParam);
          }
  
          private String findProtocol()
                  throws URISyntaxException {
              protocolEnd = address.indexOf("://",
                                            protocolStart);
              protocolAddressStart = protocolEnd + 3;
              if (protocolEnd == -1) {
                  protocolEnd = address.indexOf(':',
                                                protocolStart);
                  protocolAddressStart = protocolEnd + 1;
              }
  
              if (protocolEnd == -1) {
                  throw new URISyntaxException(address,
                                               "No ':' in address");
              }
  
              return address.substring(protocolStart,
                                       protocolEnd);
          }
  
          private String findProtocolAddressInURI()
                  throws URISyntaxException {
              protocolAddressEnd = address.indexOf('/',
                                                   protocolAddressStart);
              if (protocolAddressEnd == -1) {
                  recipientStart = -1;
  
                  return address.substring(protocolAddressStart);
              } else {
                  recipientStart = protocolAddressEnd + 1;
  
                  return address.substring(protocolAddressStart,
                                           protocolAddressEnd);
              }
          }
  
          private String findProtocolAddressInURN()
                  throws URISyntaxException {
              protocolAddressEnd = address.indexOf('?',
                                                   protocolAddressStart);
              if (protocolAddressEnd == -1) {
                  recipientStart = -1;
  
                  return address.substring(protocolAddressStart);
              } else {
                  recipientStart = protocolAddressEnd + 1;
  
                  return address.substring(protocolAddressStart,
                                           protocolAddressEnd);
              }
          }
  
          private String findRecipient() {
              if (recipientStart == -1) {
                  return null;
              }
  
              recipientEnd = address.indexOf('/',
                                             recipientStart);
              if (recipientEnd == -1) {
                  recipientParamStart = -1;
  
                  return address.substring(recipientStart);
              } else {
                  recipientParamStart = recipientEnd + 1;
  
                  return address.substring(recipientStart,
                                           recipientEnd);
              }
          }
  
          private String findRecipientParam() {
  