11/*
22 * StatusCode.java
33 *
4- * Copyright 2015-2025 Erik C. Thauvin (erik@thauvin.net)
4+ * Copyright 2015-2026 Erik C. Thauvin (erik@thauvin.net)
55 * All rights reserved.
66 *
77 * Redistribution and use in source and binary forms, with or without
@@ -79,15 +79,25 @@ public static String getReason(int code) {
7979 }
8080
8181 /**
82- * Checks if the status code is informational.
82+ * Checks if the status code is a client error. (e.g.: <code>Internal Server Error</code>)
8383 *
8484 * @param code the status code
85- * @return <code>true</code> if the status code is informational, <code>false</code>
86- * @see #isInfo(int)
85+ * @return <code>true</code> if the status code is a client error, <code>false</code> otherwise
8786 * @since 2.0.0
8887 */
89- public static boolean isInformational (int code ) {
90- return isInfo (code );
88+ public static boolean isClientError (int code ) {
89+ return code >= 400 && code < 500 ;
90+ }
91+
92+ /**
93+ * Checks if the status code is a client or server error.
94+ *
95+ * @param code the status code
96+ * @return <code>true</code> if the status code is an error, <code>false</code> otherwise
97+ * @since 2.0.0
98+ */
99+ public static boolean isError (int code ) {
100+ return code >= 400 && code < 600 ;
91101 }
92102
93103 /**
@@ -103,15 +113,37 @@ public static boolean isInfo(int code) {
103113 }
104114
105115 /**
106- * Checks if the status code is a (<code>OK</code>) success .
116+ * Checks if the status code is informational .
107117 *
108118 * @param code the status code
109- * @return <code>true</code> if the status code is a success , <code>false</code> otherwise
110- * @see #isSuccess (int)
119+ * @return <code>true</code> if the status code is informational , <code>false</code>
120+ * @see #isInfo (int)
111121 * @since 2.0.0
112122 */
113- public static boolean isSuccessful (int code ) {
114- return isSuccess (code );
123+ public static boolean isInformational (int code ) {
124+ return isInfo (code );
125+ }
126+
127+ /**
128+ * Checks if the status code is a redirect.
129+ *
130+ * @param code the status code
131+ * @return <code>true</code> if the status code is a redirect, <code>false</code> otherwise
132+ * @since 2.0.0
133+ */
134+ public static boolean isRedirect (int code ) {
135+ return code >= 300 && code < 400 ;
136+ }
137+
138+ /**
139+ * Checks if the status code is a server error.
140+ *
141+ * @param code the status code
142+ * @return <code>true</code> if the status code is a server error, <code>false</code> otherwise
143+ * @since 2.0.0
144+ */
145+ public static boolean isServerError (int code ) {
146+ return code >= 500 && code < 600 ;
115147 }
116148
117149 /**
@@ -126,6 +158,28 @@ public static boolean isSuccess(int code) {
126158 return code >= 200 && code < 300 ;
127159 }
128160
161+ /**
162+ * Checks if the status code is a (<code>OK</code>) success.
163+ *
164+ * @param code the status code
165+ * @return <code>true</code> if the status code is a success, <code>false</code> otherwise
166+ * @see #isSuccess(int)
167+ * @since 2.0.0
168+ */
169+ public static boolean isSuccessful (int code ) {
170+ return isSuccess (code );
171+ }
172+
173+ /**
174+ * Checks if the status code is valid.
175+ *
176+ * @param code the status code
177+ * @return <code>true</code> if the status code is valid, <code>false</code> otherwise
178+ */
179+ public static boolean isValid (int code ) {
180+ return code == 783 || (code >= 100 && code < 600 );
181+ }
182+
129183 /**
130184 * Returns the status code.
131185 */
@@ -161,17 +215,6 @@ public boolean isClientError() {
161215 return isClientError (code );
162216 }
163217
164- /**
165- * Checks if the status code is a client error. (e.g.: <code>Internal Server Error</code>)
166- *
167- * @param code the status code
168- * @return <code>true</code> if the status code is a client error, <code>false</code> otherwise
169- * @since 2.0.0
170- */
171- public static boolean isClientError (int code ) {
172- return code >= 400 && code < 500 ;
173- }
174-
175218 /**
176219 * Checks if the status code is a client or server error.
177220 *
@@ -181,17 +224,6 @@ public boolean isError() {
181224 return isError (code );
182225 }
183226
184- /**
185- * Checks if the status code is a client or server error.
186- *
187- * @param code the status code
188- * @return <code>true</code> if the status code is an error, <code>false</code> otherwise
189- * @since 2.0.0
190- */
191- public static boolean isError (int code ) {
192- return code >= 400 && code < 600 ;
193- }
194-
195227 /**
196228 * Checks if the status code is informational.
197229 *
@@ -220,17 +252,6 @@ public boolean isRedirect() {
220252 return isRedirect (code );
221253 }
222254
223- /**
224- * Checks if the status code is a redirect.
225- *
226- * @param code the status code
227- * @return <code>true</code> if the status code is a redirect, <code>false</code> otherwise
228- * @since 2.0.0
229- */
230- public static boolean isRedirect (int code ) {
231- return code >= 300 && code < 400 ;
232- }
233-
234255 /**
235256 * Checks if the status code is a server error.
236257 *
@@ -240,17 +261,6 @@ public boolean isServerError() {
240261 return isServerError (code );
241262 }
242263
243- /**
244- * Checks if the status code is a server error.
245- *
246- * @param code the status code
247- * @return <code>true</code> if the status code is a server error, <code>false</code> otherwise
248- * @since 2.0.0
249- */
250- public static boolean isServerError (int code ) {
251- return code >= 500 && code < 600 ;
252- }
253-
254264 /**
255265 * Checks if the status code is a (<code>OK</code>) success.
256266 *
@@ -278,14 +288,4 @@ public boolean isSuccessful() {
278288 public boolean isValid () {
279289 return isValid (code );
280290 }
281-
282- /**
283- * Checks if the status code is valid.
284- *
285- * @param code the status code
286- * @return <code>true</code> if the status code is valid, <code>false</code> otherwise
287- */
288- public static boolean isValid (int code ) {
289- return code == 783 || (code >= 100 && code < 600 );
290- }
291291}
0 commit comments