Skip to content

Commit b280733

Browse files
committed
Javadoc improvements and simple code declutter
- Add missing Javadoc tags - Remove redundant parentheses in lambdas (reduces cluttter) - Close HTML tags - Add missing Javadoc descriptions - No need to nest else clause (reduces cluttter) - Use a ternary expression - Use a single return - Access static method directly - use Objects.toString()
1 parent 2104b2a commit b280733

36 files changed

+255
-88
lines changed

httpcore5/src/main/java/org/apache/hc/core5/http/ContentType.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ public Charset getCharset(final Charset defaultCharset) {
259259
}
260260

261261
/**
262+
* Gets the named parameter's value.
263+
*
264+
* @param name The parameter name.
265+
* @return The parameter value.
262266
* @since 4.3
263267
*/
264268
public String getParameter(final String name) {
@@ -380,7 +384,8 @@ private static ContentType create(final String mimeType, final NameValuePair[] p
380384
* characters {@code <">, <;>, <,>} reserved by the HTTP specification.
381385
* @param params parameters.
382386
* @return content type
383-
*
387+
* @throws UnsupportedCharsetException If no support for a named Charset is available
388+
* in this instance of the Java virtual machine.
384389
* @since 4.4
385390
*/
386391
public static ContentType create(
@@ -487,6 +492,8 @@ public ContentType withCharset(final String charset) {
487492
*
488493
* @param params parameters.
489494
* @return a new instance with this MIME type and the given parameters.
495+
* @throws UnsupportedCharsetException If no support for a named Charset is available
496+
* in this instance of the Java virtual machine.
490497
* @since 4.4
491498
*/
492499
public ContentType withParameters(

httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public HttpHost(final String scheme, final String hostname) {
137137
/**
138138
* Creates {@code HttpHost} instance from a string. Text may not contain any blanks.
139139
*
140+
* @throws URISyntaxException Thrown when a string could not be parsed as a URI reference.
140141
* @since 4.4
141142
*/
142143
public static HttpHost create(final String s) throws URISyntaxException {

httpcore5/src/main/java/org/apache/hc/core5/http/HttpMessage.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ public interface HttpMessage extends MessageHeaders {
4141
* For incoming messages it represents protocol version this message was transmitted with.
4242
* For outgoing messages it represents a hint what protocol version should be used to transmit
4343
* the message.
44+
* </p>
4445
*
46+
* @param version The protocol version.
4547
* @since 5.0
4648
*/
4749
void setVersion(ProtocolVersion version);
@@ -52,7 +54,9 @@ public interface HttpMessage extends MessageHeaders {
5254
* For incoming messages it represents protocol version this message was transmitted with.
5355
* For outgoing messages it represents a hint what protocol version should be used to transmit
5456
* the message.
57+
* </p>
5558
*
59+
* @return The protocol version.
5660
* @since 5.0
5761
*/
5862
ProtocolVersion getVersion();

httpcore5/src/main/java/org/apache/hc/core5/http/HttpRequest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public interface HttpRequest extends HttpMessage {
5858
/**
5959
* Sets URI path of this request message.
6060
*
61+
* @param path The URI path of this request message.
6162
* @since 5.0
6263
*/
6364
void setPath(String path);
@@ -66,14 +67,14 @@ public interface HttpRequest extends HttpMessage {
6667
* Returns scheme of this request message.
6768
*
6869
* @return the scheme or {@code null}.
69-
*
7070
* @since 5.0
7171
*/
7272
String getScheme();
7373

7474
/**
7575
* Sets scheme of this request message.
7676
*
77+
* @param scheme The scheme of this request message.
7778
* @since 5.0
7879
*/
7980
void setScheme(String scheme);
@@ -82,14 +83,14 @@ public interface HttpRequest extends HttpMessage {
8283
* Returns authority of this request message.
8384
*
8485
* @return the authority or {@code null}.
85-
*
8686
* @since 5.0
8787
*/
8888
URIAuthority getAuthority();
8989

9090
/**
9191
* Sets authority of this request message.
9292
*
93+
* @param authority The authority of this request message.
9394
* @since 5.0
9495
*/
9596
void setAuthority(URIAuthority authority);
@@ -99,7 +100,6 @@ public interface HttpRequest extends HttpMessage {
99100
* Applicable to HTTP/1.1 version or earlier.
100101
*
101102
* @return the request URI.
102-
*
103103
* @since 5.0
104104
*/
105105
String getRequestUri();
@@ -108,7 +108,7 @@ public interface HttpRequest extends HttpMessage {
108108
* Returns full request URI of this request message.
109109
*
110110
* @return the request URI.
111-
*
111+
* @throws URISyntaxException Thrown when a string could not be parsed as a URI reference.
112112
* @since 5.0
113113
*/
114114
URI getUri() throws URISyntaxException;
@@ -117,7 +117,6 @@ public interface HttpRequest extends HttpMessage {
117117
* Sets the full request URI of this request message.
118118
*
119119
* @param requestUri the request URI.
120-
*
121120
* @since 5.0
122121
*/
123122
void setUri(final URI requestUri);

httpcore5/src/main/java/org/apache/hc/core5/http/HttpRequestFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
/**
3333
* A factory for {@link HttpRequest} objects.
3434
*
35+
* @param <T> The type of {@link HttpRequest}.
3536
* @since 4.0
3637
*/
3738
public interface HttpRequestFactory<T extends HttpRequest> {

httpcore5/src/main/java/org/apache/hc/core5/http/HttpRequestMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* This class can be used to resolve an object matching a particular {@link HttpRequest}.
3434
* Usually the mapped object will be a request handler to process the request.
3535
*
36+
* @param <T> The type of HTTP request handler.
3637
* @since 5.0
3738
*/
3839
public interface HttpRequestMapper<T> {
@@ -41,8 +42,7 @@ public interface HttpRequestMapper<T> {
4142
* Resolves a handler matching the given request.
4243
*
4344
* @param request the request to map to a handler
44-
* @return HTTP request handler or {@code null} if no match
45-
* is found.
45+
* @return HTTP request handler or {@code null} if no match is found.
4646
* @throws HttpException in case of an HTTP protocol violation.
4747
*/
4848
T resolve(HttpRequest request, HttpContext context) throws HttpException;

httpcore5/src/main/java/org/apache/hc/core5/http/HttpResponseFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
/**
3131
* A factory for {@link HttpResponse} objects.
3232
*
33+
* @param <T> The type of {@link HttpResponse}.
3334
* @since 4.0
3435
*/
3536
public interface HttpResponseFactory<T extends HttpResponse> {

httpcore5/src/main/java/org/apache/hc/core5/http/Method.java

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,65 @@
3232
import org.apache.hc.core5.util.Args;
3333

3434
/**
35-
* Common HTTP methods defined by the HTTP spec.
35+
* Common HTTP methods defined by the HTTP specification.
36+
* <p>
37+
* Each method is:
38+
* </p>
39+
* <ul>
40+
* <li>Either <em>safe</em> or <em>unsafe</em>: An HTTP method is safe if it doesn't change the state of the server. In other words, a method is safe if it's
41+
* read-only.</li>
42+
* <li>Either <em>idempotent</em> or <em>non-idempotent</em>: An HTTP method is idempotent if making a single request has the same effect as making several
43+
* identical requests. All safe methods are also idempotent, but not all idempotent methods are safe. For example, {@code PUT} and {@code DELETE} are both
44+
* idempotent but unsafe.</li>
45+
* </ul>
3646
*
3747
* @since 5.0
3848
*/
3949
public enum Method {
4050

51+
/**
52+
* The HTTP {@code GET} method is safe and idempotent.
53+
*/
4154
GET(true, true),
55+
56+
/**
57+
* The HTTP {@code HEAD} method is safe and idempotent.
58+
*/
4259
HEAD(true, true),
60+
61+
/**
62+
* The HTTP {@code POST} method is unsafe and non-idempotent.
63+
*/
4364
POST(false, false),
65+
66+
/**
67+
* The HTTP {@code PUT} method is unsafe and idempotent.
68+
*/
4469
PUT(false, true),
70+
71+
/**
72+
* The HTTP {@code DELETE} method is unsafe and idempotent.
73+
*/
4574
DELETE(false, true),
75+
76+
/**
77+
* The HTTP {@code CONNECT} method is unsafe and non-idempotent.
78+
*/
4679
CONNECT(false, false),
80+
81+
/**
82+
* The HTTP {@code TRACE} method is safe and idempotent.
83+
*/
4784
TRACE(true, true),
85+
86+
/**
87+
* The HTTP {@code OPTIONS} method is safe and idempotent.
88+
*/
4889
OPTIONS(true, true),
90+
91+
/**
92+
* The HTTP {@code PATCH} method is unsafe and non-idempotent.
93+
*/
4994
PATCH(false, false);
5095

5196
private final boolean safe;
@@ -56,10 +101,20 @@ public enum Method {
56101
this.idempotent = idempotent;
57102
}
58103

104+
/**
105+
* Tests whether this method is safe.
106+
*
107+
* @return whether this method is safe.
108+
*/
59109
public boolean isSafe() {
60110
return safe;
61111
}
62112

113+
/**
114+
* Tests whether this method is idempotent.
115+
*
116+
* @return whether this method is idempotent.
117+
*/
63118
public boolean isIdempotent() {
64119
return idempotent;
65120
}

httpcore5/src/main/java/org/apache/hc/core5/http/ParseException.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ public class ParseException extends ProtocolException {
3939
private final int errorOffset;
4040

4141
/**
42-
* Creates a {@link ParseException} without details.
42+
* Constructs a new {@link ParseException} without details.
4343
*/
4444
public ParseException() {
4545
super();
4646
this.errorOffset = -1;
4747
}
4848

4949
/**
50-
* Creates a {@link ParseException} with a detail message.
50+
* Constructs a new {@link ParseException} with a detail message.
5151
*
5252
* @param message the exception detail message, or {@code null}
5353
*/
@@ -57,7 +57,7 @@ public ParseException(final String message) {
5757
}
5858

5959
/**
60-
* Creates a {@link ParseException} with parsing context details.
60+
* Constructs a new {@link ParseException} with parsing context details.
6161
*
6262
* @since 5.0
6363
*/
@@ -69,7 +69,7 @@ public ParseException(final String description, final CharSequence text, final i
6969
}
7070

7171
/**
72-
* Creates a {@link ParseException} with parsing context details.
72+
* Constructs a new {@link ParseException} with parsing context details.
7373
*
7474
* @since 5.0
7575
*/

httpcore5/src/main/java/org/apache/hc/core5/http/ProtocolVersionParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public ProtocolVersion parse(
6464
final int lowerBound = cursor.getLowerBound();
6565
final int upperBound = cursor.getUpperBound();
6666
final String token1 = tokenizer.parseToken(buffer, cursor,
67-
delimiterPredicate != null ? (ch) -> delimiterPredicate.test(ch) || FULL_STOP_OR_BLANK.test(ch) : FULL_STOP_OR_BLANK);
67+
delimiterPredicate != null ? ch -> delimiterPredicate.test(ch) || FULL_STOP_OR_BLANK.test(ch) : FULL_STOP_OR_BLANK);
6868
final int major;
6969
try {
7070
major = Integer.parseInt(token1);
@@ -80,7 +80,7 @@ public ProtocolVersion parse(
8080
} else {
8181
cursor.updatePos(cursor.getPos() + 1);
8282
final String token2 = tokenizer.parseToken(buffer, cursor,
83-
delimiterPredicate != null ? (ch) -> delimiterPredicate.test(ch) || BLANK.test(ch) : BLANK);
83+
delimiterPredicate != null ? ch -> delimiterPredicate.test(ch) || BLANK.test(ch) : BLANK);
8484
final int minor;
8585
try {
8686
minor = Integer.parseInt(token2);

0 commit comments

Comments
 (0)