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.securitycenter.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 EffectiveSecurityHealthAnalyticsCustomModuleName implements ResourceName { 34 private static final PathTemplate ORGANIZATION_EFFECTIVE_CUSTOM_MODULE = 35 PathTemplate.createWithoutUrlEncoding( 36 "organizations/{organization}/securityHealthAnalyticsSettings/effectiveCustomModules/{effective_custom_module}"); 37 private static final PathTemplate FOLDER_EFFECTIVE_CUSTOM_MODULE = 38 PathTemplate.createWithoutUrlEncoding( 39 "folders/{folder}/securityHealthAnalyticsSettings/effectiveCustomModules/{effective_custom_module}"); 40 private static final PathTemplate PROJECT_EFFECTIVE_CUSTOM_MODULE = 41 PathTemplate.createWithoutUrlEncoding( 42 "projects/{project}/securityHealthAnalyticsSettings/effectiveCustomModules/{effective_custom_module}"); 43 private volatile Map<String, String> fieldValuesMap; 44 private PathTemplate pathTemplate; 45 private String fixedValue; 46 private final String organization; 47 private final String effectiveCustomModule; 48 private final String folder; 49 private final String project; 50 51 @Deprecated EffectiveSecurityHealthAnalyticsCustomModuleName()52 protected EffectiveSecurityHealthAnalyticsCustomModuleName() { 53 organization = null; 54 effectiveCustomModule = null; 55 folder = null; 56 project = null; 57 } 58 EffectiveSecurityHealthAnalyticsCustomModuleName(Builder builder)59 private EffectiveSecurityHealthAnalyticsCustomModuleName(Builder builder) { 60 organization = Preconditions.checkNotNull(builder.getOrganization()); 61 effectiveCustomModule = Preconditions.checkNotNull(builder.getEffectiveCustomModule()); 62 folder = null; 63 project = null; 64 pathTemplate = ORGANIZATION_EFFECTIVE_CUSTOM_MODULE; 65 } 66 EffectiveSecurityHealthAnalyticsCustomModuleName( FolderEffectiveCustomModuleBuilder builder)67 private EffectiveSecurityHealthAnalyticsCustomModuleName( 68 FolderEffectiveCustomModuleBuilder builder) { 69 folder = Preconditions.checkNotNull(builder.getFolder()); 70 effectiveCustomModule = Preconditions.checkNotNull(builder.getEffectiveCustomModule()); 71 organization = null; 72 project = null; 73 pathTemplate = FOLDER_EFFECTIVE_CUSTOM_MODULE; 74 } 75 EffectiveSecurityHealthAnalyticsCustomModuleName( ProjectEffectiveCustomModuleBuilder builder)76 private EffectiveSecurityHealthAnalyticsCustomModuleName( 77 ProjectEffectiveCustomModuleBuilder builder) { 78 project = Preconditions.checkNotNull(builder.getProject()); 79 effectiveCustomModule = Preconditions.checkNotNull(builder.getEffectiveCustomModule()); 80 organization = null; 81 folder = null; 82 pathTemplate = PROJECT_EFFECTIVE_CUSTOM_MODULE; 83 } 84 getOrganization()85 public String getOrganization() { 86 return organization; 87 } 88 getEffectiveCustomModule()89 public String getEffectiveCustomModule() { 90 return effectiveCustomModule; 91 } 92 getFolder()93 public String getFolder() { 94 return folder; 95 } 96 getProject()97 public String getProject() { 98 return project; 99 } 100 newBuilder()101 public static Builder newBuilder() { 102 return new Builder(); 103 } 104 105 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") newOrganizationEffectiveCustomModuleBuilder()106 public static Builder newOrganizationEffectiveCustomModuleBuilder() { 107 return new Builder(); 108 } 109 110 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") newFolderEffectiveCustomModuleBuilder()111 public static FolderEffectiveCustomModuleBuilder newFolderEffectiveCustomModuleBuilder() { 112 return new FolderEffectiveCustomModuleBuilder(); 113 } 114 115 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") newProjectEffectiveCustomModuleBuilder()116 public static ProjectEffectiveCustomModuleBuilder newProjectEffectiveCustomModuleBuilder() { 117 return new ProjectEffectiveCustomModuleBuilder(); 118 } 119 toBuilder()120 public Builder toBuilder() { 121 return new Builder(this); 122 } 123 of( String organization, String effectiveCustomModule)124 public static EffectiveSecurityHealthAnalyticsCustomModuleName of( 125 String organization, String effectiveCustomModule) { 126 return newBuilder() 127 .setOrganization(organization) 128 .setEffectiveCustomModule(effectiveCustomModule) 129 .build(); 130 } 131 132 @BetaApi("The static create methods are not stable yet and may be changed in the future.") 133 public static EffectiveSecurityHealthAnalyticsCustomModuleName ofOrganizationEffectiveCustomModuleName(String organization, String effectiveCustomModule)134 ofOrganizationEffectiveCustomModuleName(String organization, String effectiveCustomModule) { 135 return newBuilder() 136 .setOrganization(organization) 137 .setEffectiveCustomModule(effectiveCustomModule) 138 .build(); 139 } 140 141 @BetaApi("The static create methods are not stable yet and may be changed in the future.") ofFolderEffectiveCustomModuleName( String folder, String effectiveCustomModule)142 public static EffectiveSecurityHealthAnalyticsCustomModuleName ofFolderEffectiveCustomModuleName( 143 String folder, String effectiveCustomModule) { 144 return newFolderEffectiveCustomModuleBuilder() 145 .setFolder(folder) 146 .setEffectiveCustomModule(effectiveCustomModule) 147 .build(); 148 } 149 150 @BetaApi("The static create methods are not stable yet and may be changed in the future.") ofProjectEffectiveCustomModuleName( String project, String effectiveCustomModule)151 public static EffectiveSecurityHealthAnalyticsCustomModuleName ofProjectEffectiveCustomModuleName( 152 String project, String effectiveCustomModule) { 153 return newProjectEffectiveCustomModuleBuilder() 154 .setProject(project) 155 .setEffectiveCustomModule(effectiveCustomModule) 156 .build(); 157 } 158 format(String organization, String effectiveCustomModule)159 public static String format(String organization, String effectiveCustomModule) { 160 return newBuilder() 161 .setOrganization(organization) 162 .setEffectiveCustomModule(effectiveCustomModule) 163 .build() 164 .toString(); 165 } 166 167 @BetaApi("The static format methods are not stable yet and may be changed in the future.") formatOrganizationEffectiveCustomModuleName( String organization, String effectiveCustomModule)168 public static String formatOrganizationEffectiveCustomModuleName( 169 String organization, String effectiveCustomModule) { 170 return newBuilder() 171 .setOrganization(organization) 172 .setEffectiveCustomModule(effectiveCustomModule) 173 .build() 174 .toString(); 175 } 176 177 @BetaApi("The static format methods are not stable yet and may be changed in the future.") formatFolderEffectiveCustomModuleName( String folder, String effectiveCustomModule)178 public static String formatFolderEffectiveCustomModuleName( 179 String folder, String effectiveCustomModule) { 180 return newFolderEffectiveCustomModuleBuilder() 181 .setFolder(folder) 182 .setEffectiveCustomModule(effectiveCustomModule) 183 .build() 184 .toString(); 185 } 186 187 @BetaApi("The static format methods are not stable yet and may be changed in the future.") formatProjectEffectiveCustomModuleName( String project, String effectiveCustomModule)188 public static String formatProjectEffectiveCustomModuleName( 189 String project, String effectiveCustomModule) { 190 return newProjectEffectiveCustomModuleBuilder() 191 .setProject(project) 192 .setEffectiveCustomModule(effectiveCustomModule) 193 .build() 194 .toString(); 195 } 196 parse(String formattedString)197 public static EffectiveSecurityHealthAnalyticsCustomModuleName parse(String formattedString) { 198 if (formattedString.isEmpty()) { 199 return null; 200 } 201 if (ORGANIZATION_EFFECTIVE_CUSTOM_MODULE.matches(formattedString)) { 202 Map<String, String> matchMap = ORGANIZATION_EFFECTIVE_CUSTOM_MODULE.match(formattedString); 203 return ofOrganizationEffectiveCustomModuleName( 204 matchMap.get("organization"), matchMap.get("effective_custom_module")); 205 } else if (FOLDER_EFFECTIVE_CUSTOM_MODULE.matches(formattedString)) { 206 Map<String, String> matchMap = FOLDER_EFFECTIVE_CUSTOM_MODULE.match(formattedString); 207 return ofFolderEffectiveCustomModuleName( 208 matchMap.get("folder"), matchMap.get("effective_custom_module")); 209 } else if (PROJECT_EFFECTIVE_CUSTOM_MODULE.matches(formattedString)) { 210 Map<String, String> matchMap = PROJECT_EFFECTIVE_CUSTOM_MODULE.match(formattedString); 211 return ofProjectEffectiveCustomModuleName( 212 matchMap.get("project"), matchMap.get("effective_custom_module")); 213 } 214 throw new ValidationException( 215 "EffectiveSecurityHealthAnalyticsCustomModuleName.parse: formattedString not in valid format"); 216 } 217 parseList( List<String> formattedStrings)218 public static List<EffectiveSecurityHealthAnalyticsCustomModuleName> parseList( 219 List<String> formattedStrings) { 220 List<EffectiveSecurityHealthAnalyticsCustomModuleName> list = 221 new ArrayList<>(formattedStrings.size()); 222 for (String formattedString : formattedStrings) { 223 list.add(parse(formattedString)); 224 } 225 return list; 226 } 227 toStringList( List<EffectiveSecurityHealthAnalyticsCustomModuleName> values)228 public static List<String> toStringList( 229 List<EffectiveSecurityHealthAnalyticsCustomModuleName> values) { 230 List<String> list = new ArrayList<>(values.size()); 231 for (EffectiveSecurityHealthAnalyticsCustomModuleName value : values) { 232 if (value == null) { 233 list.add(""); 234 } else { 235 list.add(value.toString()); 236 } 237 } 238 return list; 239 } 240 isParsableFrom(String formattedString)241 public static boolean isParsableFrom(String formattedString) { 242 return ORGANIZATION_EFFECTIVE_CUSTOM_MODULE.matches(formattedString) 243 || FOLDER_EFFECTIVE_CUSTOM_MODULE.matches(formattedString) 244 || PROJECT_EFFECTIVE_CUSTOM_MODULE.matches(formattedString); 245 } 246 247 @Override getFieldValuesMap()248 public Map<String, String> getFieldValuesMap() { 249 if (fieldValuesMap == null) { 250 synchronized (this) { 251 if (fieldValuesMap == null) { 252 ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder(); 253 if (organization != null) { 254 fieldMapBuilder.put("organization", organization); 255 } 256 if (effectiveCustomModule != null) { 257 fieldMapBuilder.put("effective_custom_module", effectiveCustomModule); 258 } 259 if (folder != null) { 260 fieldMapBuilder.put("folder", folder); 261 } 262 if (project != null) { 263 fieldMapBuilder.put("project", project); 264 } 265 fieldValuesMap = fieldMapBuilder.build(); 266 } 267 } 268 } 269 return fieldValuesMap; 270 } 271 getFieldValue(String fieldName)272 public String getFieldValue(String fieldName) { 273 return getFieldValuesMap().get(fieldName); 274 } 275 276 @Override toString()277 public String toString() { 278 return fixedValue != null ? fixedValue : pathTemplate.instantiate(getFieldValuesMap()); 279 } 280 281 @Override equals(Object o)282 public boolean equals(Object o) { 283 if (o == this) { 284 return true; 285 } 286 if (o != null || getClass() == o.getClass()) { 287 EffectiveSecurityHealthAnalyticsCustomModuleName that = 288 ((EffectiveSecurityHealthAnalyticsCustomModuleName) o); 289 return Objects.equals(this.organization, that.organization) 290 && Objects.equals(this.effectiveCustomModule, that.effectiveCustomModule) 291 && Objects.equals(this.folder, that.folder) 292 && Objects.equals(this.project, that.project); 293 } 294 return false; 295 } 296 297 @Override hashCode()298 public int hashCode() { 299 int h = 1; 300 h *= 1000003; 301 h ^= Objects.hashCode(fixedValue); 302 h *= 1000003; 303 h ^= Objects.hashCode(organization); 304 h *= 1000003; 305 h ^= Objects.hashCode(effectiveCustomModule); 306 h *= 1000003; 307 h ^= Objects.hashCode(folder); 308 h *= 1000003; 309 h ^= Objects.hashCode(project); 310 return h; 311 } 312 313 /** 314 * Builder for 315 * organizations/{organization}/securityHealthAnalyticsSettings/effectiveCustomModules/{effective_custom_module}. 316 */ 317 public static class Builder { 318 private String organization; 319 private String effectiveCustomModule; 320 Builder()321 protected Builder() {} 322 getOrganization()323 public String getOrganization() { 324 return organization; 325 } 326 getEffectiveCustomModule()327 public String getEffectiveCustomModule() { 328 return effectiveCustomModule; 329 } 330 setOrganization(String organization)331 public Builder setOrganization(String organization) { 332 this.organization = organization; 333 return this; 334 } 335 setEffectiveCustomModule(String effectiveCustomModule)336 public Builder setEffectiveCustomModule(String effectiveCustomModule) { 337 this.effectiveCustomModule = effectiveCustomModule; 338 return this; 339 } 340 Builder( EffectiveSecurityHealthAnalyticsCustomModuleName effectiveSecurityHealthAnalyticsCustomModuleName)341 private Builder( 342 EffectiveSecurityHealthAnalyticsCustomModuleName 343 effectiveSecurityHealthAnalyticsCustomModuleName) { 344 Preconditions.checkArgument( 345 Objects.equals( 346 effectiveSecurityHealthAnalyticsCustomModuleName.pathTemplate, 347 ORGANIZATION_EFFECTIVE_CUSTOM_MODULE), 348 "toBuilder is only supported when EffectiveSecurityHealthAnalyticsCustomModuleName has the pattern of organizations/{organization}/securityHealthAnalyticsSettings/effectiveCustomModules/{effective_custom_module}"); 349 this.organization = effectiveSecurityHealthAnalyticsCustomModuleName.organization; 350 this.effectiveCustomModule = 351 effectiveSecurityHealthAnalyticsCustomModuleName.effectiveCustomModule; 352 } 353 build()354 public EffectiveSecurityHealthAnalyticsCustomModuleName build() { 355 return new EffectiveSecurityHealthAnalyticsCustomModuleName(this); 356 } 357 } 358 359 /** 360 * Builder for 361 * folders/{folder}/securityHealthAnalyticsSettings/effectiveCustomModules/{effective_custom_module}. 362 */ 363 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") 364 public static class FolderEffectiveCustomModuleBuilder { 365 private String folder; 366 private String effectiveCustomModule; 367 FolderEffectiveCustomModuleBuilder()368 protected FolderEffectiveCustomModuleBuilder() {} 369 getFolder()370 public String getFolder() { 371 return folder; 372 } 373 getEffectiveCustomModule()374 public String getEffectiveCustomModule() { 375 return effectiveCustomModule; 376 } 377 setFolder(String folder)378 public FolderEffectiveCustomModuleBuilder setFolder(String folder) { 379 this.folder = folder; 380 return this; 381 } 382 setEffectiveCustomModule( String effectiveCustomModule)383 public FolderEffectiveCustomModuleBuilder setEffectiveCustomModule( 384 String effectiveCustomModule) { 385 this.effectiveCustomModule = effectiveCustomModule; 386 return this; 387 } 388 build()389 public EffectiveSecurityHealthAnalyticsCustomModuleName build() { 390 return new EffectiveSecurityHealthAnalyticsCustomModuleName(this); 391 } 392 } 393 394 /** 395 * Builder for 396 * projects/{project}/securityHealthAnalyticsSettings/effectiveCustomModules/{effective_custom_module}. 397 */ 398 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") 399 public static class ProjectEffectiveCustomModuleBuilder { 400 private String project; 401 private String effectiveCustomModule; 402 ProjectEffectiveCustomModuleBuilder()403 protected ProjectEffectiveCustomModuleBuilder() {} 404 getProject()405 public String getProject() { 406 return project; 407 } 408 getEffectiveCustomModule()409 public String getEffectiveCustomModule() { 410 return effectiveCustomModule; 411 } 412 setProject(String project)413 public ProjectEffectiveCustomModuleBuilder setProject(String project) { 414 this.project = project; 415 return this; 416 } 417 setEffectiveCustomModule( String effectiveCustomModule)418 public ProjectEffectiveCustomModuleBuilder setEffectiveCustomModule( 419 String effectiveCustomModule) { 420 this.effectiveCustomModule = effectiveCustomModule; 421 return this; 422 } 423 build()424 public EffectiveSecurityHealthAnalyticsCustomModuleName build() { 425 return new EffectiveSecurityHealthAnalyticsCustomModuleName(this); 426 } 427 } 428 } 429