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.aiplatform.v1; 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 EndpointName implements ResourceName { 34 private static final PathTemplate PROJECT_LOCATION_ENDPOINT = 35 PathTemplate.createWithoutUrlEncoding( 36 "projects/{project}/locations/{location}/endpoints/{endpoint}"); 37 private static final PathTemplate PROJECT_LOCATION_PUBLISHER_MODEL = 38 PathTemplate.createWithoutUrlEncoding( 39 "projects/{project}/locations/{location}/publishers/{publisher}/models/{model}"); 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 endpoint; 46 private final String publisher; 47 private final String model; 48 49 @Deprecated EndpointName()50 protected EndpointName() { 51 project = null; 52 location = null; 53 endpoint = null; 54 publisher = null; 55 model = null; 56 } 57 EndpointName(Builder builder)58 private EndpointName(Builder builder) { 59 project = Preconditions.checkNotNull(builder.getProject()); 60 location = Preconditions.checkNotNull(builder.getLocation()); 61 endpoint = Preconditions.checkNotNull(builder.getEndpoint()); 62 publisher = null; 63 model = null; 64 pathTemplate = PROJECT_LOCATION_ENDPOINT; 65 } 66 EndpointName(ProjectLocationPublisherModelBuilder builder)67 private EndpointName(ProjectLocationPublisherModelBuilder builder) { 68 project = Preconditions.checkNotNull(builder.getProject()); 69 location = Preconditions.checkNotNull(builder.getLocation()); 70 publisher = Preconditions.checkNotNull(builder.getPublisher()); 71 model = Preconditions.checkNotNull(builder.getModel()); 72 endpoint = null; 73 pathTemplate = PROJECT_LOCATION_PUBLISHER_MODEL; 74 } 75 getProject()76 public String getProject() { 77 return project; 78 } 79 getLocation()80 public String getLocation() { 81 return location; 82 } 83 getEndpoint()84 public String getEndpoint() { 85 return endpoint; 86 } 87 getPublisher()88 public String getPublisher() { 89 return publisher; 90 } 91 getModel()92 public String getModel() { 93 return model; 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.") newProjectLocationEndpointBuilder()101 public static Builder newProjectLocationEndpointBuilder() { 102 return new Builder(); 103 } 104 105 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") newProjectLocationPublisherModelBuilder()106 public static ProjectLocationPublisherModelBuilder newProjectLocationPublisherModelBuilder() { 107 return new ProjectLocationPublisherModelBuilder(); 108 } 109 toBuilder()110 public Builder toBuilder() { 111 return new Builder(this); 112 } 113 of(String project, String location, String endpoint)114 public static EndpointName of(String project, String location, String endpoint) { 115 return newBuilder().setProject(project).setLocation(location).setEndpoint(endpoint).build(); 116 } 117 118 @BetaApi("The static create methods are not stable yet and may be changed in the future.") ofProjectLocationEndpointName( String project, String location, String endpoint)119 public static EndpointName ofProjectLocationEndpointName( 120 String project, String location, String endpoint) { 121 return newBuilder().setProject(project).setLocation(location).setEndpoint(endpoint).build(); 122 } 123 124 @BetaApi("The static create methods are not stable yet and may be changed in the future.") ofProjectLocationPublisherModelName( String project, String location, String publisher, String model)125 public static EndpointName ofProjectLocationPublisherModelName( 126 String project, String location, String publisher, String model) { 127 return newProjectLocationPublisherModelBuilder() 128 .setProject(project) 129 .setLocation(location) 130 .setPublisher(publisher) 131 .setModel(model) 132 .build(); 133 } 134 format(String project, String location, String endpoint)135 public static String format(String project, String location, String endpoint) { 136 return newBuilder() 137 .setProject(project) 138 .setLocation(location) 139 .setEndpoint(endpoint) 140 .build() 141 .toString(); 142 } 143 144 @BetaApi("The static format methods are not stable yet and may be changed in the future.") formatProjectLocationEndpointName( String project, String location, String endpoint)145 public static String formatProjectLocationEndpointName( 146 String project, String location, String endpoint) { 147 return newBuilder() 148 .setProject(project) 149 .setLocation(location) 150 .setEndpoint(endpoint) 151 .build() 152 .toString(); 153 } 154 155 @BetaApi("The static format methods are not stable yet and may be changed in the future.") formatProjectLocationPublisherModelName( String project, String location, String publisher, String model)156 public static String formatProjectLocationPublisherModelName( 157 String project, String location, String publisher, String model) { 158 return newProjectLocationPublisherModelBuilder() 159 .setProject(project) 160 .setLocation(location) 161 .setPublisher(publisher) 162 .setModel(model) 163 .build() 164 .toString(); 165 } 166 parse(String formattedString)167 public static EndpointName parse(String formattedString) { 168 if (formattedString.isEmpty()) { 169 return null; 170 } 171 if (PROJECT_LOCATION_ENDPOINT.matches(formattedString)) { 172 Map<String, String> matchMap = PROJECT_LOCATION_ENDPOINT.match(formattedString); 173 return ofProjectLocationEndpointName( 174 matchMap.get("project"), matchMap.get("location"), matchMap.get("endpoint")); 175 } else if (PROJECT_LOCATION_PUBLISHER_MODEL.matches(formattedString)) { 176 Map<String, String> matchMap = PROJECT_LOCATION_PUBLISHER_MODEL.match(formattedString); 177 return ofProjectLocationPublisherModelName( 178 matchMap.get("project"), 179 matchMap.get("location"), 180 matchMap.get("publisher"), 181 matchMap.get("model")); 182 } 183 throw new ValidationException("EndpointName.parse: formattedString not in valid format"); 184 } 185 parseList(List<String> formattedStrings)186 public static List<EndpointName> parseList(List<String> formattedStrings) { 187 List<EndpointName> list = new ArrayList<>(formattedStrings.size()); 188 for (String formattedString : formattedStrings) { 189 list.add(parse(formattedString)); 190 } 191 return list; 192 } 193 toStringList(List<EndpointName> values)194 public static List<String> toStringList(List<EndpointName> values) { 195 List<String> list = new ArrayList<>(values.size()); 196 for (EndpointName value : values) { 197 if (value == null) { 198 list.add(""); 199 } else { 200 list.add(value.toString()); 201 } 202 } 203 return list; 204 } 205 isParsableFrom(String formattedString)206 public static boolean isParsableFrom(String formattedString) { 207 return PROJECT_LOCATION_ENDPOINT.matches(formattedString) 208 || PROJECT_LOCATION_PUBLISHER_MODEL.matches(formattedString); 209 } 210 211 @Override getFieldValuesMap()212 public Map<String, String> getFieldValuesMap() { 213 if (fieldValuesMap == null) { 214 synchronized (this) { 215 if (fieldValuesMap == null) { 216 ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder(); 217 if (project != null) { 218 fieldMapBuilder.put("project", project); 219 } 220 if (location != null) { 221 fieldMapBuilder.put("location", location); 222 } 223 if (endpoint != null) { 224 fieldMapBuilder.put("endpoint", endpoint); 225 } 226 if (publisher != null) { 227 fieldMapBuilder.put("publisher", publisher); 228 } 229 if (model != null) { 230 fieldMapBuilder.put("model", model); 231 } 232 fieldValuesMap = fieldMapBuilder.build(); 233 } 234 } 235 } 236 return fieldValuesMap; 237 } 238 getFieldValue(String fieldName)239 public String getFieldValue(String fieldName) { 240 return getFieldValuesMap().get(fieldName); 241 } 242 243 @Override toString()244 public String toString() { 245 return fixedValue != null ? fixedValue : pathTemplate.instantiate(getFieldValuesMap()); 246 } 247 248 @Override equals(Object o)249 public boolean equals(Object o) { 250 if (o == this) { 251 return true; 252 } 253 if (o != null || getClass() == o.getClass()) { 254 EndpointName that = ((EndpointName) o); 255 return Objects.equals(this.project, that.project) 256 && Objects.equals(this.location, that.location) 257 && Objects.equals(this.endpoint, that.endpoint) 258 && Objects.equals(this.publisher, that.publisher) 259 && Objects.equals(this.model, that.model); 260 } 261 return false; 262 } 263 264 @Override hashCode()265 public int hashCode() { 266 int h = 1; 267 h *= 1000003; 268 h ^= Objects.hashCode(fixedValue); 269 h *= 1000003; 270 h ^= Objects.hashCode(project); 271 h *= 1000003; 272 h ^= Objects.hashCode(location); 273 h *= 1000003; 274 h ^= Objects.hashCode(endpoint); 275 h *= 1000003; 276 h ^= Objects.hashCode(publisher); 277 h *= 1000003; 278 h ^= Objects.hashCode(model); 279 return h; 280 } 281 282 /** Builder for projects/{project}/locations/{location}/endpoints/{endpoint}. */ 283 public static class Builder { 284 private String project; 285 private String location; 286 private String endpoint; 287 Builder()288 protected Builder() {} 289 getProject()290 public String getProject() { 291 return project; 292 } 293 getLocation()294 public String getLocation() { 295 return location; 296 } 297 getEndpoint()298 public String getEndpoint() { 299 return endpoint; 300 } 301 setProject(String project)302 public Builder setProject(String project) { 303 this.project = project; 304 return this; 305 } 306 setLocation(String location)307 public Builder setLocation(String location) { 308 this.location = location; 309 return this; 310 } 311 setEndpoint(String endpoint)312 public Builder setEndpoint(String endpoint) { 313 this.endpoint = endpoint; 314 return this; 315 } 316 Builder(EndpointName endpointName)317 private Builder(EndpointName endpointName) { 318 Preconditions.checkArgument( 319 Objects.equals(endpointName.pathTemplate, PROJECT_LOCATION_ENDPOINT), 320 "toBuilder is only supported when EndpointName has the pattern of projects/{project}/locations/{location}/endpoints/{endpoint}"); 321 this.project = endpointName.project; 322 this.location = endpointName.location; 323 this.endpoint = endpointName.endpoint; 324 } 325 build()326 public EndpointName build() { 327 return new EndpointName(this); 328 } 329 } 330 331 /** Builder for projects/{project}/locations/{location}/publishers/{publisher}/models/{model}. */ 332 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") 333 public static class ProjectLocationPublisherModelBuilder { 334 private String project; 335 private String location; 336 private String publisher; 337 private String model; 338 ProjectLocationPublisherModelBuilder()339 protected ProjectLocationPublisherModelBuilder() {} 340 getProject()341 public String getProject() { 342 return project; 343 } 344 getLocation()345 public String getLocation() { 346 return location; 347 } 348 getPublisher()349 public String getPublisher() { 350 return publisher; 351 } 352 getModel()353 public String getModel() { 354 return model; 355 } 356 setProject(String project)357 public ProjectLocationPublisherModelBuilder setProject(String project) { 358 this.project = project; 359 return this; 360 } 361 setLocation(String location)362 public ProjectLocationPublisherModelBuilder setLocation(String location) { 363 this.location = location; 364 return this; 365 } 366 setPublisher(String publisher)367 public ProjectLocationPublisherModelBuilder setPublisher(String publisher) { 368 this.publisher = publisher; 369 return this; 370 } 371 setModel(String model)372 public ProjectLocationPublisherModelBuilder setModel(String model) { 373 this.model = model; 374 return this; 375 } 376 build()377 public EndpointName build() { 378 return new EndpointName(this); 379 } 380 } 381 } 382