Add HTTP series check shortcut methods to HttpStatus

Issue: SPR-11424
This commit is contained in:
Rossen Stoyanchev 2014-03-12 17:04:16 -04:00
parent 6a4a2ec6a4
commit 6b31074e4a
1 changed files with 47 additions and 1 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -389,6 +389,52 @@ public enum HttpStatus {
return reasonPhrase;
}
/**
* Whether this status code is in the HTTP series
* {@link org.springframework.http.HttpStatus.Series#INFORMATIONAL}.
* This is a shortcut for checking the value of {@link #series()}.
*/
public boolean is1xxInformational() {
return (Series.INFORMATIONAL.equals(series()));
}
/**
* Whether this status code is in the HTTP series
* {@link org.springframework.http.HttpStatus.Series#SUCCESSFUL}.
* This is a shortcut for checking the value of {@link #series()}.
*/
public boolean is2xxSuccessful() {
return (Series.SUCCESSFUL.equals(series()));
}
/**
* Whether this status code is in the HTTP series
* {@link org.springframework.http.HttpStatus.Series#REDIRECTION}.
* This is a shortcut for checking the value of {@link #series()}.
*/
public boolean is3xxRedirection() {
return (Series.REDIRECTION.equals(series()));
}
/**
* Whether this status code is in the HTTP series
* {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR}.
* This is a shortcut for checking the value of {@link #series()}.
*/
public boolean is4xxClientError() {
return (Series.CLIENT_ERROR.equals(series()));
}
/**
* Whether this status code is in the HTTP series
* {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR}.
* This is a shortcut for checking the value of {@link #series()}.
*/
public boolean is5xxServerError() {
return (Series.SERVER_ERROR.equals(series()));
}
/**
* Returns the HTTP status series of this status code.
* @see HttpStatus.Series