8000 Converting Logging deserialized enum types to StringEnumValue by garrettjonesgoogle · Pull Request #1945 · googleapis/google-cloud-java · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.google.cloud.logging;

import com.google.api.core.ApiFunction;
import com.google.cloud.StringEnumType;
import com.google.cloud.StringEnumValue;
import com.google.common.base.MoreObjects;

import java.io.Serializable;
Expand Down Expand Up @@ -50,11 +53,51 @@ public final class HttpRequest implements Serializable {
/**
* The HTTP request method.
*/
public enum RequestMethod {
GET,
HEAD,
PUT,
POST
public static final class RequestMethod extends StringEnumValue {
private static final long serialVersionUID = 2403969065179486996L;

private RequestMethod(String constant) {
super(constant);
}

private static final ApiFunction<String, RequestMethod> CONSTRUCTOR =
new ApiFunction<String, RequestMethod>() {
@Override
public RequestMethod apply(String constant) {
return new RequestMethod(constant);
}
};

private static final StringEnumType<RequestMethod> type = new StringEnumType(
RequestMethod.class,
CONSTRUCTOR);

public static final RequestMethod GET = type.createAndRegister("GET");
public static final RequestMethod HEAD = type.createAndRegister("HEAD");
public static final RequestMethod PUT = type.createAndRegister("PUT");
public static final RequestMethod POST = type.createAndRegister("POST");

/**
* Get the RequestMethod for the given String constant, and throw an exception if the constant is
* not recognized.
*/
public static RequestMethod valueOfStrict(String constant) {
return type.valueOfStrict(constant);
}

/**
* Get the RequestMethod for the given String constant, and allow unrecognized values.
*/
public static RequestMethod valueOf(String constant) {
return type.valueOf(constant);
}

/**
* Return the known values for RequestMethod.
*/
public static RequestMethod[] values() {
return type.values();
}
}

/**
Expand Down
0