/** * Replaces the requirements with those of the supplied URI. * * @param uri the URI. * @return {@code this}. */ @NonNull public URIRequirementBuilder withUri(@CheckForNull String uri) { if (uri != null) { try { URI u = new URI(uri); withScheme(u.getScheme()); withHostnamePort(u.getHost(), u.getPort()); withPath(u.getRawPath()); } catch (URISyntaxException e) { withoutScheme().withoutHostname().withoutHostnamePort(); } } return this; }
/** * Replaces the requirements with those of the supplied URI. * * @param uri the URI. * @return {@code this}. */ @NonNull public URIRequirementBuilder withUri(@CheckForNull String uri) { if (uri != null) { try { URI u = new URI(uri); withScheme(u.getScheme()); withHostnamePort(u.getHost(), u.getPort()); withPath(u.getRawPath()); } catch (URISyntaxException e) { withoutScheme().withoutHostname().withoutHostnamePort(); } } return this; }
/** * Replace any hostname or hostname:port requirements with the supplied hostname and port. * * @param hostname the hostname to use as a requirement or (@code null} to not add any requirement * @param port the port or {@code -1} to not add {@link HostnamePortRequirement}s * @return {@code this}. */ @NonNull public URIRequirementBuilder withHostnamePort(@CheckForNull String hostname, int port) { withoutHostname(); withoutHostnamePort(); if (hostname != null) { requirements.add(new HostnameRequirement(hostname)); if (port != -1) { requirements.add(new HostnamePortRequirement(hostname, port)); } } return this; }
/** * Replace any hostname or hostname:port requirements with the supplied hostname and port. * * @param hostname the hostname to use as a requirement or (@code null} to not add any requirement * @param port the port or {@code -1} to not add {@link HostnamePortRequirement}s * @return {@code this}. */ @NonNull public URIRequirementBuilder withHostnamePort(@CheckForNull String hostname, int port) { withoutHostname(); withoutHostnamePort(); if (hostname != null) { requirements.add(new HostnameRequirement(hostname)); if (port != -1) { requirements.add(new HostnamePortRequirement(hostname, port)); } } return this; }