From d6ac3e267d7ac998fa347aa1eb79330fb5c1578b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Prante?= Date: Thu, 4 Jan 2024 22:15:07 +0100 Subject: [PATCH] remove URL mutator --- gradle.properties | 2 +- net/src/main/java/org/xbib/net/URL.java | 6 +----- net/src/main/java/org/xbib/net/URLBuilder.java | 4 ++-- net/src/test/java/org/xbib/net/ParameterTest.java | 9 ++++----- net/src/test/java/org/xbib/net/URLBuilderTest.java | 10 ++++------ net/src/test/java/org/xbib/net/URLResolverTest.java | 2 +- 6 files changed, 13 insertions(+), 20 deletions(-) diff --git a/gradle.properties b/gradle.properties index 934b51f..4f55d09 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ group = org.xbib name = net -version = 4.0.4 +version = 4.1.0 diff --git a/net/src/main/java/org/xbib/net/URL.java b/net/src/main/java/org/xbib/net/URL.java index 6a50edb..b03ef46 100755 --- a/net/src/main/java/org/xbib/net/URL.java +++ b/net/src/main/java/org/xbib/net/URL.java @@ -41,7 +41,7 @@ import java.util.Objects; * URL url = URL.http().resolveFromHost("google.com").build(); * */ -public class URL implements Comparable { +public final class URL implements Comparable { static final URL NULL_URL = URL.builder().build(); @@ -257,10 +257,6 @@ public class URL implements Comparable { } } - public URLBuilder mutator() { - return builder; - } - public URLBuilder newBuilder() { return new URLBuilder(); } diff --git a/net/src/main/java/org/xbib/net/URLBuilder.java b/net/src/main/java/org/xbib/net/URLBuilder.java index 0283d55..5a179c6 100644 --- a/net/src/main/java/org/xbib/net/URLBuilder.java +++ b/net/src/main/java/org/xbib/net/URLBuilder.java @@ -301,11 +301,11 @@ public class URLBuilder { * * @return a string */ - String toUrlString() { + public String toUrlString() { return build().toExternalForm(); } - void validateSchemeCharacters(String scheme) { + private void validateSchemeCharacters(String scheme) { boolean valid; for (int i = 0; i < scheme.length(); i++) { char c = scheme.charAt(i); diff --git a/net/src/test/java/org/xbib/net/ParameterTest.java b/net/src/test/java/org/xbib/net/ParameterTest.java index 4b1affe..a9018db 100644 --- a/net/src/test/java/org/xbib/net/ParameterTest.java +++ b/net/src/test/java/org/xbib/net/ParameterTest.java @@ -106,7 +106,7 @@ public class ParameterTest { } @Test - public void testMutatorQueryParameters() { + public void testQueryParametersWithUrlBuilder() { URL url = URL.from("http://localhost"); String requestPath = "/path"; Map map = Map.of( @@ -120,10 +120,9 @@ public class ParameterTest { .enableQueryString(true) .add(map) .build(); - URLBuilder mutator = url.mutator(); - mutator.path(requestPath); - httpParameter.forEach(e -> mutator.queryParam(e.getKey(), e.getValue())); - url = mutator.build(); + URLBuilder builder = URL.builder(url).path(requestPath); + httpParameter.forEach(e -> builder.queryParam(e.getKey(), e.getValue())); + url = builder.build(); assertEquals("http://localhost/path?operation=searchRetrieve&query=iss%20%3D%2000280836&recordSchema=MARC21plus-1-xml&version=1.1", url.toExternalForm()); } diff --git a/net/src/test/java/org/xbib/net/URLBuilderTest.java b/net/src/test/java/org/xbib/net/URLBuilderTest.java index b17287a..e5a1303 100644 --- a/net/src/test/java/org/xbib/net/URLBuilderTest.java +++ b/net/src/test/java/org/xbib/net/URLBuilderTest.java @@ -267,8 +267,8 @@ class URLBuilderTest { } @Test - void testMutator() { - URLBuilder builder = URL.from("http://google.com:8008/foobar").mutator(); + void testUrlBuilder() { + URLBuilder builder = URL.builder(URL.from("http://google.com:8008/foobar")); builder.queryParam("a%", "b%"); builder.queryParam("c", " d "); builder.scheme("https"); @@ -278,11 +278,9 @@ class URLBuilderTest { assertEquals("https://google.com:8008/foobar?a%=b%&c= d ", url.toString()); // test inheritance of params added by mutator - URL url1 = URL.from("http://example.com"); - url1.mutator().queryParams.add("a", "b"); + URL url1 = URL.builder(URL.from("http://example.com")).queryParam("a", "b").build(); assertEquals("http://example.com?a=b", url1.toString()); - URL url2 = URL.from(url1); // copy - url2.mutator().queryParams.add("c", "d"); + URL url2 = URL.builder(url1).queryParam("c", "d").build(); assertEquals("http://example.com?a=b&c=d", url2.toString()); } diff --git a/net/src/test/java/org/xbib/net/URLResolverTest.java b/net/src/test/java/org/xbib/net/URLResolverTest.java index e76e2f2..6d90f81 100644 --- a/net/src/test/java/org/xbib/net/URLResolverTest.java +++ b/net/src/test/java/org/xbib/net/URLResolverTest.java @@ -44,7 +44,7 @@ class URLResolverTest { String pathSpec = "foobar/"; String index = "index.html"; 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()); }