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.kms.v1; 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 CryptoKeyVersionName implements ResourceName { 32 private static final PathTemplate PROJECT_LOCATION_KEY_RING_CRYPTO_KEY_CRYPTO_KEY_VERSION = 33 PathTemplate.createWithoutUrlEncoding( 34 "projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}/cryptoKeyVersions/{crypto_key_version}"); 35 private volatile Map<String, String> fieldValuesMap; 36 private final String project; 37 private final String location; 38 private final String keyRing; 39 private final String cryptoKey; 40 private final String cryptoKeyVersion; 41 42 @Deprecated CryptoKeyVersionName()43 protected CryptoKeyVersionName() { 44 project = null; 45 location = null; 46 keyRing = null; 47 cryptoKey = null; 48 cryptoKeyVersion = null; 49 } 50 CryptoKeyVersionName(Builder builder)51 private CryptoKeyVersionName(Builder builder) { 52 project = Preconditions.checkNotNull(builder.getProject()); 53 location = Preconditions.checkNotNull(builder.getLocation()); 54 keyRing = Preconditions.checkNotNull(builder.getKeyRing()); 55 cryptoKey = Preconditions.checkNotNull(builder.getCryptoKey()); 56 cryptoKeyVersion = Preconditions.checkNotNull(builder.getCryptoKeyVersion()); 57 } 58 getProject()59 public String getProject() { 60 return project; 61 } 62 getLocation()63 public String getLocation() { 64 return location; 65 } 66 getKeyRing()67 public String getKeyRing() { 68 return keyRing; 69 } 70 getCryptoKey()71 public String getCryptoKey() { 72 return cryptoKey; 73 } 74 getCryptoKeyVersion()75 public String getCryptoKeyVersion() { 76 return cryptoKeyVersion; 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 keyRing, String cryptoKey, String cryptoKeyVersion)87 public static CryptoKeyVersionName of( 88 String project, String location, String keyRing, String cryptoKey, String cryptoKeyVersion) { 89 return newBuilder() 90 .setProject(project) 91 .setLocation(location) 92 .setKeyRing(keyRing) 93 .setCryptoKey(cryptoKey) 94 .setCryptoKeyVersion(cryptoKeyVersion) 95 .build(); 96 } 97 format( String project, String location, String keyRing, String cryptoKey, String cryptoKeyVersion)98 public static String format( 99 String project, String location, String keyRing, String cryptoKey, String cryptoKeyVersion) { 100 return newBuilder() 101 .setProject(project) 102 .setLocation(location) 103 .setKeyRing(keyRing) 104 .setCryptoKey(cryptoKey) 105 .setCryptoKeyVersion(cryptoKeyVersion) 106 .build() 107 .toString(); 108 } 109 parse(String formattedString)110 public static CryptoKeyVersionName parse(String formattedString) { 111 if (formattedString.isEmpty()) { 112 return null; 113 } 114 Map<String, String> matchMap = 115 PROJECT_LOCATION_KEY_RING_CRYPTO_KEY_CRYPTO_KEY_VERSION.validatedMatch( 116 formattedString, "CryptoKeyVersionName.parse: formattedString not in valid format"); 117 return of( 118 matchMap.get("project"), 119 matchMap.get("location"), 120 matchMap.get("key_ring"), 121 matchMap.get("crypto_key"), 122 matchMap.get("crypto_key_version")); 123 } 124 parseList(List<String> formattedStrings)125 public static List<CryptoKeyVersionName> parseList(List<String> formattedStrings) { 126 List<CryptoKeyVersionName> list = new ArrayList<>(formattedStrings.size()); 127 for (String formattedString : formattedStrings) { 128 list.add(parse(formattedString)); 129 } 130 return list; 131 } 132 toStringList(List<CryptoKeyVersionName> values)133 public static List<String> toStringList(List<CryptoKeyVersionName> values) { 134 List<String> list = new ArrayList<>(values.size()); 135 for (CryptoKeyVersionName 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_KEY_RING_CRYPTO_KEY_CRYPTO_KEY_VERSION.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 (keyRing != null) { 162 fieldMapBuilder.put("key_ring", keyRing); 163 } 164 if (cryptoKey != null) { 165 fieldMapBuilder.put("crypto_key", cryptoKey); 166 } 167 if (cryptoKeyVersion != null) { 168 fieldMapBuilder.put("crypto_key_version", cryptoKeyVersion); 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_KEY_RING_CRYPTO_KEY_CRYPTO_KEY_VERSION.instantiate( 184 "project", 185 project, 186 "location", 187 location, 188 "key_ring", 189 keyRing, 190 "crypto_key", 191 cryptoKey, 192 "crypto_key_version", 193 cryptoKeyVersion); 194 } 195 196 @Override equals(Object o)197 public boolean equals(Object o) { 198 if (o == this) { 199 return true; 200 } 201 if (o != null || getClass() == o.getClass()) { 202 CryptoKeyVersionName that = ((CryptoKeyVersionName) o); 203 return Objects.equals(this.project, that.project) 204 && Objects.equals(this.location, that.location) 205 && Objects.equals(this.keyRing, that.keyRing) 206 && Objects.equals(this.cryptoKey, that.cryptoKey) 207 && Objects.equals(this.cryptoKeyVersion, that.cryptoKeyVersion); 208 } 209 return false; 210 } 211 212 @Override hashCode()213 public int hashCode() { 214 int h = 1; 215 h *= 1000003; 216 h ^= Objects.hashCode(project); 217 h *= 1000003; 218 h ^= Objects.hashCode(location); 219 h *= 1000003; 220 h ^= Objects.hashCode(keyRing); 221 h *= 1000003; 222 h ^= Objects.hashCode(cryptoKey); 223 h *= 1000003; 224 h ^= Objects.hashCode(cryptoKeyVersion); 225 return h; 226 } 227 228 /** 229 * Builder for 230 * projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}/cryptoKeyVersions/{crypto_key_version}. 231 */ 232 public static class Builder { 233 private String project; 234 private String location; 235 private String keyRing; 236 private String cryptoKey; 237 private String cryptoKeyVersion; 238 Builder()239 protected Builder() {} 240 getProject()241 public String getProject() { 242 return project; 243 } 244 getLocation()245 public String getLocation() { 246 return location; 247 } 248 getKeyRing()249 public String getKeyRing() { 250 return keyRing; 251 } 252 getCryptoKey()253 public String getCryptoKey() { 254 return cryptoKey; 255 } 256 getCryptoKeyVersion()257 public String getCryptoKeyVersion() { 258 return cryptoKeyVersion; 259 } 260 setProject(String project)261 public Builder setProject(String project) { 262 this.project = project; 263 return this; 264 } 265 setLocation(String location)266 public Builder setLocation(String location) { 267 this.location = location; 268 return this; 269 } 270 setKeyRing(String keyRing)271 public Builder setKeyRing(String keyRing) { 272 this.keyRing = keyRing; 273 return this; 274 } 275 setCryptoKey(String cryptoKey)276 public Builder setCryptoKey(String cryptoKey) { 277 this.cryptoKey = cryptoKey; 278 return this; 279 } 280 setCryptoKeyVersion(String cryptoKeyVersion)281 public Builder setCryptoKeyVersion(String cryptoKeyVersion) { 282 this.cryptoKeyVersion = cryptoKeyVersion; 283 return this; 284 } 285 Builder(CryptoKeyVersionName cryptoKeyVersionName)286 private Builder(CryptoKeyVersionName cryptoKeyVersionName) { 287 this.project = cryptoKeyVersionName.project; 288 this.location = cryptoKeyVersionName.location; 289 this.keyRing = cryptoKeyVersionName.keyRing; 290 this.cryptoKey = cryptoKeyVersionName.cryptoKey; 291 this.cryptoKeyVersion = cryptoKeyVersionName.cryptoKeyVersion; 292 } 293 build()294 public CryptoKeyVersionName build() { 295 return new CryptoKeyVersionName(this); 296 } 297 } 298 } 299