• 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 ModelEvaluationName implements ResourceName {
32   private static final PathTemplate PROJECT_LOCATION_MODEL_MODEL_EVALUATION =
33       PathTemplate.createWithoutUrlEncoding(
34           "projects/{project}/locations/{location}/models/{model}/modelEvaluations/{model_evaluation}");
35   private volatile Map<String, String> fieldValuesMap;
36   private final String project;
37   private final String location;
38   private final String model;
39   private final String modelEvaluation;
40 
41   @Deprecated
ModelEvaluationName()42   protected ModelEvaluationName() {
43     project = null;
44     location = null;
45     model = null;
46     modelEvaluation = null;
47   }
48 
ModelEvaluationName(Builder builder)49   private ModelEvaluationName(Builder builder) {
50     project = Preconditions.checkNotNull(builder.getProject());
51     location = Preconditions.checkNotNull(builder.getLocation());
52     model = Preconditions.checkNotNull(builder.getModel());
53     modelEvaluation = Preconditions.checkNotNull(builder.getModelEvaluation());
54   }
55 
getProject()56   public String getProject() {
57     return project;
58   }
59 
getLocation()60   public String getLocation() {
61     return location;
62   }
63 
getModel()64   public String getModel() {
65     return model;
66   }
67 
getModelEvaluation()68   public String getModelEvaluation() {
69     return modelEvaluation;
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 model, String modelEvaluation)80   public static ModelEvaluationName of(
81       String project, String location, String model, String modelEvaluation) {
82     return newBuilder()
83         .setProject(project)
84         .setLocation(location)
85         .setModel(model)
86         .setModelEvaluation(modelEvaluation)
87         .build();
88   }
89 
format( String project, String location, String model, String modelEvaluation)90   public static String format(
91       String project, String location, String model, String modelEvaluation) {
92     return newBuilder()
93         .setProject(project)
94         .setLocation(location)
95         .setModel(model)
96         .setModelEvaluation(modelEvaluation)
97         .build()
98         .toString();
99   }
100 
parse(String formattedString)101   public static ModelEvaluationName parse(String formattedString) {
102     if (formattedString.isEmpty()) {
103       return null;
104     }
105     Map<String, String> matchMap =
106         PROJECT_LOCATION_MODEL_MODEL_EVALUATION.validatedMatch(
107             formattedString, "ModelEvaluationName.parse: formattedString not in valid format");
108     return of(
109         matchMap.get("project"),
110         matchMap.get("location"),
111         matchMap.get("model"),
112         matchMap.get("model_evaluation"));
113   }
114 
parseList(List<String> formattedStrings)115   public static List<ModelEvaluationName> parseList(List<String> formattedStrings) {
116     List<ModelEvaluationName> list = new ArrayList<>(formattedStrings.size());
117     for (String formattedString : formattedStrings) {
118       list.add(parse(formattedString));
119     }
120     return list;
121   }
122 
toStringList(List<ModelEvaluationName> values)123   public static List<String> toStringList(List<ModelEvaluationName> values) {
124     List<String> list = new ArrayList<>(values.size());
125     for (ModelEvaluationName 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_MODEL_MODEL_EVALUATION.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 (model != null) {
152             fieldMapBuilder.put("model", model);
153           }
154           if (modelEvaluation != null) {
155             fieldMapBuilder.put("model_evaluation", modelEvaluation);
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_MODEL_MODEL_EVALUATION.instantiate(
171         "project",
172         project,
173         "location",
174         location,
175         "model",
176         model,
177         "model_evaluation",
178         modelEvaluation);
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       ModelEvaluationName that = ((ModelEvaluationName) o);
188       return Objects.equals(this.project, that.project)
189           && Objects.equals(this.location, that.location)
190           && Objects.equals(this.model, that.model)
191           && Objects.equals(this.modelEvaluation, that.modelEvaluation);
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(model);
205     h *= 1000003;
206     h ^= Objects.hashCode(modelEvaluation);
207     return h;
208   }
209 
210   /**
211    * Builder for
212    * projects/{project}/locations/{location}/models/{model}/modelEvaluations/{model_evaluation}.
213    */
214   public static class Builder {
215     private String project;
216     private String location;
217     private String model;
218     private String modelEvaluation;
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 
getModel()230     public String getModel() {
231       return model;
232     }
233 
getModelEvaluation()234     public String getModelEvaluation() {
235       return modelEvaluation;
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 
setModel(String model)248     public Builder setModel(String model) {
249       this.model = model;
250       return this;
251     }
252 
setModelEvaluation(String modelEvaluation)253     public Builder setModelEvaluation(String modelEvaluation) {
254       this.modelEvaluation = modelEvaluation;
255       return this;
256     }
257 
Builder(ModelEvaluationName modelEvaluationName)258     private Builder(ModelEvaluationName modelEvaluationName) {
259       this.project = modelEvaluationName.project;
260       this.location = modelEvaluationName.location;
261       this.model = modelEvaluationName.model;
262       this.modelEvaluation = modelEvaluationName.modelEvaluation;
263     }
264 
build()265     public ModelEvaluationName build() {
266       return new ModelEvaluationName(this);
267     }
268   }
269 }
270