-
Notifications
You must be signed in to change notification settings - Fork 37
/
LinkName.java
627 lines (542 loc) · 18.1 KB
/
LinkName.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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
/*
* Copyright 2024 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.logging.v2;
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 LinkName implements ResourceName {
private static final PathTemplate PROJECT_LOCATION_BUCKET_LINK =
PathTemplate.createWithoutUrlEncoding(
"projects/{project}/locations/{location}/buckets/{bucket}/links/{link}");
private static final PathTemplate ORGANIZATION_LOCATION_BUCKET_LINK =
PathTemplate.createWithoutUrlEncoding(
"organizations/{organization}/locations/{location}/buckets/{bucket}/links/{link}");
private static final PathTemplate FOLDER_LOCATION_BUCKET_LINK =
PathTemplate.createWithoutUrlEncoding(
"folders/{folder}/locations/{location}/buckets/{bucket}/links/{link}");
private static final PathTemplate BILLING_ACCOUNT_LOCATION_BUCKET_LINK =
PathTemplate.createWithoutUrlEncoding(
"billingAccounts/{billing_account}/locations/{location}/buckets/{bucket}/links/{link}");
private volatile Map<String, String> fieldValuesMap;
private PathTemplate pathTemplate;
private String fixedValue;
private final String project;
private final String location;
private final String bucket;
private final String link;
private final String organization;
private final String folder;
private final String billingAccount;
@Deprecated
protected LinkName() {
project = null;
location = null;
bucket = null;
link = null;
organization = null;
folder = null;
billingAccount = null;
}
private LinkName(Builder builder) {
project = Preconditions.checkNotNull(builder.getProject());
location = Preconditions.checkNotNull(builder.getLocation());
bucket = Preconditions.checkNotNull(builder.getBucket());
link = Preconditions.checkNotNull(builder.getLink());
organization = null;
folder = null;
billingAccount = null;
pathTemplate = PROJECT_LOCATION_BUCKET_LINK;
}
private LinkName(OrganizationLocationBucketLinkBuilder builder) {
organization = Preconditions.checkNotNull(builder.getOrganization());
location = Preconditions.checkNotNull(builder.getLocation());
bucket = Preconditions.checkNotNull(builder.getBucket());
link = Preconditions.checkNotNull(builder.getLink());
project = null;
folder = null;
billingAccount = null;
pathTemplate = ORGANIZATION_LOCATION_BUCKET_LINK;
}
private LinkName(FolderLocationBucketLinkBuilder builder) {
folder = Preconditions.checkNotNull(builder.getFolder());
location = Preconditions.checkNotNull(builder.getLocation());
bucket = Preconditions.checkNotNull(builder.getBucket());
link = Preconditions.checkNotNull(builder.getLink());
project = null;
organization = null;
billingAccount = null;
pathTemplate = FOLDER_LOCATION_BUCKET_LINK;
}
private LinkName(BillingAccountLocationBucketLinkBuilder builder) {
billingAccount = Preconditions.checkNotNull(builder.getBillingAccount());
location = Preconditions.checkNotNull(builder.getLocation());
bucket = Preconditions.checkNotNull(builder.getBucket());
link = Preconditions.checkNotNull(builder.getLink());
project = null;
organization = null;
folder = null;
pathTemplate = BILLING_ACCOUNT_LOCATION_BUCKET_LINK;
}
public String getProject() {
return project;
}
public String getLocation() {
return location;
}
public String getBucket() {
return bucket;
}
public String getLink() {
return link;
}
public String getOrganization() {
return organization;
}
public String getFolder() {
return folder;
}
public String getBillingAccount() {
return billingAccount;
}
public static Builder newBuilder() {
return new Builder();
}
public static Builder newProjectLocationBucketLinkBuilder() {
return new Builder();
}
public static OrganizationLocationBucketLinkBuilder newOrganizationLocationBucketLinkBuilder() {
return new OrganizationLocationBucketLinkBuilder();
}
public static FolderLocationBucketLinkBuilder newFolderLocationBucketLinkBuilder() {
return new FolderLocationBucketLinkBuilder();
}
public static BillingAccountLocationBucketLinkBuilder
newBillingAccountLocationBucketLinkBuilder() {
return new BillingAccountLocationBucketLinkBuilder();
}
public Builder toBuilder() {
return new Builder(this);
}
public static LinkName of(String project, String location, String bucket, String link) {
return newBuilder()
.setProject(project)
.setLocation(location)
.setBucket(bucket)
.setLink(link)
.build();
}
public static LinkName ofProjectLocationBucketLinkName(
String project, String location, String bucket, String link) {
return newBuilder()
.setProject(project)
.setLocation(location)
.setBucket(bucket)
.setLink(link)
.build();
}
public static LinkName ofOrganizationLocationBucketLinkName(
String organization, String location, String bucket, String link) {
return newOrganizationLocationBucketLinkBuilder()
.setOrganization(organization)
.setLocation(location)
.setBucket(bucket)
.setLink(link)
.build();
}
public static LinkName ofFolderLocationBucketLinkName(
String folder, String location, String bucket, String link) {
return newFolderLocationBucketLinkBuilder()
.setFolder(folder)
.setLocation(location)
.setBucket(bucket)
.setLink(link)
.build();
}
public static LinkName ofBillingAccountLocationBucketLinkName(
String billingAccount, String location, String bucket, String link) {
return newBillingAccountLocationBucketLinkBuilder()
.setBillingAccount(billingAccount)
.setLocation(location)
.setBucket(bucket)
.setLink(link)
.build();
}
public static String format(String project, String location, String bucket, String link) {
return newBuilder()
.setProject(project)
.setLocation(location)
.setBucket(bucket)
.setLink(link)
.build()
.toString();
}
public static String formatProjectLocationBucketLinkName(
String project, String location, String bucket, String link) {
return newBuilder()
.setProject(project)
.setLocation(location)
.setBucket(bucket)
.setLink(link)
.build()
.toString();
}
public static String formatOrganizationLocationBucketLinkName(
String organization, String location, String bucket, String link) {
return newOrganizationLocationBucketLinkBuilder()
.setOrganization(organization)
.setLocation(location)
.setBucket(bucket)
.setLink(link)
.build()
.toString();
}
public static String formatFolderLocationBucketLinkName(
String folder, String location, String bucket, String link) {
return newFolderLocationBucketLinkBuilder()
.setFolder(folder)
.setLocation(location)
.setBucket(bucket)
.setLink(link)
.build()
.toString();
}
public static String formatBillingAccountLocationBucketLinkName(
String billingAccount, String location, String bucket, String link) {
return newBillingAccountLocationBucketLinkBuilder()
.setBillingAccount(billingAccount)
.setLocation(location)
.setBucket(bucket)
.setLink(link)
.build()
.toString();
}
public static LinkName parse(String formattedString) {
if (formattedString.isEmpty()) {
return null;
}
if (PROJECT_LOCATION_BUCKET_LINK.matches(formattedString)) {
Map<String, String> matchMap = PROJECT_LOCATION_BUCKET_LINK.match(formattedString);
return ofProjectLocationBucketLinkName(
matchMap.get("project"),
matchMap.get("location"),
matchMap.get("bucket"),
matchMap.get("link"));
} else if (ORGANIZATION_LOCATION_BUCKET_LINK.matches(formattedString)) {
Map<String, String> matchMap = ORGANIZATION_LOCATION_BUCKET_LINK.match(formattedString);
return ofOrganizationLocationBucketLinkName(
matchMap.get("organization"),
matchMap.get("location"),
matchMap.get("bucket"),
matchMap.get("link"));
} else if (FOLDER_LOCATION_BUCKET_LINK.matches(formattedString)) {
Map<String, String> matchMap = FOLDER_LOCATION_BUCKET_LINK.match(formattedString);
return ofFolderLocationBucketLinkName(
matchMap.get("folder"),
matchMap.get("location"),
matchMap.get("bucket"),
matchMap.get("link"));
} else if (BILLING_ACCOUNT_LOCATION_BUCKET_LINK.matches(formattedString)) {
Map<String, String> matchMap = BILLING_ACCOUNT_LOCATION_BUCKET_LINK.match(formattedString);
return ofBillingAccountLocationBucketLinkName(
matchMap.get("billing_account"),
matchMap.get("location"),
matchMap.get("bucket"),
matchMap.get("link"));
}
throw new ValidationException("LinkName.parse: formattedString not in valid format");
}
public static List<LinkName> parseList(List<String> formattedStrings) {
List<LinkName> list = new ArrayList<>(formattedStrings.size());
for (String formattedString : formattedStrings) {
list.add(parse(formattedString));
}
return list;
}
public static List<String> toStringList(List<LinkName> values) {
List<String> list = new ArrayList<>(values.size());
for (LinkName value : values) {
if (value == null) {
list.add("");
} else {
list.add(value.toString());
}
}
return list;
}
public static boolean isParsableFrom(String formattedString) {
return PROJECT_LOCATION_BUCKET_LINK.matches(formattedString)
|| ORGANIZATION_LOCATION_BUCKET_LINK.matches(formattedString)
|| FOLDER_LOCATION_BUCKET_LINK.matches(formattedString)
|| BILLING_ACCOUNT_LOCATION_BUCKET_LINK.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 (bucket != null) {
fieldMapBuilder.put("bucket", bucket);
}
if (link != null) {
fieldMapBuilder.put("link", link);
}
if (organization != null) {
fieldMapBuilder.put("organization", organization);
}
if (folder != null) {
fieldMapBuilder.put("folder", folder);
}
if (billingAccount != null) {
fieldMapBuilder.put("billing_account", billingAccount);
}
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()) {
LinkName that = ((LinkName) o);
return Objects.equals(this.project, that.project)
&& Objects.equals(this.location, that.location)
&& Objects.equals(this.bucket, that.bucket)
&& Objects.equals(this.link, that.link)
&& Objects.equals(this.organization, that.organization)
&& Objects.equals(this.folder, that.folder)
&& Objects.equals(this.billingAccount, that.billingAccount);
}
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(bucket);
h *= 1000003;
h ^= Objects.hashCode(link);
h *= 1000003;
h ^= Objects.hashCode(organization);
h *= 1000003;
h ^= Objects.hashCode(folder);
h *= 1000003;
h ^= Objects.hashCode(billingAccount);
return h;
}
/** Builder for projects/{project}/locations/{location}/buckets/{bucket}/links/{link}. */
public static class Builder {
private String project;
private String location;
private String bucket;
private String link;
protected Builder() {}
public String getProject() {
return project;
}
public String getLocation() {
return location;
}
public String getBucket() {
return bucket;
}
public String getLink() {
return link;
}
public Builder setProject(String project) {
this.project = project;
return this;
}
public Builder setLocation(String location) {
this.location = location;
return this;
}
public Builder setBucket(String bucket) {
this.bucket = bucket;
return this;
}
public Builder setLink(String link) {
this.link = link;
return this;
}
private Builder(LinkName linkName) {
Preconditions.checkArgument(
Objects.equals(linkName.pathTemplate, PROJECT_LOCATION_BUCKET_LINK),
"toBuilder is only supported when LinkName has the pattern of projects/{project}/locations/{location}/buckets/{bucket}/links/{link}");
this.project = linkName.project;
this.location = linkName.location;
this.bucket = linkName.bucket;
this.link = linkName.link;
}
public LinkName build() {
return new LinkName(this);
}
}
/**
* Builder for organizations/{organization}/locations/{location}/buckets/{bucket}/links/{link}.
*/
public static class OrganizationLocationBucketLinkBuilder {
private String organization;
private String location;
private String bucket;
private String link;
protected OrganizationLocationBucketLinkBuilder() {}
public String getOrganization() {
return organization;
}
public String getLocation() {
return location;
}
public String getBucket() {
return bucket;
}
public String getLink() {
return link;
}
public OrganizationLocationBucketLinkBuilder setOrganization(String organization) {
this.organization = organization;
return this;
}
public OrganizationLocationBucketLinkBuilder setLocation(String location) {
this.location = location;
return this;
}
public OrganizationLocationBucketLinkBuilder setBucket(String bucket) {
this.bucket = bucket;
return this;
}
public OrganizationLocationBucketLinkBuilder setLink(String link) {
this.link = link;
return this;
}
public LinkName build() {
return new LinkName(this);
}
}
/** Builder for folders/{folder}/locations/{location}/buckets/{bucket}/links/{link}. */
public static class FolderLocationBucketLinkBuilder {
private String folder;
private String location;
private String bucket;
private String link;
protected FolderLocationBucketLinkBuilder() {}
public String getFolder() {
return folder;
}
public String getLocation() {
return location;
}
public String getBucket() {
return bucket;
}
public String getLink() {
return link;
}
public FolderLocationBucketLinkBuilder setFolder(String folder) {
this.folder = folder;
return this;
}
public FolderLocationBucketLinkBuilder setLocation(String location) {
this.location = location;
return this;
}
public FolderLocationBucketLinkBuilder setBucket(String bucket) {
this.bucket = bucket;
return this;
}
public FolderLocationBucketLinkBuilder setLink(String link) {
this.link = link;
return this;
}
public LinkName build() {
return new LinkName(this);
}
}
/**
* Builder for
* billingAccounts/{billing_account}/locations/{location}/buckets/{bucket}/links/{link}.
*/
public static class BillingAccountLocationBucketLinkBuilder {
private String billingAccount;
private String location;
private String bucket;
private String link;
protected BillingAccountLocationBucketLinkBuilder() {}
public String getBillingAccount() {
return billingAccount;
}
public String getLocation() {
return location;
}
public String getBucket() {
return bucket;
}
public String getLink() {
return link;
}
public BillingAccountLocationBucketLinkBuilder setBillingAccount(String billingAccount) {
this.billingAccount = billingAccount;
return this;
}
public BillingAccountLocationBucketLinkBuilder setLocation(String location) {
this.location = location;
return this;
}
public BillingAccountLocationBucketLinkBuilder setBucket(String bucket) {
this.bucket = bucket;
return this;
}
public BillingAccountLocationBucketLinkBuilder setLink(String link) {
this.link = link;
return this;
}
public LinkName build() {
return new LinkName(this);
}
}
}