This repository has been archived by the owner on Sep 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
DataSourceName.java
316 lines (266 loc) · 10.1 KB
/
DataSourceName.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
/*
* Copyright 2020 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.bigquery.datatransfer.v1;
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;
/** AUTO-GENERATED DOCUMENTATION AND CLASS */
@javax.annotation.Generated("by GAPIC protoc plugin")
public class DataSourceName implements ResourceName {
@Deprecated
protected DataSourceName() {}
private static final PathTemplate PROJECT_DATA_SOURCE_PATH_TEMPLATE =
PathTemplate.createWithoutUrlEncoding("projects/{project}/dataSources/{data_source}");
private static final PathTemplate PROJECT_LOCATION_DATA_SOURCE_PATH_TEMPLATE =
PathTemplate.createWithoutUrlEncoding(
"projects/{project}/locations/{location}/dataSources/{data_source}");
private volatile Map<String, String> fieldValuesMap;
private PathTemplate pathTemplate;
private String fixedValue;
private String project;
private String dataSource;
private String location;
public String getProject() {
return project;
}
public String getDataSource() {
return dataSource;
}
public String getLocation() {
return location;
}
private DataSourceName(Builder builder) {
project = Preconditions.checkNotNull(builder.getProject());
dataSource = Preconditions.checkNotNull(builder.getDataSource());
pathTemplate = PROJECT_DATA_SOURCE_PATH_TEMPLATE;
}
private DataSourceName(ProjectLocationDataSourceBuilder builder) {
project = Preconditions.checkNotNull(builder.getProject());
location = Preconditions.checkNotNull(builder.getLocation());
dataSource = Preconditions.checkNotNull(builder.getDataSource());
pathTemplate = PROJECT_LOCATION_DATA_SOURCE_PATH_TEMPLATE;
}
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 newProjectDataSourceBuilder() {
return new Builder();
}
@BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
public static ProjectLocationDataSourceBuilder newProjectLocationDataSourceBuilder() {
return new ProjectLocationDataSourceBuilder();
}
public Builder toBuilder() {
return new Builder(this);
}
public static DataSourceName of(String project, String dataSource) {
return newProjectDataSourceBuilder().setProject(project).setDataSource(dataSource).build();
}
@BetaApi("The static create methods are not stable yet and may be changed in the future.")
public static DataSourceName ofProjectDataSourceName(String project, String dataSource) {
return newProjectDataSourceBuilder().setProject(project).setDataSource(dataSource).build();
}
@BetaApi("The static create methods are not stable yet and may be changed in the future.")
public static DataSourceName ofProjectLocationDataSourceName(
String project, String location, String dataSource) {
return newProjectLocationDataSourceBuilder()
.setProject(project)
.setLocation(location)
.setDataSource(dataSource)
.build();
}
public static String format(String project, String dataSource) {
return newBuilder().setProject(project).setDataSource(dataSource).build().toString();
}
@BetaApi("The static format methods are not stable yet and may be changed in the future.")
public static String formatProjectDataSourceName(String project, String dataSource) {
return newBuilder().setProject(project).setDataSource(dataSource).build().toString();
}
@BetaApi("The static format methods are not stable yet and may be changed in the future.")
public static String formatProjectLocationDataSourceName(
String project, String location, String dataSource) {
return newProjectLocationDataSourceBuilder()
.setProject(project)
.setLocation(location)
.setDataSource(dataSource)
.build()
.toString();
}
public static DataSourceName parse(String formattedString) {
if (formattedString.isEmpty()) {
return null;
}
if (PROJECT_DATA_SOURCE_PATH_TEMPLATE.matches(formattedString)) {
Map<String, String> matchMap = PROJECT_DATA_SOURCE_PATH_TEMPLATE.match(formattedString);
return ofProjectDataSourceName(matchMap.get("project"), matchMap.get("data_source"));
} else if (PROJECT_LOCATION_DATA_SOURCE_PATH_TEMPLATE.matches(formattedString)) {
Map<String, String> matchMap =
PROJECT_LOCATION_DATA_SOURCE_PATH_TEMPLATE.match(formattedString);
return ofProjectLocationDataSourceName(
matchMap.get("project"), matchMap.get("location"), matchMap.get("data_source"));
}
throw new ValidationException("JobName.parse: formattedString not in valid format");
}
@BetaApi("The method will be renamed to parseList after subclasses of this class are removed.")
public static List<DataSourceName> parse(List<String> formattedStrings) {
List<DataSourceName> list = new ArrayList<>(formattedStrings.size());
for (String formattedString : formattedStrings) {
list.add(parse(formattedString));
}
return list;
}
@BetaApi("The method will be renamed to toStringList after subclasses of this class are removed.")
public static List<String> toStrings(List<DataSourceName> values) {
List<String> list = new ArrayList<>(values.size());
for (DataSourceName value : values) {
if (value == null) {
list.add("");
} else {
list.add(value.toString());
}
}
return list;
}
public static boolean isParsableFrom(String formattedString) {
return PROJECT_DATA_SOURCE_PATH_TEMPLATE.matches(formattedString)
|| PROJECT_LOCATION_DATA_SOURCE_PATH_TEMPLATE.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 (dataSource != null) {
fieldMapBuilder.put("data_source", dataSource);
}
if (location != null) {
fieldMapBuilder.put("location", location);
}
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());
}
/** Builder for projects/{project}/dataSources/{data_source}. */
public static class Builder {
private String project;
private String dataSource;
protected Builder() {}
public String getProject() {
return project;
}
public String getDataSource() {
return dataSource;
}
public Builder setProject(String project) {
this.project = project;
return this;
}
public Builder setDataSource(String dataSource) {
this.dataSource = dataSource;
return this;
}
private Builder(DataSourceName dataSourceName) {
Preconditions.checkArgument(
dataSourceName.pathTemplate == PROJECT_DATA_SOURCE_PATH_TEMPLATE,
"toBuilder is only supported when DataSourceName has the pattern of "
+ "projects/{project}/dataSources/{data_source}.");
project = dataSourceName.project;
dataSource = dataSourceName.dataSource;
}
public DataSourceName build() {
return new DataSourceName(this);
}
}
/** Builder for projects/{project}/locations/{location}/dataSources/{data_source}. */
@BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
public static class ProjectLocationDataSourceBuilder {
private String project;
private String location;
private String dataSource;
private ProjectLocationDataSourceBuilder() {}
public String getProject() {
return project;
}
public String getLocation() {
return location;
}
public String getDataSource() {
return dataSource;
}
public ProjectLocationDataSourceBuilder setProject(String project) {
this.project = project;
return this;
}
public ProjectLocationDataSourceBuilder setLocation(String location) {
this.location = location;
return this;
}
public ProjectLocationDataSourceBuilder setDataSource(String dataSource) {
this.dataSource = dataSource;
return this;
}
public DataSourceName build() {
return new DataSourceName(this);
}
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
DataSourceName that = (DataSourceName) o;
return (Objects.equals(this.project, that.project))
&& (Objects.equals(this.dataSource, that.dataSource))
&& (Objects.equals(this.location, that.location));
}
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(dataSource);
h *= 1000003;
h ^= Objects.hashCode(location);
return h;
}
}