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