1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.adservices.service.common.bhttp;
18 
19 import com.android.internal.util.Preconditions;
20 
21 /** Utility methods for HTTP status code. */
22 public class HttpStatusCodeUtil {
23 
24     public static final int INFORMATIVE_MIN = 100;
25     public static final int INFORMATIVE_MAX = 199;
26     public static final int FINAL_MIN = 200;
27     public static final int FINAL_MAX = 599;
28 
29     /** Precondition check for informative status code. */
checkIsInformativeStatusCode(final int statusCode)30     public static void checkIsInformativeStatusCode(final int statusCode) {
31         Preconditions.checkArgument(
32                 isInformativeStatusCode(statusCode),
33                 "Status code %d is not an informative status code.",
34                 statusCode);
35     }
36 
37     /** Precondition check for final status code. */
checkIsFinalStatusCode(final int statusCode)38     public static void checkIsFinalStatusCode(final int statusCode) {
39         Preconditions.checkArgument(
40                 isFinalStatusCode(statusCode),
41                 "Status code %d is not an final status code.",
42                 statusCode);
43     }
44 
45     /** Returns whether the given status code is an informative status code. */
isInformativeStatusCode(final int statusCode)46     public static boolean isInformativeStatusCode(final int statusCode) {
47         return statusCode >= INFORMATIVE_MIN && statusCode <= INFORMATIVE_MAX;
48     }
49 
50     /** Returns whether the given status code is a final status code. */
isFinalStatusCode(final int statusCode)51     public static boolean isFinalStatusCode(final int statusCode) {
52         return statusCode >= FINAL_MIN && statusCode <= FINAL_MAX;
53     }
54 }
55