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