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