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