remove URL mutator

This commit is contained in:
Jörg Prante 2024-01-04 22:15:07 +01:00
parent c45bbfca53
commit d6ac3e267d
6 changed files with 13 additions and 20 deletions

View file

@ -1,3 +1,3 @@
group = org.xbib group = org.xbib
name = net name = net
version = 4.0.4 version = 4.1.0

View file

@ -41,7 +41,7 @@ import java.util.Objects;
* URL url = URL.http().resolveFromHost("google.com").build(); * URL url = URL.http().resolveFromHost("google.com").build();
* *
*/ */
public class URL implements Comparable<URL> { public final class URL implements Comparable<URL> {
static final URL NULL_URL = URL.builder().build(); static final URL NULL_URL = URL.builder().build();
@ -257,10 +257,6 @@ public class URL implements Comparable<URL> {
} }
} }
public URLBuilder mutator() {
return builder;
}
public URLBuilder newBuilder() { public URLBuilder newBuilder() {
return new URLBuilder(); return new URLBuilder();
} }

View file

@ -301,11 +301,11 @@ public class URLBuilder {
* *
* @return a string * @return a string
*/ */
String toUrlString() { public String toUrlString() {
return build().toExternalForm(); return build().toExternalForm();
} }
void validateSchemeCharacters(String scheme) { private void validateSchemeCharacters(String scheme) {
boolean valid; boolean valid;
for (int i = 0; i < scheme.length(); i++) { for (int i = 0; i < scheme.length(); i++) {
char c = scheme.charAt(i); char c = scheme.charAt(i);

View file

@ -106,7 +106,7 @@ public class ParameterTest {
} }
@Test @Test
public void testMutatorQueryParameters() { public void testQueryParametersWithUrlBuilder() {
URL url = URL.from("http://localhost"); URL url = URL.from("http://localhost");
String requestPath = "/path"; String requestPath = "/path";
Map<String, Object> map = Map.of( Map<String, Object> map = Map.of(
@ -120,10 +120,9 @@ public class ParameterTest {
.enableQueryString(true) .enableQueryString(true)
.add(map) .add(map)
.build(); .build();
URLBuilder mutator = url.mutator(); URLBuilder builder = URL.builder(url).path(requestPath);
mutator.path(requestPath); httpParameter.forEach(e -> builder.queryParam(e.getKey(), e.getValue()));
httpParameter.forEach(e -> mutator.queryParam(e.getKey(), e.getValue())); url = builder.build();
url = mutator.build();
assertEquals("http://localhost/path?operation=searchRetrieve&query=iss%20%3D%2000280836&recordSchema=MARC21plus-1-xml&version=1.1", assertEquals("http://localhost/path?operation=searchRetrieve&query=iss%20%3D%2000280836&recordSchema=MARC21plus-1-xml&version=1.1",
url.toExternalForm()); url.toExternalForm());
} }

View file

@ -267,8 +267,8 @@ class URLBuilderTest {
} }
@Test @Test
void testMutator() { void testUrlBuilder() {
URLBuilder builder = URL.from("http://google.com:8008/foobar").mutator(); URLBuilder builder = URL.builder(URL.from("http://google.com:8008/foobar"));
builder.queryParam("a%", "b%"); builder.queryParam("a%", "b%");
builder.queryParam("c", " d "); builder.queryParam("c", " d ");
builder.scheme("https"); builder.scheme("https");
@ -278,11 +278,9 @@ class URLBuilderTest {
assertEquals("https://google.com:8008/foobar?a%=b%&c= d ", url.toString()); assertEquals("https://google.com:8008/foobar?a%=b%&c= d ", url.toString());
// test inheritance of params added by mutator // test inheritance of params added by mutator
URL url1 = URL.from("http://example.com"); URL url1 = URL.builder(URL.from("http://example.com")).queryParam("a", "b").build();
url1.mutator().queryParams.add("a", "b");
assertEquals("http://example.com?a=b", url1.toString()); assertEquals("http://example.com?a=b", url1.toString());
URL url2 = URL.from(url1); // copy URL url2 = URL.builder(url1).queryParam("c", "d").build();
url2.mutator().queryParams.add("c", "d");
assertEquals("http://example.com?a=b&c=d", url2.toString()); assertEquals("http://example.com?a=b&c=d", url2.toString());
} }

View file

@ -44,7 +44,7 @@ class URLResolverTest {
String pathSpec = "foobar/"; String pathSpec = "foobar/";
String index = "index.html"; String index = "index.html";
String queryString = "a=b"; String queryString = "a=b";
URL url = base.resolve(pathSpec).resolve(index).mutator().query(queryString).build().normalize(); URL url = URL.builder(base.resolve(pathSpec).resolve(index)).query(queryString).build().normalize();
assertEquals("http://example:8080/foobar/index.html?a=b", url.toString()); assertEquals("http://example:8080/foobar/index.html?a=b", url.toString());
} }