Skip to content

Commit 603b4ae

Browse files
Convert all Resource Manager deserialized enum types to StringEnumValue (#2138)
Addresses #1944.
1 parent 40984be commit 603b4ae

1 file changed

Lines changed: 48 additions & 5 deletions

File tree

  • google-cloud-resourcemanager/src/main/java/com/google/cloud/resourcemanager

google-cloud-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ProjectInfo.java

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
import static com.google.common.base.MoreObjects.firstNonNull;
2020
import static com.google.common.base.Preconditions.checkNotNull;
2121

22+
import com.google.api.core.ApiFunction;
2223
import com.google.api.client.util.Data;
24+
import com.google.cloud.StringEnumType;
25+
import com.google.cloud.StringEnumValue;
2326
import com.google.common.collect.ImmutableMap;
2427
import com.google.common.collect.Maps;
2528

@@ -50,27 +53,67 @@ public class ProjectInfo implements Serializable {
5053
/**
5154
* The project lifecycle states.
5255
*/
53-
public enum State {
56+
public static final class State extends StringEnumValue {
57+
private static final long serialVersionUID = 869635563976629566L;
58+
59+
private static final ApiFunction<String, State> CONSTRUCTOR =
60+
new ApiFunction<String, State>() {
61+
@Override
62+
public State apply(String constant) {
63+
return new State(constant);
64+
}
65+
};
66+
67+
private static final StringEnumType<State> type = new StringEnumType(
68+
State.class,
69+
CONSTRUCTOR);
70+
5471
/**
5572
* Only used/useful for distinguishing unset values.
5673
*/
57-
LIFECYCLE_STATE_UNSPECIFIED,
74+
public static final State LIFECYCLE_STATE_UNSPECIFIED = type.createAndRegister("LIFECYCLE_STATE_UNSPECIFIED");
5875

5976
/**
6077
* The normal and active state.
6178
*/
62-
ACTIVE,
79+
public static final State ACTIVE = type.createAndRegister("ACTIVE");
6380

6481
/**
6582
* The project has been marked for deletion by the user or by the system (Google Cloud
6683
* Platform). This can generally be reversed by calling {@link ResourceManager#undelete}.
6784
*/
68-
DELETE_REQUESTED,
85+
public static final State DELETE_REQUESTED = type.createAndRegister("DELETE_REQUESTED");
6986

7087
/**
7188
* The process of deleting the project has begun. Reversing the deletion is no longer possible.
7289
*/
73-
DELETE_IN_PROGRESS
90+
public static final State DELETE_IN_PROGRESS = type.createAndRegister("DELETE_IN_PROGRESS");
91+
92+
private State(String constant) {
93+
super(constant);
94+
}
95+
96+
/**
97+
* Get the State for the given String constant, and throw an exception if the constant is
98+
* not recognized.
99+
*/
100+
public static State valueOfStrict(String constant) {
101+
return type.valueOfStrict(constant);
102+
}
103+
104+
/**
105+
* Get the State for the given String constant, and allow unrecognized values.
106+
*/
107+
public static State valueOf(String constant) {
108+
return type.valueOf(constant);
109+
}
110+
111+
/**
112+
* Return the known values for State.
113+
*/
114+
public static State[] values() {
115+
return type.values();
116+
}
74117
}
75118

76119
static class ResourceId implements Serializable {

0 commit comments

Comments
 (0)