Skip to content

Commit 16dcaa1

Browse files
Converting Logging deserialized enum types to StringEnumValue
1 parent 2fd93d9 commit 16dcaa1

File tree

1 file changed

+48
-5
lines changed

1 file changed

+48
-5
lines changed

google-cloud-logging/src/main/java/com/google/cloud/logging/HttpRequest.java

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package com.google.cloud.logging;
1818

19+
import com.google.api.core.ApiFunction;
20+
import com.google.cloud.StringEnumType;
21+
import com.google.cloud.StringEnumValue;
1922
import com.google.common.base.MoreObjects;
2023

2124
import java.io.Serializable;
@@ -50,11 +53,51 @@ public final class HttpRequest implements Serializable {
5053
/**
5154
* The HTTP request method.
5255
*/
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+
}
58101
}
59102

60103
/**

0 commit comments

Comments
 (0)