From 6b31074e4a7b8e8b883d304e962af1c2b9b4c03d Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Wed, 12 Mar 2014 17:04:16 -0400 Subject: [PATCH] Add HTTP series check shortcut methods to HttpStatus Issue: SPR-11424 --- .../org/springframework/http/HttpStatus.java | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/spring-web/src/main/java/org/springframework/http/HttpStatus.java b/spring-web/src/main/java/org/springframework/http/HttpStatus.java index 225fbccd9f..262ad852c2 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpStatus.java +++ b/spring-web/src/main/java/org/springframework/http/HttpStatus.java @@ -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