• 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.automl.v1beta1;
18 
19 import com.google.api.pathtemplate.PathTemplate;
20 import com.google.api.resourcenames.ResourceName;
21 import com.google.common.base.Preconditions;
22 import com.google.common.collect.ImmutableMap;
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Objects;
27 import javax.annotation.Generated;
28 
29 // AUTO-GENERATED DOCUMENTATION AND CLASS.
30 @Generated("by gapic-generator-java")
31 public class ColumnSpecName implements ResourceName {
32   private static final PathTemplate PROJECT_LOCATION_DATASET_TABLE_SPEC_COLUMN_SPEC =
33       PathTemplate.createWithoutUrlEncoding(
34           "projects/{project}/locations/{location}/datasets/{dataset}/tableSpecs/{table_spec}/columnSpecs/{column_spec}");
35   private volatile Map<String, String> fieldValuesMap;
36   private final String project;
37   private final String location;
38   private final String dataset;
39   private final String tableSpec;
40   private final String columnSpec;
41 
42   @Deprecated
ColumnSpecName()43   protected ColumnSpecName() {
44     project = null;
45     location = null;
46     dataset = null;
47     tableSpec = null;
48     columnSpec = null;
49   }
50 
ColumnSpecName(Builder builder)51   private ColumnSpecName(Builder builder) {
52     project = Preconditions.checkNotNull(builder.getProject());
53     location = Preconditions.checkNotNull(builder.getLocation());
54     dataset = Preconditions.checkNotNull(builder.getDataset());
55     tableSpec = Preconditions.checkNotNull(builder.getTableSpec());
56     columnSpec = Preconditions.checkNotNull(builder.getColumnSpec());
57   }
58 
getProject()59   public String getProject() {
60     return project;
61   }
62 
getLocation()63   public String getLocation() {
64     return location;
65   }
66 
getDataset()67   public String getDataset() {
68     return dataset;
69   }
70 
getTableSpec()71   public String getTableSpec() {
72     return tableSpec;
73   }
74 
getColumnSpec()75   public String getColumnSpec() {
76     return columnSpec;
77   }
78 
newBuilder()79   public static Builder newBuilder() {
80     return new Builder();
81   }
82 
toBuilder()83   public Builder toBuilder() {
84     return new Builder(this);
85   }
86 
of( String project, String location, String dataset, String tableSpec, String columnSpec)87   public static ColumnSpecName of(
88       String project, String location, String dataset, String tableSpec, String columnSpec) {
89     return newBuilder()
90         .setProject(project)
91         .setLocation(location)
92         .setDataset(dataset)
93         .setTableSpec(tableSpec)
94         .setColumnSpec(columnSpec)
95         .build();
96   }
97 
format( String project, String location, String dataset, String tableSpec, String columnSpec)98   public static String format(
99       String project, String location, String dataset, String tableSpec, String columnSpec) {
100     return newBuilder()
101         .setProject(project)
102         .setLocation(location)
103         .setDataset(dataset)
104         .setTableSpec(tableSpec)
105         .setColumnSpec(columnSpec)
106         .build()
107         .toString();
108   }
109 
parse(String formattedString)110   public static ColumnSpecName parse(String formattedString) {
111     if (formattedString.isEmpty()) {
112       return null;
113     }
114     Map<String, String> matchMap =
115         PROJECT_LOCATION_DATASET_TABLE_SPEC_COLUMN_SPEC.validatedMatch(
116             formattedString, "ColumnSpecName.parse: formattedString not in valid format");
117     return of(
118         matchMap.get("project"),
119         matchMap.get("location"),
120         matchMap.get("dataset"),
121         matchMap.get("table_spec"),
122         matchMap.get("column_spec"));
123   }
124 
parseList(List<String> formattedStrings)125   public static List<ColumnSpecName> parseList(List<String> formattedStrings) {
126     List<ColumnSpecName> list = new ArrayList<>(formattedStrings.size());
127     for (String formattedString : formattedStrings) {
128       list.add(parse(formattedString));
129     }
130     return list;
131   }
132 
toStringList(List<ColumnSpecName> values)133   public static List<String> toStringList(List<ColumnSpecName> values) {
134     List<String> list = new ArrayList<>(values.size());
135     for (ColumnSpecName value : values) {
136       if (value == null) {
137         list.add("");
138       } else {
139         list.add(value.toString());
140       }
141     }
142     return list;
143   }
144 
isParsableFrom(String formattedString)145   public static boolean isParsableFrom(String formattedString) {
146     return PROJECT_LOCATION_DATASET_TABLE_SPEC_COLUMN_SPEC.matches(formattedString);
147   }
148 
149   @Override
getFieldValuesMap()150   public Map<String, String> getFieldValuesMap() {
151     if (fieldValuesMap == null) {
152       synchronized (this) {
153         if (fieldValuesMap == null) {
154           ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder();
155           if (project != null) {
156             fieldMapBuilder.put("project", project);
157           }
158           if (location != null) {
159             fieldMapBuilder.put("location", location);
160           }
161           if (dataset != null) {
162             fieldMapBuilder.put("dataset", dataset);
163           }
164           if (tableSpec != null) {
165             fieldMapBuilder.put("table_spec", tableSpec);
166           }
167           if (columnSpec != null) {
168             fieldMapBuilder.put("column_spec", columnSpec);
169           }
170           fieldValuesMap = fieldMapBuilder.build();
171         }
172       }
173     }
174     return fieldValuesMap;
175   }
176 
getFieldValue(String fieldName)177   public String getFieldValue(String fieldName) {
178     return getFieldValuesMap().get(fieldName);
179   }
180 
181   @Override
toString()182   public String toString() {
183     return PROJECT_LOCATION_DATASET_TABLE_SPEC_COLUMN_SPEC.instantiate(
184         "project",
185         project,
186         "location",
187         location,
188         "dataset",
189         dataset,
190         "table_spec",
191         tableSpec,
192         "column_spec",
193         columnSpec);
194   }
195 
196   @Override
equals(Object o)197   public boolean equals(Object o) {
198     if (o == this) {
199       return true;
200     }
201     if (o != null || getClass() == o.getClass()) {
202       ColumnSpecName that = ((ColumnSpecName) o);
203       return Objects.equals(this.project, that.project)
204           && Objects.equals(this.location, that.location)
205           && Objects.equals(this.dataset, that.dataset)
206           && Objects.equals(this.tableSpec, that.tableSpec)
207           && Objects.equals(this.columnSpec, that.columnSpec);
208     }
209     return false;
210   }
211 
212   @Override
hashCode()213   public int hashCode() {
214     int h = 1;
215     h *= 1000003;
216     h ^= Objects.hashCode(project);
217     h *= 1000003;
218     h ^= Objects.hashCode(location);
219     h *= 1000003;
220     h ^= Objects.hashCode(dataset);
221     h *= 1000003;
222     h ^= Objects.hashCode(tableSpec);
223     h *= 1000003;
224     h ^= Objects.hashCode(columnSpec);
225     return h;
226   }
227 
228   /**
229    * Builder for
230    * projects/{project}/locations/{location}/datasets/{dataset}/tableSpecs/{table_spec}/columnSpecs/{column_spec}.
231    */
232   public static class Builder {
233     private String project;
234     private String location;
235     private String dataset;
236     private String tableSpec;
237     private String columnSpec;
238 
Builder()239     protected Builder() {}
240 
getProject()241     public String getProject() {
242       return project;
243     }
244 
getLocation()245     public String getLocation() {
246       return location;
247     }
248 
getDataset()249     public String getDataset() {
250       return dataset;
251     }
252 
getTableSpec()253     public String getTableSpec() {
254       return tableSpec;
255     }
256 
getColumnSpec()257     public String getColumnSpec() {
258       return columnSpec;
259     }
260 
setProject(String project)261     public Builder setProject(String project) {
262       this.project = project;
263       return this;
264     }
265 
setLocation(String location)266     public Builder setLocation(String location) {
267       this.location = location;
268       return this;
269     }
270 
setDataset(String dataset)271     public Builder setDataset(String dataset) {
272       this.dataset = dataset;
273       return this;
274     }
275 
setTableSpec(String tableSpec)276     public Builder setTableSpec(String tableSpec) {
277       this.tableSpec = tableSpec;
278       return this;
279     }
280 
setColumnSpec(String columnSpec)281     public Builder setColumnSpec(String columnSpec) {
282       this.columnSpec = columnSpec;
283       return this;
284     }
285 
Builder(ColumnSpecName columnSpecName)286     private Builder(ColumnSpecName columnSpecName) {
287       this.project = columnSpecName.project;
288       this.location = columnSpecName.location;
289       this.dataset = columnSpecName.dataset;
290       this.tableSpec = columnSpecName.tableSpec;
291       this.columnSpec = columnSpecName.columnSpec;
292     }
293 
build()294     public ColumnSpecName build() {
295       return new ColumnSpecName(this);
296     }
297   }
298 }
299