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