• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      https://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.cloud.discoveryengine.v1beta;
18 
19 import com.google.api.core.BetaApi;
20 import com.google.api.pathtemplate.PathTemplate;
21 import com.google.api.pathtemplate.ValidationException;
22 import com.google.api.resourcenames.ResourceName;
23 import com.google.common.base.Preconditions;
24 import com.google.common.collect.ImmutableMap;
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Objects;
29 import javax.annotation.Generated;
30 
31 // AUTO-GENERATED DOCUMENTATION AND CLASS.
32 @Generated("by gapic-generator-java")
33 public class DocumentName implements ResourceName {
34   private static final PathTemplate PROJECT_LOCATION_DATA_STORE_BRANCH_DOCUMENT =
35       PathTemplate.createWithoutUrlEncoding(
36           "projects/{project}/locations/{location}/dataStores/{data_store}/branches/{branch}/documents/{document}");
37   private static final PathTemplate PROJECT_LOCATION_COLLECTION_DATA_STORE_BRANCH_DOCUMENT =
38       PathTemplate.createWithoutUrlEncoding(
39           "projects/{project}/locations/{location}/collections/{collection}/dataStores/{data_store}/branches/{branch}/documents/{document}");
40   private volatile Map<String, String> fieldValuesMap;
41   private PathTemplate pathTemplate;
42   private String fixedValue;
43   private final String project;
44   private final String location;
45   private final String dataStore;
46   private final String branch;
47   private final String document;
48   private final String collection;
49 
50   @Deprecated
DocumentName()51   protected DocumentName() {
52     project = null;
53     location = null;
54     dataStore = null;
55     branch = null;
56     document = null;
57     collection = null;
58   }
59 
DocumentName(Builder builder)60   private DocumentName(Builder builder) {
61     project = Preconditions.checkNotNull(builder.getProject());
62     location = Preconditions.checkNotNull(builder.getLocation());
63     dataStore = Preconditions.checkNotNull(builder.getDataStore());
64     branch = Preconditions.checkNotNull(builder.getBranch());
65     document = Preconditions.checkNotNull(builder.getDocument());
66     collection = null;
67     pathTemplate = PROJECT_LOCATION_DATA_STORE_BRANCH_DOCUMENT;
68   }
69 
DocumentName(ProjectLocationCollectionDataStoreBranchDocumentBuilder builder)70   private DocumentName(ProjectLocationCollectionDataStoreBranchDocumentBuilder builder) {
71     project = Preconditions.checkNotNull(builder.getProject());
72     location = Preconditions.checkNotNull(builder.getLocation());
73     collection = Preconditions.checkNotNull(builder.getCollection());
74     dataStore = Preconditions.checkNotNull(builder.getDataStore());
75     branch = Preconditions.checkNotNull(builder.getBranch());
76     document = Preconditions.checkNotNull(builder.getDocument());
77     pathTemplate = PROJECT_LOCATION_COLLECTION_DATA_STORE_BRANCH_DOCUMENT;
78   }
79 
getProject()80   public String getProject() {
81     return project;
82   }
83 
getLocation()84   public String getLocation() {
85     return location;
86   }
87 
getDataStore()88   public String getDataStore() {
89     return dataStore;
90   }
91 
getBranch()92   public String getBranch() {
93     return branch;
94   }
95 
getDocument()96   public String getDocument() {
97     return document;
98   }
99 
getCollection()100   public String getCollection() {
101     return collection;
102   }
103 
newBuilder()104   public static Builder newBuilder() {
105     return new Builder();
106   }
107 
108   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
newProjectLocationDataStoreBranchDocumentBuilder()109   public static Builder newProjectLocationDataStoreBranchDocumentBuilder() {
110     return new Builder();
111   }
112 
113   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
114   public static ProjectLocationCollectionDataStoreBranchDocumentBuilder
newProjectLocationCollectionDataStoreBranchDocumentBuilder()115       newProjectLocationCollectionDataStoreBranchDocumentBuilder() {
116     return new ProjectLocationCollectionDataStoreBranchDocumentBuilder();
117   }
118 
toBuilder()119   public Builder toBuilder() {
120     return new Builder(this);
121   }
122 
of( String project, String location, String dataStore, String branch, String document)123   public static DocumentName of(
124       String project, String location, String dataStore, String branch, String document) {
125     return newBuilder()
126         .setProject(project)
127         .setLocation(location)
128         .setDataStore(dataStore)
129         .setBranch(branch)
130         .setDocument(document)
131         .build();
132   }
133 
134   @BetaApi("The static create methods are not stable yet and may be changed in the future.")
ofProjectLocationDataStoreBranchDocumentName( String project, String location, String dataStore, String branch, String document)135   public static DocumentName ofProjectLocationDataStoreBranchDocumentName(
136       String project, String location, String dataStore, String branch, String document) {
137     return newBuilder()
138         .setProject(project)
139         .setLocation(location)
140         .setDataStore(dataStore)
141         .setBranch(branch)
142         .setDocument(document)
143         .build();
144   }
145 
146   @BetaApi("The static create methods are not stable yet and may be changed in the future.")
ofProjectLocationCollectionDataStoreBranchDocumentName( String project, String location, String collection, String dataStore, String branch, String document)147   public static DocumentName ofProjectLocationCollectionDataStoreBranchDocumentName(
148       String project,
149       String location,
150       String collection,
151       String dataStore,
152       String branch,
153       String document) {
154     return newProjectLocationCollectionDataStoreBranchDocumentBuilder()
155         .setProject(project)
156         .setLocation(location)
157         .setCollection(collection)
158         .setDataStore(dataStore)
159         .setBranch(branch)
160         .setDocument(document)
161         .build();
162   }
163 
format( String project, String location, String dataStore, String branch, String document)164   public static String format(
165       String project, String location, String dataStore, String branch, String document) {
166     return newBuilder()
167         .setProject(project)
168         .setLocation(location)
169         .setDataStore(dataStore)
170         .setBranch(branch)
171         .setDocument(document)
172         .build()
173         .toString();
174   }
175 
176   @BetaApi("The static format methods are not stable yet and may be changed in the future.")
formatProjectLocationDataStoreBranchDocumentName( String project, String location, String dataStore, String branch, String document)177   public static String formatProjectLocationDataStoreBranchDocumentName(
178       String project, String location, String dataStore, String branch, String document) {
179     return newBuilder()
180         .setProject(project)
181         .setLocation(location)
182         .setDataStore(dataStore)
183         .setBranch(branch)
184         .setDocument(document)
185         .build()
186         .toString();
187   }
188 
189   @BetaApi("The static format methods are not stable yet and may be changed in the future.")
formatProjectLocationCollectionDataStoreBranchDocumentName( String project, String location, String collection, String dataStore, String branch, String document)190   public static String formatProjectLocationCollectionDataStoreBranchDocumentName(
191       String project,
192       String location,
193       String collection,
194       String dataStore,
195       String branch,
196       String document) {
197     return newProjectLocationCollectionDataStoreBranchDocumentBuilder()
198         .setProject(project)
199         .setLocation(location)
200         .setCollection(collection)
201         .setDataStore(dataStore)
202         .setBranch(branch)
203         .setDocument(document)
204         .build()
205         .toString();
206   }
207 
parse(String formattedString)208   public static DocumentName parse(String formattedString) {
209     if (formattedString.isEmpty()) {
210       return null;
211     }
212     if (PROJECT_LOCATION_DATA_STORE_BRANCH_DOCUMENT.matches(formattedString)) {
213       Map<String, String> matchMap =
214           PROJECT_LOCATION_DATA_STORE_BRANCH_DOCUMENT.match(formattedString);
215       return ofProjectLocationDataStoreBranchDocumentName(
216           matchMap.get("project"),
217           matchMap.get("location"),
218           matchMap.get("data_store"),
219           matchMap.get("branch"),
220           matchMap.get("document"));
221     } else if (PROJECT_LOCATION_COLLECTION_DATA_STORE_BRANCH_DOCUMENT.matches(formattedString)) {
222       Map<String, String> matchMap =
223           PROJECT_LOCATION_COLLECTION_DATA_STORE_BRANCH_DOCUMENT.match(formattedString);
224       return ofProjectLocationCollectionDataStoreBranchDocumentName(
225           matchMap.get("project"),
226           matchMap.get("location"),
227           matchMap.get("collection"),
228           matchMap.get("data_store"),
229           matchMap.get("branch"),
230           matchMap.get("document"));
231     }
232     throw new ValidationException("DocumentName.parse: formattedString not in valid format");
233   }
234 
parseList(List<String> formattedStrings)235   public static List<DocumentName> parseList(List<String> formattedStrings) {
236     List<DocumentName> list = new ArrayList<>(formattedStrings.size());
237     for (String formattedString : formattedStrings) {
238       list.add(parse(formattedString));
239     }
240     return list;
241   }
242 
toStringList(List<DocumentName> values)243   public static List<String> toStringList(List<DocumentName> values) {
244     List<String> list = new ArrayList<>(values.size());
245     for (DocumentName value : values) {
246       if (value == null) {
247         list.add("");
248       } else {
249         list.add(value.toString());
250       }
251     }
252     return list;
253   }
254 
isParsableFrom(String formattedString)255   public static boolean isParsableFrom(String formattedString) {
256     return PROJECT_LOCATION_DATA_STORE_BRANCH_DOCUMENT.matches(formattedString)
257         || PROJECT_LOCATION_COLLECTION_DATA_STORE_BRANCH_DOCUMENT.matches(formattedString);
258   }
259 
260   @Override
getFieldValuesMap()261   public Map<String, String> getFieldValuesMap() {
262     if (fieldValuesMap == null) {
263       synchronized (this) {
264         if (fieldValuesMap == null) {
265           ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder();
266           if (project != null) {
267             fieldMapBuilder.put("project", project);
268           }
269           if (location != null) {
270             fieldMapBuilder.put("location", location);
271           }
272           if (dataStore != null) {
273             fieldMapBuilder.put("data_store", dataStore);
274           }
275           if (branch != null) {
276             fieldMapBuilder.put("branch", branch);
277           }
278           if (document != null) {
279             fieldMapBuilder.put("document", document);
280           }
281           if (collection != null) {
282             fieldMapBuilder.put("collection", collection);
283           }
284           fieldValuesMap = fieldMapBuilder.build();
285         }
286       }
287     }
288     return fieldValuesMap;
289   }
290 
getFieldValue(String fieldName)291   public String getFieldValue(String fieldName) {
292     return getFieldValuesMap().get(fieldName);
293   }
294 
295   @Override
toString()296   public String toString() {
297     return fixedValue != null ? fixedValue : pathTemplate.instantiate(getFieldValuesMap());
298   }
299 
300   @Override
equals(Object o)301   public boolean equals(Object o) {
302     if (o == this) {
303       return true;
304     }
305     if (o != null || getClass() == o.getClass()) {
306       DocumentName that = ((DocumentName) o);
307       return Objects.equals(this.project, that.project)
308           && Objects.equals(this.location, that.location)
309           && Objects.equals(this.dataStore, that.dataStore)
310           && Objects.equals(this.branch, that.branch)
311           && Objects.equals(this.document, that.document)
312           && Objects.equals(this.collection, that.collection);
313     }
314     return false;
315   }
316 
317   @Override
hashCode()318   public int hashCode() {
319     int h = 1;
320     h *= 1000003;
321     h ^= Objects.hashCode(fixedValue);
322     h *= 1000003;
323     h ^= Objects.hashCode(project);
324     h *= 1000003;
325     h ^= Objects.hashCode(location);
326     h *= 1000003;
327     h ^= Objects.hashCode(dataStore);
328     h *= 1000003;
329     h ^= Objects.hashCode(branch);
330     h *= 1000003;
331     h ^= Objects.hashCode(document);
332     h *= 1000003;
333     h ^= Objects.hashCode(collection);
334     return h;
335   }
336 
337   /**
338    * Builder for
339    * projects/{project}/locations/{location}/dataStores/{data_store}/branches/{branch}/documents/{document}.
340    */
341   public static class Builder {
342     private String project;
343     private String location;
344     private String dataStore;
345     private String branch;
346     private String document;
347 
Builder()348     protected Builder() {}
349 
getProject()350     public String getProject() {
351       return project;
352     }
353 
getLocation()354     public String getLocation() {
355       return location;
356     }
357 
getDataStore()358     public String getDataStore() {
359       return dataStore;
360     }
361 
getBranch()362     public String getBranch() {
363       return branch;
364     }
365 
getDocument()366     public String getDocument() {
367       return document;
368     }
369 
setProject(String project)370     public Builder setProject(String project) {
371       this.project = project;
372       return this;
373     }
374 
setLocation(String location)375     public Builder setLocation(String location) {
376       this.location = location;
377       return this;
378     }
379 
setDataStore(String dataStore)380     public Builder setDataStore(String dataStore) {
381       this.dataStore = dataStore;
382       return this;
383     }
384 
setBranch(String branch)385     public Builder setBranch(String branch) {
386       this.branch = branch;
387       return this;
388     }
389 
setDocument(String document)390     public Builder setDocument(String document) {
391       this.document = document;
392       return this;
393     }
394 
Builder(DocumentName documentName)395     private Builder(DocumentName documentName) {
396       Preconditions.checkArgument(
397           Objects.equals(documentName.pathTemplate, PROJECT_LOCATION_DATA_STORE_BRANCH_DOCUMENT),
398           "toBuilder is only supported when DocumentName has the pattern of projects/{project}/locations/{location}/dataStores/{data_store}/branches/{branch}/documents/{document}");
399       this.project = documentName.project;
400       this.location = documentName.location;
401       this.dataStore = documentName.dataStore;
402       this.branch = documentName.branch;
403       this.document = documentName.document;
404     }
405 
build()406     public DocumentName build() {
407       return new DocumentName(this);
408     }
409   }
410 
411   /**
412    * Builder for
413    * projects/{project}/locations/{location}/collections/{collection}/dataStores/{data_store}/branches/{branch}/documents/{document}.
414    */
415   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
416   public static class ProjectLocationCollectionDataStoreBranchDocumentBuilder {
417     private String project;
418     private String location;
419     private String collection;
420     private String dataStore;
421     private String branch;
422     private String document;
423 
ProjectLocationCollectionDataStoreBranchDocumentBuilder()424     protected ProjectLocationCollectionDataStoreBranchDocumentBuilder() {}
425 
getProject()426     public String getProject() {
427       return project;
428     }
429 
getLocation()430     public String getLocation() {
431       return location;
432     }
433 
getCollection()434     public String getCollection() {
435       return collection;
436     }
437 
getDataStore()438     public String getDataStore() {
439       return dataStore;
440     }
441 
getBranch()442     public String getBranch() {
443       return branch;
444     }
445 
getDocument()446     public String getDocument() {
447       return document;
448     }
449 
setProject(String project)450     public ProjectLocationCollectionDataStoreBranchDocumentBuilder setProject(String project) {
451       this.project = project;
452       return this;
453     }
454 
setLocation(String location)455     public ProjectLocationCollectionDataStoreBranchDocumentBuilder setLocation(String location) {
456       this.location = location;
457       return this;
458     }
459 
setCollection( String collection)460     public ProjectLocationCollectionDataStoreBranchDocumentBuilder setCollection(
461         String collection) {
462       this.collection = collection;
463       return this;
464     }
465 
setDataStore(String dataStore)466     public ProjectLocationCollectionDataStoreBranchDocumentBuilder setDataStore(String dataStore) {
467       this.dataStore = dataStore;
468       return this;
469     }
470 
setBranch(String branch)471     public ProjectLocationCollectionDataStoreBranchDocumentBuilder setBranch(String branch) {
472       this.branch = branch;
473       return this;
474     }
475 
setDocument(String document)476     public ProjectLocationCollectionDataStoreBranchDocumentBuilder setDocument(String document) {
477       this.document = document;
478       return this;
479     }
480 
build()481     public DocumentName build() {
482       return new DocumentName(this);
483     }
484   }
485 }
486