• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.common.base.Preconditions;
21 import com.google.common.collect.ImmutableMap;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.Objects;
26 import javax.annotation.Generated;
27 
28 // AUTO-GENERATED DOCUMENTATION AND CLASS.
29 @Generated("by gapic-generator-java")
30 public class KeyRingName extends KeyName {
31   private static final PathTemplate PROJECT_LOCATION_KEY_RING =
32       PathTemplate.createWithoutUrlEncoding(
33           "projects/{project}/locations/{location}/keyRings/{key_ring}");
34   private volatile Map<String, String> fieldValuesMap;
35   private final String project;
36   private final String location;
37   private final String keyRing;
38 
39   @Deprecated
KeyRingName()40   protected KeyRingName() {
41     project = null;
42     location = null;
43     keyRing = null;
44   }
45 
KeyRingName(Builder builder)46   private KeyRingName(Builder builder) {
47     project = Preconditions.checkNotNull(builder.getProject());
48     location = Preconditions.checkNotNull(builder.getLocation());
49     keyRing = Preconditions.checkNotNull(builder.getKeyRing());
50   }
51 
getProject()52   public String getProject() {
53     return project;
54   }
55 
getLocation()56   public String getLocation() {
57     return location;
58   }
59 
getKeyRing()60   public String getKeyRing() {
61     return keyRing;
62   }
63 
newBuilder()64   public static Builder newBuilder() {
65     return new Builder();
66   }
67 
toBuilder()68   public Builder toBuilder() {
69     return new Builder(this);
70   }
71 
of(String project, String location, String keyRing)72   public static KeyRingName of(String project, String location, String keyRing) {
73     return newBuilder().setProject(project).setLocation(location).setKeyRing(keyRing).build();
74   }
75 
format(String project, String location, String keyRing)76   public static String format(String project, String location, String keyRing) {
77     return newBuilder()
78         .setProject(project)
79         .setLocation(location)
80         .setKeyRing(keyRing)
81         .build()
82         .toString();
83   }
84 
parse(String formattedString)85   public static KeyRingName parse(String formattedString) {
86     if (formattedString.isEmpty()) {
87       return null;
88     }
89     Map<String, String> matchMap =
90         PROJECT_LOCATION_KEY_RING.validatedMatch(
91             formattedString, "KeyRingName.parse: formattedString not in valid format");
92     return of(matchMap.get("project"), matchMap.get("location"), matchMap.get("key_ring"));
93   }
94 
parseList(List<String> formattedStrings)95   public static List<KeyRingName> parseList(List<String> formattedStrings) {
96     List<KeyRingName> list = new ArrayList<>(formattedStrings.size());
97     for (String formattedString : formattedStrings) {
98       list.add(parse(formattedString));
99     }
100     return list;
101   }
102 
toStringList(List<KeyRingName> values)103   public static List<String> toStringList(List<KeyRingName> values) {
104     List<String> list = new ArrayList<>(values.size());
105     for (KeyRingName value : values) {
106       if (value == null) {
107         list.add("");
108       } else {
109         list.add(value.toString());
110       }
111     }
112     return list;
113   }
114 
isParsableFrom(String formattedString)115   public static boolean isParsableFrom(String formattedString) {
116     return PROJECT_LOCATION_KEY_RING.matches(formattedString);
117   }
118 
119   @Override
getFieldValuesMap()120   public Map<String, String> getFieldValuesMap() {
121     if (fieldValuesMap == null) {
122       synchronized (this) {
123         if (fieldValuesMap == null) {
124           ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder();
125           if (project != null) {
126             fieldMapBuilder.put("project", project);
127           }
128           if (location != null) {
129             fieldMapBuilder.put("location", location);
130           }
131           if (keyRing != null) {
132             fieldMapBuilder.put("key_ring", keyRing);
133           }
134           fieldValuesMap = fieldMapBuilder.build();
135         }
136       }
137     }
138     return fieldValuesMap;
139   }
140 
getFieldValue(String fieldName)141   public String getFieldValue(String fieldName) {
142     return getFieldValuesMap().get(fieldName);
143   }
144 
145   @Override
toString()146   public String toString() {
147     return PROJECT_LOCATION_KEY_RING.instantiate(
148         "project", project, "location", location, "key_ring", keyRing);
149   }
150 
151   @Override
equals(Object o)152   public boolean equals(Object o) {
153     if (o == this) {
154       return true;
155     }
156     if (o != null || getClass() == o.getClass()) {
157       KeyRingName that = ((KeyRingName) o);
158       return Objects.equals(this.project, that.project)
159           && Objects.equals(this.location, that.location)
160           && Objects.equals(this.keyRing, that.keyRing);
161     }
162     return false;
163   }
164 
165   @Override
hashCode()166   public int hashCode() {
167     int h = 1;
168     h *= 1000003;
169     h ^= Objects.hashCode(project);
170     h *= 1000003;
171     h ^= Objects.hashCode(location);
172     h *= 1000003;
173     h ^= Objects.hashCode(keyRing);
174     return h;
175   }
176 
177   /** Builder for projects/{project}/locations/{location}/keyRings/{key_ring}. */
178   public static class Builder {
179     private String project;
180     private String location;
181     private String keyRing;
182 
Builder()183     protected Builder() {}
184 
getProject()185     public String getProject() {
186       return project;
187     }
188 
getLocation()189     public String getLocation() {
190       return location;
191     }
192 
getKeyRing()193     public String getKeyRing() {
194       return keyRing;
195     }
196 
setProject(String project)197     public Builder setProject(String project) {
198       this.project = project;
199       return this;
200     }
201 
setLocation(String location)202     public Builder setLocation(String location) {
203       this.location = location;
204       return this;
205     }
206 
setKeyRing(String keyRing)207     public Builder setKeyRing(String keyRing) {
208       this.keyRing = keyRing;
209       return this;
210     }
211 
Builder(KeyRingName keyRingName)212     private Builder(KeyRingName keyRingName) {
213       this.project = keyRingName.project;
214       this.location = keyRingName.location;
215       this.keyRing = keyRingName.keyRing;
216     }
217 
build()218     public KeyRingName build() {
219       return new KeyRingName(this);
220     }
221   }
222 }
223