code: private static URI createBare(final URI link) {
          final URI uri;
          if (link.getRawQuery() == null && link.getRawFragment() == null) {
              uri = link;
          } else {
              final String href = link.toString();
              final int idx;
              if (link.getRawQuery() == null) {
                  idx = href.indexOf('#');
              } else {
                  idx = href.indexOf('?');
              }
              uri = URI.create(href.substring(0, idx));
          }
          return uri;
      }
docs: Remove query and fragment parts from the provided URI and
  return the resulting URI.
  @param link The link from which parts need to be removed.
  @return The URI corresponding to the same provided URI but without
  query and fragment parts.