|
16 | 16 |
|
17 | 17 | package com.google.cloud.logging; |
18 | 18 |
|
| 19 | +import com.google.api.core.ApiFunction; |
| 20 | +import com.google.cloud.StringEnumType; |
| 21 | +import com.google.cloud.StringEnumValue; |
19 | 22 | import com.google.common.base.MoreObjects; |
20 | 23 |
|
21 | 24 | import java.io.Serializable; |
@@ -50,11 +53,51 @@ public final class HttpRequest implements Serializable { |
50 | 53 | /** |
51 | 54 | * The HTTP request method. |
52 | 55 | */ |
53 | | - public enum RequestMethod { |
54 | | - GET, |
55 | | - HEAD, |
56 | | - PUT, |
57 | | - POST |
| 56 | + public static final class RequestMethod extends StringEnumValue { |
| 57 | + private static final long serialVersionUID = 2403969065179486996L; |
| 58 | + |
| 59 | + private RequestMethod(String constant) { |
| 60 | + super(constant); |
| 61 | + } |
| 62 | + |
| 63 | + private static final ApiFunction<String, RequestMethod> CONSTRUCTOR = |
| 64 | + new ApiFunction<String, RequestMethod>() { |
| 65 | + @Override |
| 66 | + public RequestMethod apply(String constant) { |
| 67 | + return new RequestMethod(constant); |
| 68 | + } |
| 69 | + }; |
| 70 | + |
| 71 | + private static final StringEnumType<RequestMethod> type = new StringEnumType( |
| 72 | + RequestMethod.class, |
| 73 | + CONSTRUCTOR); |
| 74 | + |
| 75 | + public static final RequestMethod GET = type.createAndRegister("GET"); |
| 76 | + public static final RequestMethod HEAD = type.createAndRegister("HEAD"); |
| 77 | + public static final RequestMethod PUT = type.createAndRegister("PUT"); |
| 78 | + public static final RequestMethod POST = type.createAndRegister("POST"); |
| 79 | + |
| 80 | + /** |
| 81 | + * Get the RequestMethod for the given String constant, and throw an exception if the constant is |
| 82 | + * not recognized. |
| 83 | + */ |
| 84 | + public static RequestMethod valueOfStrict(String constant) { |
| 85 | + return type.valueOfStrict(constant); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * Get the RequestMethod for the given String constant, and allow unrecognized values. |
| 90 | + */ |
| 91 | + public static RequestMethod valueOf(String constant) { |
| 92 | + return type.valueOf(constant); |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Return the known values for RequestMethod. |
| 97 | + */ |
| 98 | + public static RequestMethod[] values() { |
| 99 | + return type.values(); |
| 100 | + } |
58 | 101 | } |
59 | 102 |
|
60 | 103 | /** |
|
0 commit comments