This repository has been archived by the owner on Sep 16, 2023. It is now read-only.
/
AutoscalingPolicyName.java
364 lines (316 loc) · 11.7 KB
/
AutoscalingPolicyName.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.dataproc.v1beta2;
import com.google.api.core.BetaApi;
import com.google.api.pathtemplate.PathTemplate;
import com.google.api.pathtemplate.ValidationException;
import com.google.api.resourcenames.ResourceName;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import javax.annotation.Generated;
// AUTO-GENERATED DOCUMENTATION AND CLASS.
@Generated("by gapic-generator-java")
public class AutoscalingPolicyName implements ResourceName {
private static final PathTemplate PROJECT_LOCATION_AUTOSCALING_POLICY =
PathTemplate.createWithoutUrlEncoding(
"projects/{project}/locations/{location}/autoscalingPolicies/{autoscaling_policy}");
private static final PathTemplate PROJECT_REGION_AUTOSCALING_POLICY =
PathTemplate.createWithoutUrlEncoding(
"projects/{project}/regions/{region}/autoscalingPolicies/{autoscaling_policy}");
private volatile Map<String, String> fieldValuesMap;
private PathTemplate pathTemplate;
private String fixedValue;
private final String project;
private final String location;
private final String autoscalingPolicy;
private final String region;
@Deprecated
protected AutoscalingPolicyName() {
project = null;
location = null;
autoscalingPolicy = null;
region = null;
}
private AutoscalingPolicyName(Builder builder) {
project = Preconditions.checkNotNull(builder.getProject());
location = Preconditions.checkNotNull(builder.getLocation());
autoscalingPolicy = Preconditions.checkNotNull(builder.getAutoscalingPolicy());
region = null;
pathTemplate = PROJECT_LOCATION_AUTOSCALING_POLICY;
}
private AutoscalingPolicyName(ProjectRegionAutoscalingPolicyBuilder builder) {
project = Preconditions.checkNotNull(builder.getProject());
region = Preconditions.checkNotNull(builder.getRegion());
autoscalingPolicy = Preconditions.checkNotNull(builder.getAutoscalingPolicy());
location = null;
pathTemplate = PROJECT_REGION_AUTOSCALING_POLICY;
}
public String getProject() {
return project;
}
public String getLocation() {
return location;
}
public String getAutoscalingPolicy() {
return autoscalingPolicy;
}
public String getRegion() {
return region;
}
public static Builder newBuilder() {
return new Builder();
}
@BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
public static Builder newProjectLocationAutoscalingPolicyBuilder() {
return new Builder();
}
@BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
public static ProjectRegionAutoscalingPolicyBuilder newProjectRegionAutoscalingPolicyBuilder() {
return new ProjectRegionAutoscalingPolicyBuilder();
}
public Builder toBuilder() {
return new Builder(this);
}
public static AutoscalingPolicyName of(
String project, String location, String autoscalingPolicy) {
return newBuilder()
.setProject(project)
.setLocation(location)
.setAutoscalingPolicy(autoscalingPolicy)
.build();
}
@BetaApi("The static create methods are not stable yet and may be changed in the future.")
public static AutoscalingPolicyName ofProjectLocationAutoscalingPolicyName(
String project, String location, String autoscalingPolicy) {
return newBuilder()
.setProject(project)
.setLocation(location)
.setAutoscalingPolicy(autoscalingPolicy)
.build();
}
@BetaApi("The static create methods are not stable yet and may be changed in the future.")
public static AutoscalingPolicyName ofProjectRegionAutoscalingPolicyName(
String project, String region, String autoscalingPolicy) {
return newProjectRegionAutoscalingPolicyBuilder()
.setProject(project)
.setRegion(region)
.setAutoscalingPolicy(autoscalingPolicy)
.build();
}
public static String format(String project, String location, String autoscalingPolicy) {
return newBuilder()
.setProject(project)
.setLocation(location)
.setAutoscalingPolicy(autoscalingPolicy)
.build()
.toString();
}
@BetaApi("The static format methods are not stable yet and may be changed in the future.")
public static String formatProjectLocationAutoscalingPolicyName(
String project, String location, String autoscalingPolicy) {
return newBuilder()
.setProject(project)
.setLocation(location)
.setAutoscalingPolicy(autoscalingPolicy)
.build()
.toString();
}
@BetaApi("The static format methods are not stable yet and may be changed in the future.")
public static String formatProjectRegionAutoscalingPolicyName(
String project, String region, String autoscalingPolicy) {
return newProjectRegionAutoscalingPolicyBuilder()
.setProject(project)
.setRegion(region)
.setAutoscalingPolicy(autoscalingPolicy)
.build()
.toString();
}
public static AutoscalingPolicyName parse(String formattedString) {
if (formattedString.isEmpty()) {
return null;
}
if (PROJECT_LOCATION_AUTOSCALING_POLICY.matches(formattedString)) {
Map<String, String> matchMap = PROJECT_LOCATION_AUTOSCALING_POLICY.match(formattedString);
return ofProjectLocationAutoscalingPolicyName(
matchMap.get("project"), matchMap.get("location"), matchMap.get("autoscaling_policy"));
} else if (PROJECT_REGION_AUTOSCALING_POLICY.matches(formattedString)) {
Map<String, String> matchMap = PROJECT_REGION_AUTOSCALING_POLICY.match(formattedString);
return ofProjectRegionAutoscalingPolicyName(
matchMap.get("project"), matchMap.get("region"), matchMap.get("autoscaling_policy"));
}
throw new ValidationException(
"AutoscalingPolicyName.parse: formattedString not in valid format");
}
public static List<AutoscalingPolicyName> parseList(List<String> formattedStrings) {
List<AutoscalingPolicyName> list = new ArrayList<>(formattedStrings.size());
for (String formattedString : formattedStrings) {
list.add(parse(formattedString));
}
return list;
}
public static List<String> toStringList(List<AutoscalingPolicyName> values) {
List<String> list = new ArrayList<>(values.size());
for (AutoscalingPolicyName value : values) {
if (value == null) {
list.add("");
} else {
list.add(value.toString());
}
}
return list;
}
public static boolean isParsableFrom(String formattedString) {
return PROJECT_LOCATION_AUTOSCALING_POLICY.matches(formattedString)
|| PROJECT_REGION_AUTOSCALING_POLICY.matches(formattedString);
}
@Override
public Map<String, String> getFieldValuesMap() {
if (fieldValuesMap == null) {
synchronized (this) {
if (fieldValuesMap == null) {
ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder();
if (project != null) {
fieldMapBuilder.put("project", project);
}
if (location != null) {
fieldMapBuilder.put("location", location);
}
if (autoscalingPolicy != null) {
fieldMapBuilder.put("autoscaling_policy", autoscalingPolicy);
}
if (region != null) {
fieldMapBuilder.put("region", region);
}
fieldValuesMap = fieldMapBuilder.build();
}
}
}
return fieldValuesMap;
}
public String getFieldValue(String fieldName) {
return getFieldValuesMap().get(fieldName);
}
@Override
public String toString() {
return fixedValue != null ? fixedValue : pathTemplate.instantiate(getFieldValuesMap());
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
AutoscalingPolicyName that = ((AutoscalingPolicyName) o);
return Objects.equals(this.project, that.project)
&& Objects.equals(this.location, that.location)
&& Objects.equals(this.autoscalingPolicy, that.autoscalingPolicy)
&& Objects.equals(this.region, that.region);
}
return false;
}
@Override
public int hashCode() {
int h = 1;
h *= 1000003;
h ^= Objects.hashCode(fixedValue);
h *= 1000003;
h ^= Objects.hashCode(project);
h *= 1000003;
h ^= Objects.hashCode(location);
h *= 1000003;
h ^= Objects.hashCode(autoscalingPolicy);
h *= 1000003;
h ^= Objects.hashCode(region);
return h;
}
/**
* Builder for projects/{project}/locations/{location}/autoscalingPolicies/{autoscaling_policy}.
*/
public static class Builder {
private String project;
private String location;
private String autoscalingPolicy;
protected Builder() {}
public String getProject() {
return project;
}
public String getLocation() {
return location;
}
public String getAutoscalingPolicy() {
return autoscalingPolicy;
}
public Builder setProject(String project) {
this.project = project;
return this;
}
public Builder setLocation(String location) {
this.location = location;
return this;
}
public Builder setAutoscalingPolicy(String autoscalingPolicy) {
this.autoscalingPolicy = autoscalingPolicy;
return this;
}
private Builder(AutoscalingPolicyName autoscalingPolicyName) {
Preconditions.checkArgument(
Objects.equals(autoscalingPolicyName.pathTemplate, PROJECT_LOCATION_AUTOSCALING_POLICY),
"toBuilder is only supported when AutoscalingPolicyName has the pattern of projects/{project}/locations/{location}/autoscalingPolicies/{autoscaling_policy}");
this.project = autoscalingPolicyName.project;
this.location = autoscalingPolicyName.location;
this.autoscalingPolicy = autoscalingPolicyName.autoscalingPolicy;
}
public AutoscalingPolicyName build() {
return new AutoscalingPolicyName(this);
}
}
/** Builder for projects/{project}/regions/{region}/autoscalingPolicies/{autoscaling_policy}. */
@BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
public static class ProjectRegionAutoscalingPolicyBuilder {
private String project;
private String region;
private String autoscalingPolicy;
protected ProjectRegionAutoscalingPolicyBuilder() {}
public String getProject() {
return project;
}
public String getRegion() {
return region;
}
public String getAutoscalingPolicy() {
return autoscalingPolicy;
}
public ProjectRegionAutoscalingPolicyBuilder setProject(String project) {
this.project = project;
return this;
}
public ProjectRegionAutoscalingPolicyBuilder setRegion(String region) {
this.region = region;
return this;
}
public ProjectRegionAutoscalingPolicyBuilder setAutoscalingPolicy(String autoscalingPolicy) {
this.autoscalingPolicy = autoscalingPolicy;
return this;
}
public AutoscalingPolicyName build() {
return new AutoscalingPolicyName(this);
}
}
}