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