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.dialogflow.v2; 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 SessionName implements ResourceName { 34 private static final PathTemplate PROJECT_SESSION = 35 PathTemplate.createWithoutUrlEncoding("projects/{project}/agent/sessions/{session}"); 36 private static final PathTemplate PROJECT_ENVIRONMENT_USER_SESSION = 37 PathTemplate.createWithoutUrlEncoding( 38 "projects/{project}/agent/environments/{environment}/users/{user}/sessions/{session}"); 39 private static final PathTemplate PROJECT_LOCATION_SESSION = 40 PathTemplate.createWithoutUrlEncoding( 41 "projects/{project}/locations/{location}/agent/sessions/{session}"); 42 private static final PathTemplate PROJECT_LOCATION_ENVIRONMENT_USER_SESSION = 43 PathTemplate.createWithoutUrlEncoding( 44 "projects/{project}/locations/{location}/agent/environments/{environment}/users/{user}/sessions/{session}"); 45 private volatile Map<String, String> fieldValuesMap; 46 private PathTemplate pathTemplate; 47 private String fixedValue; 48 private final String project; 49 private final String session; 50 private final String environment; 51 private final String user; 52 private final String location; 53 54 @Deprecated SessionName()55 protected SessionName() { 56 project = null; 57 session = null; 58 environment = null; 59 user = null; 60 location = null; 61 } 62 SessionName(Builder builder)63 private SessionName(Builder builder) { 64 project = Preconditions.checkNotNull(builder.getProject()); 65 session = Preconditions.checkNotNull(builder.getSession()); 66 environment = null; 67 user = null; 68 location = null; 69 pathTemplate = PROJECT_SESSION; 70 } 71 SessionName(ProjectEnvironmentUserSessionBuilder builder)72 private SessionName(ProjectEnvironmentUserSessionBuilder builder) { 73 project = Preconditions.checkNotNull(builder.getProject()); 74 environment = Preconditions.checkNotNull(builder.getEnvironment()); 75 user = Preconditions.checkNotNull(builder.getUser()); 76 session = Preconditions.checkNotNull(builder.getSession()); 77 location = null; 78 pathTemplate = PROJECT_ENVIRONMENT_USER_SESSION; 79 } 80 SessionName(ProjectLocationSessionBuilder builder)81 private SessionName(ProjectLocationSessionBuilder builder) { 82 project = Preconditions.checkNotNull(builder.getProject()); 83 location = Preconditions.checkNotNull(builder.getLocation()); 84 session = Preconditions.checkNotNull(builder.getSession()); 85 environment = null; 86 user = null; 87 pathTemplate = PROJECT_LOCATION_SESSION; 88 } 89 SessionName(ProjectLocationEnvironmentUserSessionBuilder builder)90 private SessionName(ProjectLocationEnvironmentUserSessionBuilder builder) { 91 project = Preconditions.checkNotNull(builder.getProject()); 92 location = Preconditions.checkNotNull(builder.getLocation()); 93 environment = Preconditions.checkNotNull(builder.getEnvironment()); 94 user = Preconditions.checkNotNull(builder.getUser()); 95 session = Preconditions.checkNotNull(builder.getSession()); 96 pathTemplate = PROJECT_LOCATION_ENVIRONMENT_USER_SESSION; 97 } 98 getProject()99 public String getProject() { 100 return project; 101 } 102 getSession()103 public String getSession() { 104 return session; 105 } 106 getEnvironment()107 public String getEnvironment() { 108 return environment; 109 } 110 getUser()111 public String getUser() { 112 return user; 113 } 114 getLocation()115 public String getLocation() { 116 return location; 117 } 118 newBuilder()119 public static Builder newBuilder() { 120 return new Builder(); 121 } 122 123 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") newProjectSessionBuilder()124 public static Builder newProjectSessionBuilder() { 125 return new Builder(); 126 } 127 128 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") newProjectEnvironmentUserSessionBuilder()129 public static ProjectEnvironmentUserSessionBuilder newProjectEnvironmentUserSessionBuilder() { 130 return new ProjectEnvironmentUserSessionBuilder(); 131 } 132 133 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") newProjectLocationSessionBuilder()134 public static ProjectLocationSessionBuilder newProjectLocationSessionBuilder() { 135 return new ProjectLocationSessionBuilder(); 136 } 137 138 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") 139 public static ProjectLocationEnvironmentUserSessionBuilder newProjectLocationEnvironmentUserSessionBuilder()140 newProjectLocationEnvironmentUserSessionBuilder() { 141 return new ProjectLocationEnvironmentUserSessionBuilder(); 142 } 143 toBuilder()144 public Builder toBuilder() { 145 return new Builder(this); 146 } 147 of(String project, String session)148 public static SessionName of(String project, String session) { 149 return newBuilder().setProject(project).setSession(session).build(); 150 } 151 152 @BetaApi("The static create methods are not stable yet and may be changed in the future.") ofProjectSessionName(String project, String session)153 public static SessionName ofProjectSessionName(String project, String session) { 154 return newBuilder().setProject(project).setSession(session).build(); 155 } 156 157 @BetaApi("The static create methods are not stable yet and may be changed in the future.") ofProjectEnvironmentUserSessionName( String project, String environment, String user, String session)158 public static SessionName ofProjectEnvironmentUserSessionName( 159 String project, String environment, String user, String session) { 160 return newProjectEnvironmentUserSessionBuilder() 161 .setProject(project) 162 .setEnvironment(environment) 163 .setUser(user) 164 .setSession(session) 165 .build(); 166 } 167 168 @BetaApi("The static create methods are not stable yet and may be changed in the future.") ofProjectLocationSessionName( String project, String location, String session)169 public static SessionName ofProjectLocationSessionName( 170 String project, String location, String session) { 171 return newProjectLocationSessionBuilder() 172 .setProject(project) 173 .setLocation(location) 174 .setSession(session) 175 .build(); 176 } 177 178 @BetaApi("The static create methods are not stable yet and may be changed in the future.") ofProjectLocationEnvironmentUserSessionName( String project, String location, String environment, String user, String session)179 public static SessionName ofProjectLocationEnvironmentUserSessionName( 180 String project, String location, String environment, String user, String session) { 181 return newProjectLocationEnvironmentUserSessionBuilder() 182 .setProject(project) 183 .setLocation(location) 184 .setEnvironment(environment) 185 .setUser(user) 186 .setSession(session) 187 .build(); 188 } 189 format(String project, String session)190 public static String format(String project, String session) { 191 return newBuilder().setProject(project).setSession(session).build().toString(); 192 } 193 194 @BetaApi("The static format methods are not stable yet and may be changed in the future.") formatProjectSessionName(String project, String session)195 public static String formatProjectSessionName(String project, String session) { 196 return newBuilder().setProject(project).setSession(session).build().toString(); 197 } 198 199 @BetaApi("The static format methods are not stable yet and may be changed in the future.") formatProjectEnvironmentUserSessionName( String project, String environment, String user, String session)200 public static String formatProjectEnvironmentUserSessionName( 201 String project, String environment, String user, String session) { 202 return newProjectEnvironmentUserSessionBuilder() 203 .setProject(project) 204 .setEnvironment(environment) 205 .setUser(user) 206 .setSession(session) 207 .build() 208 .toString(); 209 } 210 211 @BetaApi("The static format methods are not stable yet and may be changed in the future.") formatProjectLocationSessionName( String project, String location, String session)212 public static String formatProjectLocationSessionName( 213 String project, String location, String session) { 214 return newProjectLocationSessionBuilder() 215 .setProject(project) 216 .setLocation(location) 217 .setSession(session) 218 .build() 219 .toString(); 220 } 221 222 @BetaApi("The static format methods are not stable yet and may be changed in the future.") formatProjectLocationEnvironmentUserSessionName( String project, String location, String environment, String user, String session)223 public static String formatProjectLocationEnvironmentUserSessionName( 224 String project, String location, String environment, String user, String session) { 225 return newProjectLocationEnvironmentUserSessionBuilder() 226 .setProject(project) 227 .setLocation(location) 228 .setEnvironment(environment) 229 .setUser(user) 230 .setSession(session) 231 .build() 232 .toString(); 233 } 234 parse(String formattedString)235 public static SessionName parse(String formattedString) { 236 if (formattedString.isEmpty()) { 237 return null; 238 } 239 if (PROJECT_SESSION.matches(formattedString)) { 240 Map<String, String> matchMap = PROJECT_SESSION.match(formattedString); 241 return ofProjectSessionName(matchMap.get("project"), matchMap.get("session")); 242 } else if (PROJECT_ENVIRONMENT_USER_SESSION.matches(formattedString)) { 243 Map<String, String> matchMap = PROJECT_ENVIRONMENT_USER_SESSION.match(formattedString); 244 return ofProjectEnvironmentUserSessionName( 245 matchMap.get("project"), 246 matchMap.get("environment"), 247 matchMap.get("user"), 248 matchMap.get("session")); 249 } else if (PROJECT_LOCATION_SESSION.matches(formattedString)) { 250 Map<String, String> matchMap = PROJECT_LOCATION_SESSION.match(formattedString); 251 return ofProjectLocationSessionName( 252 matchMap.get("project"), matchMap.get("location"), matchMap.get("session")); 253 } else if (PROJECT_LOCATION_ENVIRONMENT_USER_SESSION.matches(formattedString)) { 254 Map<String, String> matchMap = 255 PROJECT_LOCATION_ENVIRONMENT_USER_SESSION.match(formattedString); 256 return ofProjectLocationEnvironmentUserSessionName( 257 matchMap.get("project"), 258 matchMap.get("location"), 259 matchMap.get("environment"), 260 matchMap.get("user"), 261 matchMap.get("session")); 262 } 263 throw new ValidationException("SessionName.parse: formattedString not in valid format"); 264 } 265 parseList(List<String> formattedStrings)266 public static List<SessionName> parseList(List<String> formattedStrings) { 267 List<SessionName> list = new ArrayList<>(formattedStrings.size()); 268 for (String formattedString : formattedStrings) { 269 list.add(parse(formattedString)); 270 } 271 return list; 272 } 273 toStringList(List<SessionName> values)274 public static List<String> toStringList(List<SessionName> values) { 275 List<String> list = new ArrayList<>(values.size()); 276 for (SessionName value : values) { 277 if (value == null) { 278 list.add(""); 279 } else { 280 list.add(value.toString()); 281 } 282 } 283 return list; 284 } 285 isParsableFrom(String formattedString)286 public static boolean isParsableFrom(String formattedString) { 287 return PROJECT_SESSION.matches(formattedString) 288 || PROJECT_ENVIRONMENT_USER_SESSION.matches(formattedString) 289 || PROJECT_LOCATION_SESSION.matches(formattedString) 290 || PROJECT_LOCATION_ENVIRONMENT_USER_SESSION.matches(formattedString); 291 } 292 293 @Override getFieldValuesMap()294 public Map<String, String> getFieldValuesMap() { 295 if (fieldValuesMap == null) { 296 synchronized (this) { 297 if (fieldValuesMap == null) { 298 ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder(); 299 if (project != null) { 300 fieldMapBuilder.put("project", project); 301 } 302 if (session != null) { 303 fieldMapBuilder.put("session", session); 304 } 305 if (environment != null) { 306 fieldMapBuilder.put("environment", environment); 307 } 308 if (user != null) { 309 fieldMapBuilder.put("user", user); 310 } 311 if (location != null) { 312 fieldMapBuilder.put("location", location); 313 } 314 fieldValuesMap = fieldMapBuilder.build(); 315 } 316 } 317 } 318 return fieldValuesMap; 319 } 320 getFieldValue(String fieldName)321 public String getFieldValue(String fieldName) { 322 return getFieldValuesMap().get(fieldName); 323 } 324 325 @Override toString()326 public String toString() { 327 return fixedValue != null ? fixedValue : pathTemplate.instantiate(getFieldValuesMap()); 328 } 329 330 @Override equals(Object o)331 public boolean equals(Object o) { 332 if (o == this) { 333 return true; 334 } 335 if (o != null || getClass() == o.getClass()) { 336 SessionName that = ((SessionName) o); 337 return Objects.equals(this.project, that.project) 338 && Objects.equals(this.session, that.session) 339 && Objects.equals(this.environment, that.environment) 340 && Objects.equals(this.user, that.user) 341 && Objects.equals(this.location, that.location); 342 } 343 return false; 344 } 345 346 @Override hashCode()347 public int hashCode() { 348 int h = 1; 349 h *= 1000003; 350 h ^= Objects.hashCode(fixedValue); 351 h *= 1000003; 352 h ^= Objects.hashCode(project); 353 h *= 1000003; 354 h ^= Objects.hashCode(session); 355 h *= 1000003; 356 h ^= Objects.hashCode(environment); 357 h *= 1000003; 358 h ^= Objects.hashCode(user); 359 h *= 1000003; 360 h ^= Objects.hashCode(location); 361 return h; 362 } 363 364 /** Builder for projects/{project}/agent/sessions/{session}. */ 365 public static class Builder { 366 private String project; 367 private String session; 368 Builder()369 protected Builder() {} 370 getProject()371 public String getProject() { 372 return project; 373 } 374 getSession()375 public String getSession() { 376 return session; 377 } 378 setProject(String project)379 public Builder setProject(String project) { 380 this.project = project; 381 return this; 382 } 383 setSession(String session)384 public Builder setSession(String session) { 385 this.session = session; 386 return this; 387 } 388 Builder(SessionName sessionName)389 private Builder(SessionName sessionName) { 390 Preconditions.checkArgument( 391 Objects.equals(sessionName.pathTemplate, PROJECT_SESSION), 392 "toBuilder is only supported when SessionName has the pattern of projects/{project}/agent/sessions/{session}"); 393 this.project = sessionName.project; 394 this.session = sessionName.session; 395 } 396 build()397 public SessionName build() { 398 return new SessionName(this); 399 } 400 } 401 402 /** 403 * Builder for 404 * projects/{project}/agent/environments/{environment}/users/{user}/sessions/{session}. 405 */ 406 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") 407 public static class ProjectEnvironmentUserSessionBuilder { 408 private String project; 409 private String environment; 410 private String user; 411 private String session; 412 ProjectEnvironmentUserSessionBuilder()413 protected ProjectEnvironmentUserSessionBuilder() {} 414 getProject()415 public String getProject() { 416 return project; 417 } 418 getEnvironment()419 public String getEnvironment() { 420 return environment; 421 } 422 getUser()423 public String getUser() { 424 return user; 425 } 426 getSession()427 public String getSession() { 428 return session; 429 } 430 setProject(String project)431 public ProjectEnvironmentUserSessionBuilder setProject(String project) { 432 this.project = project; 433 return this; 434 } 435 setEnvironment(String environment)436 public ProjectEnvironmentUserSessionBuilder setEnvironment(String environment) { 437 this.environment = environment; 438 return this; 439 } 440 setUser(String user)441 public ProjectEnvironmentUserSessionBuilder setUser(String user) { 442 this.user = user; 443 return this; 444 } 445 setSession(String session)446 public ProjectEnvironmentUserSessionBuilder setSession(String session) { 447 this.session = session; 448 return this; 449 } 450 build()451 public SessionName build() { 452 return new SessionName(this); 453 } 454 } 455 456 /** Builder for projects/{project}/locations/{location}/agent/sessions/{session}. */ 457 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") 458 public static class ProjectLocationSessionBuilder { 459 private String project; 460 private String location; 461 private String session; 462 ProjectLocationSessionBuilder()463 protected ProjectLocationSessionBuilder() {} 464 getProject()465 public String getProject() { 466 return project; 467 } 468 getLocation()469 public String getLocation() { 470 return location; 471 } 472 getSession()473 public String getSession() { 474 return session; 475 } 476 setProject(String project)477 public ProjectLocationSessionBuilder setProject(String project) { 478 this.project = project; 479 return this; 480 } 481 setLocation(String location)482 public ProjectLocationSessionBuilder setLocation(String location) { 483 this.location = location; 484 return this; 485 } 486 setSession(String session)487 public ProjectLocationSessionBuilder setSession(String session) { 488 this.session = session; 489 return this; 490 } 491 build()492 public SessionName build() { 493 return new SessionName(this); 494 } 495 } 496 497 /** 498 * Builder for 499 * projects/{project}/locations/{location}/agent/environments/{environment}/users/{user}/sessions/{session}. 500 */ 501 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") 502 public static class ProjectLocationEnvironmentUserSessionBuilder { 503 private String project; 504 private String location; 505 private String environment; 506 private String user; 507 private String session; 508 ProjectLocationEnvironmentUserSessionBuilder()509 protected ProjectLocationEnvironmentUserSessionBuilder() {} 510 getProject()511 public String getProject() { 512 return project; 513 } 514 getLocation()515 public String getLocation() { 516 return location; 517 } 518 getEnvironment()519 public String getEnvironment() { 520 return environment; 521 } 522 getUser()523 public String getUser() { 524 return user; 525 } 526 getSession()527 public String getSession() { 528 return session; 529 } 530 setProject(String project)531 public ProjectLocationEnvironmentUserSessionBuilder setProject(String project) { 532 this.project = project; 533 return this; 534 } 535 setLocation(String location)536 public ProjectLocationEnvironmentUserSessionBuilder setLocation(String location) { 537 this.location = location; 538 return this; 539 } 540 setEnvironment(String environment)541 public ProjectLocationEnvironmentUserSessionBuilder setEnvironment(String environment) { 542 this.environment = environment; 543 return this; 544 } 545 setUser(String user)546 public ProjectLocationEnvironmentUserSessionBuilder setUser(String user) { 547 this.user = user; 548 return this; 549 } 550 setSession(String session)551 public ProjectLocationEnvironmentUserSessionBuilder setSession(String session) { 552 this.session = session; 553 return this; 554 } 555 build()556 public SessionName build() { 557 return new SessionName(this); 558 } 559 } 560 } 561