• 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 DataStoreName implements ResourceName {
34   private static final PathTemplate PROJECT_LOCATION_DATA_STORE =
35       PathTemplate.createWithoutUrlEncoding(
36           "projects/{project}/locations/{location}/dataStores/{data_store}");
37   private static final PathTemplate PROJECT_LOCATION_COLLECTION_DATA_STORE =
38       PathTemplate.createWithoutUrlEncoding(
39           "projects/{project}/locations/{location}/collections/{collection}/dataStores/{data_store}");
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 collection;
47 
48   @Deprecated
DataStoreName()49   protected DataStoreName() {
50     project = null;
51     location = null;
52     dataStore = null;
53     collection = null;
54   }
55 
DataStoreName(Builder builder)56   private DataStoreName(Builder builder) {
57     project = Preconditions.checkNotNull(builder.getProject());
58     location = Preconditions.checkNotNull(builder.getLocation());
59     dataStore = Preconditions.checkNotNull(builder.getDataStore());
60     collection = null;
61     pathTemplate = PROJECT_LOCATION_DATA_STORE;
62   }
63 
DataStoreName(ProjectLocationCollectionDataStoreBuilder builder)64   private DataStoreName(ProjectLocationCollectionDataStoreBuilder builder) {
65     project = Preconditions.checkNotNull(builder.getProject());
66     location = Preconditions.checkNotNull(builder.getLocation());
67     collection = Preconditions.checkNotNull(builder.getCollection());
68     dataStore = Preconditions.checkNotNull(builder.getDataStore());
69     pathTemplate = PROJECT_LOCATION_COLLECTION_DATA_STORE;
70   }
71 
getProject()72   public String getProject() {
73     return project;
74   }
75 
getLocation()76   public String getLocation() {
77     return location;
78   }
79 
getDataStore()80   public String getDataStore() {
81     return dataStore;
82   }
83 
getCollection()84   public String getCollection() {
85     return collection;
86   }
87 
newBuilder()88   public static Builder newBuilder() {
89     return new Builder();
90   }
91 
92   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
newProjectLocationDataStoreBuilder()93   public static Builder newProjectLocationDataStoreBuilder() {
94     return new Builder();
95   }
96 
97   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
98   public static ProjectLocationCollectionDataStoreBuilder
newProjectLocationCollectionDataStoreBuilder()99       newProjectLocationCollectionDataStoreBuilder() {
100     return new ProjectLocationCollectionDataStoreBuilder();
101   }
102 
toBuilder()103   public Builder toBuilder() {
104     return new Builder(this);
105   }
106 
of(String project, String location, String dataStore)107   public static DataStoreName of(String project, String location, String dataStore) {
108     return newBuilder().setProject(project).setLocation(location).setDataStore(dataStore).build();
109   }
110 
111   @BetaApi("The static create methods are not stable yet and may be changed in the future.")
ofProjectLocationDataStoreName( String project, String location, String dataStore)112   public static DataStoreName ofProjectLocationDataStoreName(
113       String project, String location, String dataStore) {
114     return newBuilder().setProject(project).setLocation(location).setDataStore(dataStore).build();
115   }
116 
117   @BetaApi("The static create methods are not stable yet and may be changed in the future.")
ofProjectLocationCollectionDataStoreName( String project, String location, String collection, String dataStore)118   public static DataStoreName ofProjectLocationCollectionDataStoreName(
119       String project, String location, String collection, String dataStore) {
120     return newProjectLocationCollectionDataStoreBuilder()
121         .setProject(project)
122         .setLocation(location)
123         .setCollection(collection)
124         .setDataStore(dataStore)
125         .build();
126   }
127 
format(String project, String location, String dataStore)128   public static String format(String project, String location, String dataStore) {
129     return newBuilder()
130         .setProject(project)
131         .setLocation(location)
132         .setDataStore(dataStore)
133         .build()
134         .toString();
135   }
136 
137   @BetaApi("The static format methods are not stable yet and may be changed in the future.")
formatProjectLocationDataStoreName( String project, String location, String dataStore)138   public static String formatProjectLocationDataStoreName(
139       String project, String location, String dataStore) {
140     return newBuilder()
141         .setProject(project)
142         .setLocation(location)
143         .setDataStore(dataStore)
144         .build()
145         .toString();
146   }
147 
148   @BetaApi("The static format methods are not stable yet and may be changed in the future.")
formatProjectLocationCollectionDataStoreName( String project, String location, String collection, String dataStore)149   public static String formatProjectLocationCollectionDataStoreName(
150       String project, String location, String collection, String dataStore) {
151     return newProjectLocationCollectionDataStoreBuilder()
152         .setProject(project)
153         .setLocation(location)
154         .setCollection(collection)
155         .setDataStore(dataStore)
156         .build()
157         .toString();
158   }
159 
parse(String formattedString)160   public static DataStoreName parse(String formattedString) {
161     if (formattedString.isEmpty()) {
162       return null;
163     }
164     if (PROJECT_LOCATION_DATA_STORE.matches(formattedString)) {
165       Map<String, String> matchMap = PROJECT_LOCATION_DATA_STORE.match(formattedString);
166       return ofProjectLocationDataStoreName(
167           matchMap.get("project"), matchMap.get("location"), matchMap.get("data_store"));
168     } else if (PROJECT_LOCATION_COLLECTION_DATA_STORE.matches(formattedString)) {
169       Map<String, String> matchMap = PROJECT_LOCATION_COLLECTION_DATA_STORE.match(formattedString);
170       return ofProjectLocationCollectionDataStoreName(
171           matchMap.get("project"),
172           matchMap.get("location"),
173           matchMap.get("collection"),
174           matchMap.get("data_store"));
175     }
176     throw new ValidationException("DataStoreName.parse: formattedString not in valid format");
177   }
178 
parseList(List<String> formattedStrings)179   public static List<DataStoreName> parseList(List<String> formattedStrings) {
180     List<DataStoreName> list = new ArrayList<>(formattedStrings.size());
181     for (String formattedString : formattedStrings) {
182       list.add(parse(formattedString));
183     }
184     return list;
185   }
186 
toStringList(List<DataStoreName> values)187   public static List<String> toStringList(List<DataStoreName> values) {
188     List<String> list = new ArrayList<>(values.size());
189     for (DataStoreName value : values) {
190       if (value == null) {
191         list.add("");
192       } else {
193         list.add(value.toString());
194       }
195     }
196     return list;
197   }
198 
isParsableFrom(String formattedString)199   public static boolean isParsableFrom(String formattedString) {
200     return PROJECT_LOCATION_DATA_STORE.matches(formattedString)
201         || PROJECT_LOCATION_COLLECTION_DATA_STORE.matches(formattedString);
202   }
203 
204   @Override
getFieldValuesMap()205   public Map<String, String> getFieldValuesMap() {
206     if (fieldValuesMap == null) {
207       synchronized (this) {
208         if (fieldValuesMap == null) {
209           ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder();
210           if (project != null) {
211             fieldMapBuilder.put("project", project);
212           }
213           if (location != null) {
214             fieldMapBuilder.put("location", location);
215           }
216           if (dataStore != null) {
217             fieldMapBuilder.put("data_store", dataStore);
218           }
219           if (collection != null) {
220             fieldMapBuilder.put("collection", collection);
221           }
222           fieldValuesMap = fieldMapBuilder.build();
223         }
224       }
225     }
226     return fieldValuesMap;
227   }
228 
getFieldValue(String fieldName)229   public String getFieldValue(String fieldName) {
230     return getFieldValuesMap().get(fieldName);
231   }
232 
233   @Override
toString()234   public String toString() {
235     return fixedValue != null ? fixedValue : pathTemplate.instantiate(getFieldValuesMap());
236   }
237 
238   @Override
equals(Object o)239   public boolean equals(Object o) {
240     if (o == this) {
241       return true;
242     }
243     if (o != null || getClass() == o.getClass()) {
244       DataStoreName that = ((DataStoreName) o);
245       return Objects.equals(this.project, that.project)
246           && Objects.equals(this.location, that.location)
247           && Objects.equals(this.dataStore, that.dataStore)
248           && Objects.equals(this.collection, that.collection);
249     }
250     return false;
251   }
252 
253   @Override
hashCode()254   public int hashCode() {
255     int h = 1;
256     h *= 1000003;
257     h ^= Objects.hashCode(fixedValue);
258     h *= 1000003;
259     h ^= Objects.hashCode(project);
260     h *= 1000003;
261     h ^= Objects.hashCode(location);
262     h *= 1000003;
263     h ^= Objects.hashCode(dataStore);
264     h *= 1000003;
265     h ^= Objects.hashCode(collection);
266     return h;
267   }
268 
269   /** Builder for projects/{project}/locations/{location}/dataStores/{data_store}. */
270   public static class Builder {
271     private String project;
272     private String location;
273     private String dataStore;
274 
Builder()275     protected Builder() {}
276 
getProject()277     public String getProject() {
278       return project;
279     }
280 
getLocation()281     public String getLocation() {
282       return location;
283     }
284 
getDataStore()285     public String getDataStore() {
286       return dataStore;
287     }
288 
setProject(String project)289     public Builder setProject(String project) {
290       this.project = project;
291       return this;
292     }
293 
setLocation(String location)294     public Builder setLocation(String location) {
295       this.location = location;
296       return this;
297     }
298 
setDataStore(String dataStore)299     public Builder setDataStore(String dataStore) {
300       this.dataStore = dataStore;
301       return this;
302     }
303 
Builder(DataStoreName dataStoreName)304     private Builder(DataStoreName dataStoreName) {
305       Preconditions.checkArgument(
306           Objects.equals(dataStoreName.pathTemplate, PROJECT_LOCATION_DATA_STORE),
307           "toBuilder is only supported when DataStoreName has the pattern of projects/{project}/locations/{location}/dataStores/{data_store}");
308       this.project = dataStoreName.project;
309       this.location = dataStoreName.location;
310       this.dataStore = dataStoreName.dataStore;
311     }
312 
build()313     public DataStoreName build() {
314       return new DataStoreName(this);
315     }
316   }
317 
318   /**
319    * Builder for
320    * projects/{project}/locations/{location}/collections/{collection}/dataStores/{data_store}.
321    */
322   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
323   public static class ProjectLocationCollectionDataStoreBuilder {
324     private String project;
325     private String location;
326     private String collection;
327     private String dataStore;
328 
ProjectLocationCollectionDataStoreBuilder()329     protected ProjectLocationCollectionDataStoreBuilder() {}
330 
getProject()331     public String getProject() {
332       return project;
333     }
334 
getLocation()335     public String getLocation() {
336       return location;
337     }
338 
getCollection()339     public String getCollection() {
340       return collection;
341     }
342 
getDataStore()343     public String getDataStore() {
344       return dataStore;
345     }
346 
setProject(String project)347     public ProjectLocationCollectionDataStoreBuilder setProject(String project) {
348       this.project = project;
349       return this;
350     }
351 
setLocation(String location)352     public ProjectLocationCollectionDataStoreBuilder setLocation(String location) {
353       this.location = location;
354       return this;
355     }
356 
setCollection(String collection)357     public ProjectLocationCollectionDataStoreBuilder setCollection(String collection) {
358       this.collection = collection;
359       return this;
360     }
361 
setDataStore(String dataStore)362     public ProjectLocationCollectionDataStoreBuilder setDataStore(String dataStore) {
363       this.dataStore = dataStore;
364       return this;
365     }
366 
build()367     public DataStoreName build() {
368       return new DataStoreName(this);
369     }
370   }
371 }
372