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