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