• 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.v1;
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 AnnotationSpecName implements ResourceName {
32   private static final PathTemplate PROJECT_LOCATION_DATASET_ANNOTATION_SPEC =
33       PathTemplate.createWithoutUrlEncoding(
34           "projects/{project}/locations/{location}/datasets/{dataset}/annotationSpecs/{annotation_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 annotationSpec;
40 
41   @Deprecated
AnnotationSpecName()42   protected AnnotationSpecName() {
43     project = null;
44     location = null;
45     dataset = null;
46     annotationSpec = null;
47   }
48 
AnnotationSpecName(Builder builder)49   private AnnotationSpecName(Builder builder) {
50     project = Preconditions.checkNotNull(builder.getProject());
51     location = Preconditions.checkNotNull(builder.getLocation());
52     dataset = Preconditions.checkNotNull(builder.getDataset());
53     annotationSpec = Preconditions.checkNotNull(builder.getAnnotationSpec());
54   }
55 
getProject()56   public String getProject() {
57     return project;
58   }
59 
getLocation()60   public String getLocation() {
61     return location;
62   }
63 
getDataset()64   public String getDataset() {
65     return dataset;
66   }
67 
getAnnotationSpec()68   public String getAnnotationSpec() {
69     return annotationSpec;
70   }
71 
newBuilder()72   public static Builder newBuilder() {
73     return new Builder();
74   }
75 
toBuilder()76   public Builder toBuilder() {
77     return new Builder(this);
78   }
79 
of( String project, String location, String dataset, String annotationSpec)80   public static AnnotationSpecName of(
81       String project, String location, String dataset, String annotationSpec) {
82     return newBuilder()
83         .setProject(project)
84         .setLocation(location)
85         .setDataset(dataset)
86         .setAnnotationSpec(annotationSpec)
87         .build();
88   }
89 
format( String project, String location, String dataset, String annotationSpec)90   public static String format(
91       String project, String location, String dataset, String annotationSpec) {
92     return newBuilder()
93         .setProject(project)
94         .setLocation(location)
95         .setDataset(dataset)
96         .setAnnotationSpec(annotationSpec)
97         .build()
98         .toString();
99   }
100 
parse(String formattedString)101   public static AnnotationSpecName parse(String formattedString) {
102     if (formattedString.isEmpty()) {
103       return null;
104     }
105     Map<String, String> matchMap =
106         PROJECT_LOCATION_DATASET_ANNOTATION_SPEC.validatedMatch(
107             formattedString, "AnnotationSpecName.parse: formattedString not in valid format");
108     return of(
109         matchMap.get("project"),
110         matchMap.get("location"),
111         matchMap.get("dataset"),
112         matchMap.get("annotation_spec"));
113   }
114 
parseList(List<String> formattedStrings)115   public static List<AnnotationSpecName> parseList(List<String> formattedStrings) {
116     List<AnnotationSpecName> list = new ArrayList<>(formattedStrings.size());
117     for (String formattedString : formattedStrings) {
118       list.add(parse(formattedString));
119     }
120     return list;
121   }
122 
toStringList(List<AnnotationSpecName> values)123   public static List<String> toStringList(List<AnnotationSpecName> values) {
124     List<String> list = new ArrayList<>(values.size());
125     for (AnnotationSpecName value : values) {
126       if (value == null) {
127         list.add("");
128       } else {
129         list.add(value.toString());
130       }
131     }
132     return list;
133   }
134 
isParsableFrom(String formattedString)135   public static boolean isParsableFrom(String formattedString) {
136     return PROJECT_LOCATION_DATASET_ANNOTATION_SPEC.matches(formattedString);
137   }
138 
139   @Override
getFieldValuesMap()140   public Map<String, String> getFieldValuesMap() {
141     if (fieldValuesMap == null) {
142       synchronized (this) {
143         if (fieldValuesMap == null) {
144           ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder();
145           if (project != null) {
146             fieldMapBuilder.put("project", project);
147           }
148           if (location != null) {
149             fieldMapBuilder.put("location", location);
150           }
151           if (dataset != null) {
152             fieldMapBuilder.put("dataset", dataset);
153           }
154           if (annotationSpec != null) {
155             fieldMapBuilder.put("annotation_spec", annotationSpec);
156           }
157           fieldValuesMap = fieldMapBuilder.build();
158         }
159       }
160     }
161     return fieldValuesMap;
162   }
163 
getFieldValue(String fieldName)164   public String getFieldValue(String fieldName) {
165     return getFieldValuesMap().get(fieldName);
166   }
167 
168   @Override
toString()169   public String toString() {
170     return PROJECT_LOCATION_DATASET_ANNOTATION_SPEC.instantiate(
171         "project",
172         project,
173         "location",
174         location,
175         "dataset",
176         dataset,
177         "annotation_spec",
178         annotationSpec);
179   }
180 
181   @Override
equals(Object o)182   public boolean equals(Object o) {
183     if (o == this) {
184       return true;
185     }
186     if (o != null || getClass() == o.getClass()) {
187       AnnotationSpecName that = ((AnnotationSpecName) o);
188       return Objects.equals(this.project, that.project)
189           && Objects.equals(this.location, that.location)
190           && Objects.equals(this.dataset, that.dataset)
191           && Objects.equals(this.annotationSpec, that.annotationSpec);
192     }
193     return false;
194   }
195 
196   @Override
hashCode()197   public int hashCode() {
198     int h = 1;
199     h *= 1000003;
200     h ^= Objects.hashCode(project);
201     h *= 1000003;
202     h ^= Objects.hashCode(location);
203     h *= 1000003;
204     h ^= Objects.hashCode(dataset);
205     h *= 1000003;
206     h ^= Objects.hashCode(annotationSpec);
207     return h;
208   }
209 
210   /**
211    * Builder for
212    * projects/{project}/locations/{location}/datasets/{dataset}/annotationSpecs/{annotation_spec}.
213    */
214   public static class Builder {
215     private String project;
216     private String location;
217     private String dataset;
218     private String annotationSpec;
219 
Builder()220     protected Builder() {}
221 
getProject()222     public String getProject() {
223       return project;
224     }
225 
getLocation()226     public String getLocation() {
227       return location;
228     }
229 
getDataset()230     public String getDataset() {
231       return dataset;
232     }
233 
getAnnotationSpec()234     public String getAnnotationSpec() {
235       return annotationSpec;
236     }
237 
setProject(String project)238     public Builder setProject(String project) {
239       this.project = project;
240       return this;
241     }
242 
setLocation(String location)243     public Builder setLocation(String location) {
244       this.location = location;
245       return this;
246     }
247 
setDataset(String dataset)248     public Builder setDataset(String dataset) {
249       this.dataset = dataset;
250       return this;
251     }
252 
setAnnotationSpec(String annotationSpec)253     public Builder setAnnotationSpec(String annotationSpec) {
254       this.annotationSpec = annotationSpec;
255       return this;
256     }
257 
Builder(AnnotationSpecName annotationSpecName)258     private Builder(AnnotationSpecName annotationSpecName) {
259       this.project = annotationSpecName.project;
260       this.location = annotationSpecName.location;
261       this.dataset = annotationSpecName.dataset;
262       this.annotationSpec = annotationSpecName.annotationSpec;
263     }
264 
build()265     public AnnotationSpecName build() {
266       return new AnnotationSpecName(this);
267     }
268   }
269 }
270