Skip to content

Commit 41692ff

Browse files
authored
Merge pull requests #321
* Improve performance
1 parent 7b97f75 commit 41692ff

File tree

12 files changed

+332
-129
lines changed

12 files changed

+332
-129
lines changed

joylive-core/joylive-core-api/src/main/java/com/jd/live/agent/core/util/URI.java

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ public URI() {
6060
super(null);
6161
}
6262

63-
private URI(String scheme,
64-
String user,
65-
String password,
66-
String host,
67-
Integer port,
68-
String path,
69-
Map<String, String> parameters,
70-
String url) {
63+
protected URI(final String scheme,
64+
final String user,
65+
final String password,
66+
final String host,
67+
final Integer port,
68+
final String path,
69+
final Map<String, String> parameters,
70+
final String url) {
7171
super(parameters);
7272
this.scheme = scheme;
7373
this.user = user;
@@ -136,7 +136,7 @@ public int getPort(int defaultPort) {
136136
* @return a new URI instance with the updated scheme.
137137
*/
138138
public URI scheme(String scheme) {
139-
return new URI(scheme, user, password, host, port, path, parameters);
139+
return create(scheme, user, password, host, port, path, parameters);
140140
}
141141

142142
/**
@@ -147,7 +147,7 @@ public URI scheme(String scheme) {
147147
*/
148148
@Deprecated
149149
public URI schema(String schema) {
150-
return new URI(schema, user, password, host, port, path, parameters);
150+
return create(schema, user, password, host, port, path, parameters);
151151
}
152152

153153
/**
@@ -157,7 +157,7 @@ public URI schema(String schema) {
157157
* @return a new URI instance with the updated user component
158158
*/
159159
public URI user(String user) {
160-
return new URI(scheme, user, password, host, port, path, parameters);
160+
return create(scheme, user, password, host, port, path, parameters);
161161
}
162162

163163
/**
@@ -167,7 +167,7 @@ public URI user(String user) {
167167
* @return a new URI instance with the updated password component
168168
*/
169169
public URI password(String password) {
170-
return new URI(scheme, user, password, host, port, path, parameters);
170+
return create(scheme, user, password, host, port, path, parameters);
171171
}
172172

173173
/**
@@ -177,7 +177,7 @@ public URI password(String password) {
177177
* @return a new URI instance with the updated host.
178178
*/
179179
public URI host(String host) {
180-
return new URI(scheme, user, password, host, port, path, parameters);
180+
return create(scheme, user, password, host, port, path, parameters);
181181
}
182182

183183
/**
@@ -187,7 +187,7 @@ public URI host(String host) {
187187
* @return a new URI instance with the updated port.
188188
*/
189189
public URI port(Integer port) {
190-
return new URI(scheme, user, password, host, port, path, parameters);
190+
return create(scheme, user, password, host, port, path, parameters);
191191
}
192192

193193
/**
@@ -198,7 +198,7 @@ public URI port(Integer port) {
198198
* @return a new URI instance with the updated host.
199199
*/
200200
public URI address(String host, Integer port) {
201-
return new URI(scheme, user, password, host, port, path, parameters);
201+
return create(scheme, user, password, host, port, path, parameters);
202202
}
203203

204204
/**
@@ -208,7 +208,7 @@ public URI address(String host, Integer port) {
208208
* @return a new URI instance with the updated path.
209209
*/
210210
public URI path(String path) {
211-
return new URI(scheme, user, password, host, port, path, parameters);
211+
return create(scheme, user, password, host, port, path, parameters);
212212
}
213213

214214
/**
@@ -218,7 +218,7 @@ public URI path(String path) {
218218
* @return a new URI instance with the updated path.
219219
*/
220220
public URI parameters(Map<String, String> parameters) {
221-
return new URI(scheme, user, password, host, port, path, parameters);
221+
return create(scheme, user, password, host, port, path, parameters);
222222
}
223223

224224
/**
@@ -251,7 +251,7 @@ public URI parameter(String key, String value) {
251251
}
252252
newUrl = builder.toString();
253253
}
254-
return new URI(scheme, user, password, host, port, path, newParameters, newUrl);
254+
return create(scheme, user, password, host, port, path, newParameters, newUrl);
255255
}
256256

257257
/**
@@ -366,6 +366,27 @@ public String toString() {
366366
return getUri();
367367
}
368368

369+
protected URI create(final String scheme,
370+
final String user,
371+
final String password,
372+
final String host,
373+
final Integer port,
374+
final String path,
375+
final Map<String, String> parameters) {
376+
return new URI(scheme, user, password, host, port, path, parameters, null);
377+
}
378+
379+
protected URI create(final String scheme,
380+
final String user,
381+
final String password,
382+
final String host,
383+
final Integer port,
384+
final String path,
385+
final Map<String, String> parameters,
386+
final String url) {
387+
return new URI(scheme, user, password, host, port, path, parameters, url);
388+
}
389+
369390
private static boolean isIpv6(String host) {
370391
return host != null && host.indexOf(':') >= 0;
371392
}

0 commit comments

Comments
 (0)