Less object instantiation in WebMvcTags

See gh-12894
This commit is contained in:
Jon Schneider 2018-04-17 21:41:49 -05:00 committed by Stephane Nicoll
parent 0bc7bef5e5
commit d676147680
1 changed files with 14 additions and 7 deletions

View File

@ -40,6 +40,14 @@ public final class WebMvcTags {
private static final Tag URI_REDIRECTION = Tag.of("uri", "REDIRECTION");
private static final Tag URI_UNKNOWN = Tag.of("uri", "UNKNOWN");
private static final Tag EXCEPTION_NONE = Tag.of("exception", "None");
private static final Tag STATUS_UNKNOWN = Tag.of("status", "UNKNOWN");
private static final Tag METHOD_UNKNOWN = Tag.of("method", "UNKNOWN");
private WebMvcTags() {
}
@ -50,8 +58,7 @@ public final class WebMvcTags {
* @return the method tag whose value is a capitalized method (e.g. GET).
*/
public static Tag method(HttpServletRequest request) {
return (request == null ? Tag.of("method", "UNKNOWN")
: Tag.of("method", request.getMethod()));
return request == null ? METHOD_UNKNOWN : Tag.of("method", request.getMethod());
}
/**
@ -60,8 +67,8 @@ public final class WebMvcTags {
* @return the status tag derived from the status of the response
*/
public static Tag status(HttpServletResponse response) {
return (response == null ? Tag.of("status", "UNKNOWN")
: Tag.of("status", ((Integer) response.getStatus()).toString()));
return response == null ? STATUS_UNKNOWN :
Tag.of("status", Integer.toString(response.getStatus()));
}
/**
@ -91,7 +98,7 @@ public final class WebMvcTags {
String pathInfo = getPathInfo(request);
return Tag.of("uri", pathInfo.isEmpty() ? "root" : pathInfo);
}
return Tag.of("uri", "UNKNOWN");
return URI_UNKNOWN;
}
private static HttpStatus extractStatus(HttpServletResponse response) {
@ -121,8 +128,8 @@ public final class WebMvcTags {
* @return the exception tag derived from the exception
*/
public static Tag exception(Throwable exception) {
return Tag.of("exception",
(exception == null ? "None" : exception.getClass().getSimpleName()));
return exception == null ? EXCEPTION_NONE :
Tag.of("exception", exception.getClass().getSimpleName());
}
}