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