Skip to content
This repository was archived by the owner on Jul 31, 2022. It is now read-only.

Commit c7ce5ba

Browse files
authored
Merge pull request #56 from Ktt-Development/optimize-toString
Optimize toString
2 parents d035c4d + 10786ce commit c7ce5ba

16 files changed

+170
-184
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.kttdevelopment</groupId>
88
<artifactId>simplehttpserver</artifactId>
9-
<version>03.04.03</version>
9+
<version>03.05.00</version>
1010
<packaging>jar</packaging>
1111

1212
<url>https://github.com/Ktt-Development/simplehttpserver</url>

src/main/java/com/kttdevelopment/simplehttpserver/HttpSessionHandler.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* This class assigns {@link HttpSession} to every client.
1010
*
1111
* @since 03.03.00
12-
* @version 03.03.00
12+
* @version 03.05.00
1313
* @author Ktt Development
1414
*/
1515
public class HttpSessionHandler {
@@ -130,16 +130,14 @@ public synchronized final void updateLastAccessTime(){
130130

131131
//
132132

133-
@SuppressWarnings("StringBufferReplaceableByString")
134133
@Override
135134
public String toString(){
136-
final StringBuilder OUT = new StringBuilder();
137-
OUT.append("HttpSession") .append('{');
138-
OUT.append("sessionID") .append('=') .append(sessionID) .append(", ");
139-
OUT.append("creationTime") .append('=') .append(creationTime) .append(", ");
140-
OUT.append("lastAccessTime") .append('=') .append(lastAccessTime);
141-
OUT.append('}');
142-
return OUT.toString();
135+
return
136+
"HttpSession" + '{' +
137+
"sessionID" + '=' + sessionID + ", " +
138+
"creationTime" + '=' + creationTime + ", " +
139+
"lastAccessTime" + '=' + lastAccessTime +
140+
'}';
143141
}
144142

145143
};
@@ -158,4 +156,13 @@ public String toString(){
158156
return session;
159157
}
160158

159+
@Override
160+
public String toString(){
161+
return
162+
"HttpSessionHandler" + '{' +
163+
"sessions" + '=' + sessions + ", " +
164+
"cookie" + '=' + cookie + ", " +
165+
'}';
166+
}
167+
161168
}

src/main/java/com/kttdevelopment/simplehttpserver/SimpleHttpCookie.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @see SimpleHttpExchange
1010
* @see Builder
1111
* @since 02.00.00
12-
* @version 02.03.00
12+
* @version 03.05.00
1313
* @author Ktt Development
1414
*/
1515
public class SimpleHttpCookie {
@@ -93,23 +93,21 @@ public final String toCookieHeaderString(){
9393
return OUT.toString();
9494
}
9595

96-
@SuppressWarnings("StringBufferReplaceableByString")
97-
public String toString(){
98-
final StringBuilder OUT = new StringBuilder();
99-
100-
OUT.append("SimpleHttpCookie") .append('{');
101-
OUT.append("name") .append('=') .append(name) .append(", ");
102-
OUT.append("value") .append('=') .append(value) .append(", ");
103-
OUT.append("expires") .append('=') .append(expires) .append(", ");
104-
OUT.append("maxAge") .append('=') .append(maxAge) .append(", ");
105-
OUT.append("domain") .append('=') .append(domain) .append(", ");
106-
OUT.append("path") .append('=') .append(path) .append(", ");
107-
OUT.append("secure") .append('=') .append(secure) .append(", ");
108-
OUT.append("httpOnly") .append('=') .append(httpOnly) .append(", ");
109-
OUT.append("sameSite") .append('=') .append(sameSite);
110-
OUT.append('}');
96+
//
11197

112-
return OUT.toString();
98+
public String toString(){
99+
return
100+
"SimpleHttpCookie" + '{' +
101+
"name" + '=' + name + ", " +
102+
"value" + '=' + value + ", " +
103+
"expires" + '=' + expires + ", " +
104+
"maxAge" + '=' + maxAge + ", " +
105+
"domain" + '=' + domain + ", " +
106+
"path" + '=' + path + ", " +
107+
"secure" + '=' + secure + ", " +
108+
"httpOnly" + '=' + httpOnly + ", " +
109+
"sameSite" + '=' + sameSite +
110+
'}';
113111
}
114112

115113
/**

src/main/java/com/kttdevelopment/simplehttpserver/SimpleHttpExchangeImpl.java

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* @see SimpleHttpExchange
1919
* @since 02.00.00
20-
* @version 03.04.03
20+
* @version 03.05.00
2121
* @author Ktt Development
2222
*/
2323
@SuppressWarnings("SpellCheckingInspection")
@@ -415,31 +415,29 @@ public synchronized final void setAttribute(final String name, final Object valu
415415

416416
//
417417

418-
@SuppressWarnings("StringBufferReplaceableByString")
419418
@Override
420419
public String toString(){
421-
final StringBuilder OUT = new StringBuilder();
422-
OUT.append("SimpleHttpExchange").append('{');
423-
OUT.append("httpServer") .append('=') .append(httpServer) .append(", ");
424-
OUT.append("httpExchange") .append('=') .append(httpExchange) .append(", ");
425-
OUT.append("URI") .append('=') .append(URI) .append(", ");
426-
OUT.append("publicAddress") .append('=') .append(publicAddr) .append(", ");
427-
OUT.append("localAddress") .append('=') .append(localAddr) .append(", ");
428-
OUT.append("httpContext") .append('=') .append(httpContext) .append(", ");
429-
OUT.append("httpPrincipal") .append('=') .append(httpPrincipal) .append(", ");
430-
OUT.append("protocol") .append('=') .append(protocol) .append(", ");
431-
OUT.append("requestHeaders") .append('=') .append(requestHeaders) .append(", ");
432-
OUT.append("requestMethod") .append('=') .append(requestMethod) .append(", ");
433-
OUT.append("responseHeaders") .append('=') .append(getResponseHeaders()) .append(", ");
434-
OUT.append("responseCode") .append('=') .append(getResponseCode()) .append(", ");
435-
OUT.append("rawGet") .append('=') .append(rawGet) .append(", ");
436-
OUT.append("getMap") .append('=') .append(getMap) .append(", ");
437-
OUT.append("hasGet") .append('=') .append(hasGet) .append(", ");
438-
OUT.append("rawPost") .append('=') .append(rawPost) .append(", ");
439-
OUT.append("postMap") .append('=') .append(postMap) .append(", ");
440-
OUT.append("hasPost") .append('=') .append(hasPost) .append(", ");
441-
OUT.append("cookies") .append('=') .append(cookies);
442-
OUT.append('}');
443-
return OUT.toString();
420+
return
421+
"SimpleHttpExchange" + '{' +
422+
"httpServer" + '=' + httpServer + ", " +
423+
"httpExchange" + '=' + httpExchange + ", " +
424+
"URI" + '=' + URI + ", " +
425+
"publicAddress" + '=' + publicAddr + ", " +
426+
"localAddress" + '=' + localAddr + ", " +
427+
"httpContext" + '=' + httpContext + ", " +
428+
"httpPrincipal" + '=' + httpPrincipal + ", " +
429+
"protocol" + '=' + protocol + ", " +
430+
"requestHeaders" + '=' + requestHeaders + ", " +
431+
"requestMethod" + '=' + requestMethod + ", " +
432+
"responseHeaders" + '=' + getResponseHeaders() + ", " +
433+
"responseCode" + '=' + getResponseCode() + ", " +
434+
"rawGet" + '=' + rawGet + ", " +
435+
"getMap" + '=' + getMap + ", " +
436+
"hasGet" + '=' + hasGet + ", " +
437+
"rawPost" + '=' + rawPost + ", " +
438+
"postMap" + '=' + postMap + ", " +
439+
"hasPost" + '=' + hasPost + ", " +
440+
"cookies" + '=' + cookies +
441+
'}';
444442
}
445443
}

src/main/java/com/kttdevelopment/simplehttpserver/SimpleHttpServerImpl.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* @see SimpleHttpServer
1515
* @since 02.00.00
16-
* @version 03.04.03
16+
* @version 03.05.00
1717
* @author Ktt Development
1818
*/
1919
@SuppressWarnings("SpellCheckingInspection")
@@ -248,17 +248,15 @@ public synchronized final void stop(final int delay){
248248

249249
//
250250

251-
@SuppressWarnings("StringBufferReplaceableByString")
252251
@Override
253252
public String toString(){
254-
final StringBuilder OUT = new StringBuilder();
255-
OUT.append("SimpleHttpServer") .append('{');
256-
OUT.append("httpServer") .append('=') .append(server) .append(", ");
257-
OUT.append("contexts") .append('=') .append(contexts) .append(", ");
258-
OUT.append("address") .append('=') .append(getAddress()) .append(", ");
259-
OUT.append("executor") .append('=') .append(getExecutor());
260-
OUT.append('}');
261-
return OUT.toString();
253+
return
254+
"SimpleHttpServer" + '{' +
255+
"httpServer" + '=' + server + ", " +
256+
"contexts" + '=' + contexts + ", " +
257+
"address" + '=' + getAddress() + ", " +
258+
"executor" + '=' + getExecutor() +
259+
'}';
262260
}
263261

264262
// start slash; no end slash

src/main/java/com/kttdevelopment/simplehttpserver/SimpleHttpsServerImpl.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* @see SimpleHttpsServer
1515
* @since 03.04.00
16-
* @version 03.04.03
16+
* @version 03.05.00
1717
* @author Ktt Development
1818
*/
1919
final class SimpleHttpsServerImpl extends SimpleHttpsServer {
@@ -263,18 +263,16 @@ public synchronized final void stop(final int delay){
263263

264264
// endregion
265265

266-
@SuppressWarnings("StringBufferReplaceableByString")
267266
@Override
268267
public String toString(){
269-
final StringBuilder OUT = new StringBuilder();
270-
OUT.append("SimpleHttpsServer") .append('{');
271-
OUT.append("httpServer") .append('=') .append(server) .append(", ");
272-
OUT.append("httpsConfigurator") .append('=') .append(getHttpsConfigurator()) .append(", ");
273-
OUT.append("contexts") .append('=') .append(contexts) .append(", ");
274-
OUT.append("address") .append('=') .append(getAddress()) .append(", ");
275-
OUT.append("executor") .append('=') .append(getExecutor());
276-
OUT.append('}');
277-
return OUT.toString();
268+
return
269+
"SimpleHttpsServer" + '{' +
270+
"httpServer" + '=' + server + ", " +
271+
"httpsConfigurator" + '=' + getHttpsConfigurator() + ", " +
272+
"contexts" + '=' + contexts + ", " +
273+
"address" + '=' + getAddress() + ", " +
274+
"executor" + '=' + getExecutor() +
275+
'}';
278276
}
279277

280278
// start slash; no end slash

src/main/java/com/kttdevelopment/simplehttpserver/handler/DirectoryEntry.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @see FileHandler
1313
* @see FileEntry
1414
* @since 02.00.00
15-
* @version 02.00.00
15+
* @version 03.05.00
1616
* @author Ktt Development
1717
*/
1818
class DirectoryEntry {
@@ -219,19 +219,16 @@ private static String getContext(final String path){
219219

220220
//
221221

222-
223-
@SuppressWarnings("StringBufferReplaceableByString")
224222
@Override
225223
public String toString(){
226-
final StringBuilder OUT = new StringBuilder();
227-
OUT.append("DirectoryEntry") .append("{");
228-
OUT.append("isWalkthrough") .append("=") .append(isWalkthrough) .append(", ");
229-
OUT.append("isFilePreloaded") .append("=") .append(isFilesPreloaded) .append(", ");
230-
OUT.append("directory") .append("=") .append(directory) .append(", ");
231-
OUT.append("(preloaded) files") .append("=") .append(files) .append(", ");
232-
OUT.append("adapter") .append("=") .append(adapter);
233-
OUT.append("}");
234-
return OUT.toString();
224+
return
225+
"DirectoryEntry" + "{" +
226+
"isWalkthrough" + "=" + isWalkthrough + ", " +
227+
"isFilePreloaded" + "=" + isFilesPreloaded + ", " +
228+
"directory" + "=" + directory + ", " +
229+
"(preloaded) files" + "=" + files + ", " +
230+
"adapter" + "=" + adapter +
231+
"}";
235232
}
236233

237234
}

src/main/java/com/kttdevelopment/simplehttpserver/handler/FileEntry.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* @see FileHandler
1111
* @since 02.00.00
12-
* @version 02.00.00
12+
* @version 03.05.00
1313
* @author Ktt Development
1414
*/
1515
class FileEntry {
@@ -96,17 +96,14 @@ public final byte[] getBytes(){
9696

9797
//
9898

99-
100-
@SuppressWarnings("StringBufferReplaceableByString")
10199
@Override
102100
public String toString(){
103-
final StringBuilder OUT = new StringBuilder();
104-
OUT.append("FileEntry") .append("{");
105-
OUT.append("isPreloaded") .append("=") .append(isPreloaded) .append(", ");
106-
OUT.append("file") .append("=") .append(file.toString()) .append(", ");
107-
OUT.append("(preloaded) bytes") .append("=") .append(Arrays.toString(preloadedBytes)) .append(", ");
108-
OUT.append("}");
109-
return OUT.toString();
101+
return
102+
"FileEntry" + '{' +
103+
"isPreloaded" + '=' + isPreloaded + ", " +
104+
"file" + '=' + file.toString() + ", " +
105+
"(preloaded) bytes" + '=' + Arrays.toString(preloadedBytes) +
106+
'}';
110107
}
111108

112109
}

src/main/java/com/kttdevelopment/simplehttpserver/handler/FileHandler.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @see SimpleHttpHandler
2323
* @see com.sun.net.httpserver.HttpHandler
2424
* @since 02.00.00
25-
* @version 02.00.00
25+
* @version 03.05.00
2626
* @author Ktt Development
2727
*/
2828
public class FileHandler implements SimpleHttpHandler {
@@ -711,17 +711,14 @@ private static String getContext(final String path){
711711

712712
//
713713

714-
715-
@SuppressWarnings("StringBufferReplaceableByString")
716714
@Override
717715
public String toString(){
718-
final StringBuilder OUT = new StringBuilder();
719-
OUT.append("FileHandler") .append('{');
720-
OUT.append("adapter") .append('=') .append(adapter.toString()) .append(", ");
721-
OUT.append("(loaded) files") .append('=') .append(files) .append(", ");
722-
OUT.append("(loaded) directories") .append('=') .append(directories);
723-
OUT.append('}');
724-
return OUT.toString();
716+
return
717+
"FileHandler" + '{' +
718+
"adapter" + '=' + adapter.toString() + ", " +
719+
"(loaded) files" + '=' + files + ", " +
720+
"(loaded) directories" + '=' + directories +
721+
'}';
725722
}
726723

727724
}

src/main/java/com/kttdevelopment/simplehttpserver/handler/PredicateHandler.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @see SimpleHttpExchange
1717
* @see Predicate
1818
* @since 01.00.00
19-
* @version 02.00.00
19+
* @version 03.05.00
2020
* @author Ktt Development
2121
*/
2222
public class PredicateHandler implements HttpHandler {
@@ -51,17 +51,14 @@ public final void handle(final HttpExchange exchange) throws IOException{
5151

5252
//
5353

54-
55-
@SuppressWarnings("StringBufferReplaceableByString")
5654
@Override
5755
public String toString(){
58-
final StringBuilder OUT = new StringBuilder();
59-
OUT.append("PredicateHandler") .append('{');
60-
OUT.append("(true) handler") .append('=') .append(T.toString()) .append(", ");
61-
OUT.append("(false) handler") .append('=') .append(F.toString()) .append(", ");
62-
OUT.append("predicate") .append('=') .append(predicate.toString());
63-
OUT.append('}');
64-
return OUT.toString();
56+
return
57+
"PredicateHandler" + '{' +
58+
"(true) handler" + '=' + T.toString() + ", " +
59+
"(false) handler" + '=' + F.toString() + ", " +
60+
"predicate" + '=' + predicate.toString() +
61+
'}';
6562
}
6663

6764
}

0 commit comments

Comments
 (0)