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