• 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.recommender.v1;
18 
19 import com.google.api.core.BetaApi;
20 import com.google.api.pathtemplate.PathTemplate;
21 import com.google.api.pathtemplate.ValidationException;
22 import com.google.api.resourcenames.ResourceName;
23 import com.google.common.base.Preconditions;
24 import com.google.common.collect.ImmutableMap;
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Objects;
29 import javax.annotation.Generated;
30 
31 // AUTO-GENERATED DOCUMENTATION AND CLASS.
32 @Generated("by gapic-generator-java")
33 public class InsightName implements ResourceName {
34   private static final PathTemplate PROJECT_LOCATION_INSIGHT_TYPE_INSIGHT =
35       PathTemplate.createWithoutUrlEncoding(
36           "projects/{project}/locations/{location}/insightTypes/{insight_type}/insights/{insight}");
37   private static final PathTemplate BILLING_ACCOUNT_LOCATION_INSIGHT_TYPE_INSIGHT =
38       PathTemplate.createWithoutUrlEncoding(
39           "billingAccounts/{billing_account}/locations/{location}/insightTypes/{insight_type}/insights/{insight}");
40   private static final PathTemplate FOLDER_LOCATION_INSIGHT_TYPE_INSIGHT =
41       PathTemplate.createWithoutUrlEncoding(
42           "folders/{folder}/locations/{location}/insightTypes/{insight_type}/insights/{insight}");
43   private static final PathTemplate ORGANIZATION_LOCATION_INSIGHT_TYPE_INSIGHT =
44       PathTemplate.createWithoutUrlEncoding(
45           "organizations/{organization}/locations/{location}/insightTypes/{insight_type}/insights/{insight}");
46   private volatile Map<String, String> fieldValuesMap;
47   private PathTemplate pathTemplate;
48   private String fixedValue;
49   private final String project;
50   private final String location;
51   private final String insightType;
52   private final String insight;
53   private final String billingAccount;
54   private final String folder;
55   private final String organization;
56 
57   @Deprecated
InsightName()58   protected InsightName() {
59     project = null;
60     location = null;
61     insightType = null;
62     insight = null;
63     billingAccount = null;
64     folder = null;
65     organization = null;
66   }
67 
InsightName(Builder builder)68   private InsightName(Builder builder) {
69     project = Preconditions.checkNotNull(builder.getProject());
70     location = Preconditions.checkNotNull(builder.getLocation());
71     insightType = Preconditions.checkNotNull(builder.getInsightType());
72     insight = Preconditions.checkNotNull(builder.getInsight());
73     billingAccount = null;
74     folder = null;
75     organization = null;
76     pathTemplate = PROJECT_LOCATION_INSIGHT_TYPE_INSIGHT;
77   }
78 
InsightName(BillingAccountLocationInsightTypeInsightBuilder builder)79   private InsightName(BillingAccountLocationInsightTypeInsightBuilder builder) {
80     billingAccount = Preconditions.checkNotNull(builder.getBillingAccount());
81     location = Preconditions.checkNotNull(builder.getLocation());
82     insightType = Preconditions.checkNotNull(builder.getInsightType());
83     insight = Preconditions.checkNotNull(builder.getInsight());
84     project = null;
85     folder = null;
86     organization = null;
87     pathTemplate = BILLING_ACCOUNT_LOCATION_INSIGHT_TYPE_INSIGHT;
88   }
89 
InsightName(FolderLocationInsightTypeInsightBuilder builder)90   private InsightName(FolderLocationInsightTypeInsightBuilder builder) {
91     folder = Preconditions.checkNotNull(builder.getFolder());
92     location = Preconditions.checkNotNull(builder.getLocation());
93     insightType = Preconditions.checkNotNull(builder.getInsightType());
94     insight = Preconditions.checkNotNull(builder.getInsight());
95     project = null;
96     billingAccount = null;
97     organization = null;
98     pathTemplate = FOLDER_LOCATION_INSIGHT_TYPE_INSIGHT;
99   }
100 
InsightName(OrganizationLocationInsightTypeInsightBuilder builder)101   private InsightName(OrganizationLocationInsightTypeInsightBuilder builder) {
102     organization = Preconditions.checkNotNull(builder.getOrganization());
103     location = Preconditions.checkNotNull(builder.getLocation());
104     insightType = Preconditions.checkNotNull(builder.getInsightType());
105     insight = Preconditions.checkNotNull(builder.getInsight());
106     project = null;
107     billingAccount = null;
108     folder = null;
109     pathTemplate = ORGANIZATION_LOCATION_INSIGHT_TYPE_INSIGHT;
110   }
111 
getProject()112   public String getProject() {
113     return project;
114   }
115 
getLocation()116   public String getLocation() {
117     return location;
118   }
119 
getInsightType()120   public String getInsightType() {
121     return insightType;
122   }
123 
getInsight()124   public String getInsight() {
125     return insight;
126   }
127 
getBillingAccount()128   public String getBillingAccount() {
129     return billingAccount;
130   }
131 
getFolder()132   public String getFolder() {
133     return folder;
134   }
135 
getOrganization()136   public String getOrganization() {
137     return organization;
138   }
139 
newBuilder()140   public static Builder newBuilder() {
141     return new Builder();
142   }
143 
144   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
newProjectLocationInsightTypeInsightBuilder()145   public static Builder newProjectLocationInsightTypeInsightBuilder() {
146     return new Builder();
147   }
148 
149   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
150   public static BillingAccountLocationInsightTypeInsightBuilder
newBillingAccountLocationInsightTypeInsightBuilder()151       newBillingAccountLocationInsightTypeInsightBuilder() {
152     return new BillingAccountLocationInsightTypeInsightBuilder();
153   }
154 
155   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
156   public static FolderLocationInsightTypeInsightBuilder
newFolderLocationInsightTypeInsightBuilder()157       newFolderLocationInsightTypeInsightBuilder() {
158     return new FolderLocationInsightTypeInsightBuilder();
159   }
160 
161   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
162   public static OrganizationLocationInsightTypeInsightBuilder
newOrganizationLocationInsightTypeInsightBuilder()163       newOrganizationLocationInsightTypeInsightBuilder() {
164     return new OrganizationLocationInsightTypeInsightBuilder();
165   }
166 
toBuilder()167   public Builder toBuilder() {
168     return new Builder(this);
169   }
170 
of( String project, String location, String insightType, String insight)171   public static InsightName of(
172       String project, String location, String insightType, String insight) {
173     return newBuilder()
174         .setProject(project)
175         .setLocation(location)
176         .setInsightType(insightType)
177         .setInsight(insight)
178         .build();
179   }
180 
181   @BetaApi("The static create methods are not stable yet and may be changed in the future.")
ofProjectLocationInsightTypeInsightName( String project, String location, String insightType, String insight)182   public static InsightName ofProjectLocationInsightTypeInsightName(
183       String project, String location, String insightType, String insight) {
184     return newBuilder()
185         .setProject(project)
186         .setLocation(location)
187         .setInsightType(insightType)
188         .setInsight(insight)
189         .build();
190   }
191 
192   @BetaApi("The static create methods are not stable yet and may be changed in the future.")
ofBillingAccountLocationInsightTypeInsightName( String billingAccount, String location, String insightType, String insight)193   public static InsightName ofBillingAccountLocationInsightTypeInsightName(
194       String billingAccount, String location, String insightType, String insight) {
195     return newBillingAccountLocationInsightTypeInsightBuilder()
196         .setBillingAccount(billingAccount)
197         .setLocation(location)
198         .setInsightType(insightType)
199         .setInsight(insight)
200         .build();
201   }
202 
203   @BetaApi("The static create methods are not stable yet and may be changed in the future.")
ofFolderLocationInsightTypeInsightName( String folder, String location, String insightType, String insight)204   public static InsightName ofFolderLocationInsightTypeInsightName(
205       String folder, String location, String insightType, String insight) {
206     return newFolderLocationInsightTypeInsightBuilder()
207         .setFolder(folder)
208         .setLocation(location)
209         .setInsightType(insightType)
210         .setInsight(insight)
211         .build();
212   }
213 
214   @BetaApi("The static create methods are not stable yet and may be changed in the future.")
ofOrganizationLocationInsightTypeInsightName( String organization, String location, String insightType, String insight)215   public static InsightName ofOrganizationLocationInsightTypeInsightName(
216       String organization, String location, String insightType, String insight) {
217     return newOrganizationLocationInsightTypeInsightBuilder()
218         .setOrganization(organization)
219         .setLocation(location)
220         .setInsightType(insightType)
221         .setInsight(insight)
222         .build();
223   }
224 
format(String project, String location, String insightType, String insight)225   public static String format(String project, String location, String insightType, String insight) {
226     return newBuilder()
227         .setProject(project)
228         .setLocation(location)
229         .setInsightType(insightType)
230         .setInsight(insight)
231         .build()
232         .toString();
233   }
234 
235   @BetaApi("The static format methods are not stable yet and may be changed in the future.")
formatProjectLocationInsightTypeInsightName( String project, String location, String insightType, String insight)236   public static String formatProjectLocationInsightTypeInsightName(
237       String project, String location, String insightType, String insight) {
238     return newBuilder()
239         .setProject(project)
240         .setLocation(location)
241         .setInsightType(insightType)
242         .setInsight(insight)
243         .build()
244         .toString();
245   }
246 
247   @BetaApi("The static format methods are not stable yet and may be changed in the future.")
formatBillingAccountLocationInsightTypeInsightName( String billingAccount, String location, String insightType, String insight)248   public static String formatBillingAccountLocationInsightTypeInsightName(
249       String billingAccount, String location, String insightType, String insight) {
250     return newBillingAccountLocationInsightTypeInsightBuilder()
251         .setBillingAccount(billingAccount)
252         .setLocation(location)
253         .setInsightType(insightType)
254         .setInsight(insight)
255         .build()
256         .toString();
257   }
258 
259   @BetaApi("The static format methods are not stable yet and may be changed in the future.")
formatFolderLocationInsightTypeInsightName( String folder, String location, String insightType, String insight)260   public static String formatFolderLocationInsightTypeInsightName(
261       String folder, String location, String insightType, String insight) {
262     return newFolderLocationInsightTypeInsightBuilder()
263         .setFolder(folder)
264         .setLocation(location)
265         .setInsightType(insightType)
266         .setInsight(insight)
267         .build()
268         .toString();
269   }
270 
271   @BetaApi("The static format methods are not stable yet and may be changed in the future.")
formatOrganizationLocationInsightTypeInsightName( String organization, String location, String insightType, String insight)272   public static String formatOrganizationLocationInsightTypeInsightName(
273       String organization, String location, String insightType, String insight) {
274     return newOrganizationLocationInsightTypeInsightBuilder()
275         .setOrganization(organization)
276         .setLocation(location)
277         .setInsightType(insightType)
278         .setInsight(insight)
279         .build()
280         .toString();
281   }
282 
parse(String formattedString)283   public static InsightName parse(String formattedString) {
284     if (formattedString.isEmpty()) {
285       return null;
286     }
287     if (PROJECT_LOCATION_INSIGHT_TYPE_INSIGHT.matches(formattedString)) {
288       Map<String, String> matchMap = PROJECT_LOCATION_INSIGHT_TYPE_INSIGHT.match(formattedString);
289       return ofProjectLocationInsightTypeInsightName(
290           matchMap.get("project"),
291           matchMap.get("location"),
292           matchMap.get("insight_type"),
293           matchMap.get("insight"));
294     } else if (BILLING_ACCOUNT_LOCATION_INSIGHT_TYPE_INSIGHT.matches(formattedString)) {
295       Map<String, String> matchMap =
296           BILLING_ACCOUNT_LOCATION_INSIGHT_TYPE_INSIGHT.match(formattedString);
297       return ofBillingAccountLocationInsightTypeInsightName(
298           matchMap.get("billing_account"),
299           matchMap.get("location"),
300           matchMap.get("insight_type"),
301           matchMap.get("insight"));
302     } else if (FOLDER_LOCATION_INSIGHT_TYPE_INSIGHT.matches(formattedString)) {
303       Map<String, String> matchMap = FOLDER_LOCATION_INSIGHT_TYPE_INSIGHT.match(formattedString);
304       return ofFolderLocationInsightTypeInsightName(
305           matchMap.get("folder"),
306           matchMap.get("location"),
307           matchMap.get("insight_type"),
308           matchMap.get("insight"));
309     } else if (ORGANIZATION_LOCATION_INSIGHT_TYPE_INSIGHT.matches(formattedString)) {
310       Map<String, String> matchMap =
311           ORGANIZATION_LOCATION_INSIGHT_TYPE_INSIGHT.match(formattedString);
312       return ofOrganizationLocationInsightTypeInsightName(
313           matchMap.get("organization"),
314           matchMap.get("location"),
315           matchMap.get("insight_type"),
316           matchMap.get("insight"));
317     }
318     throw new ValidationException("InsightName.parse: formattedString not in valid format");
319   }
320 
parseList(List<String> formattedStrings)321   public static List<InsightName> parseList(List<String> formattedStrings) {
322     List<InsightName> list = new ArrayList<>(formattedStrings.size());
323     for (String formattedString : formattedStrings) {
324       list.add(parse(formattedString));
325     }
326     return list;
327   }
328 
toStringList(List<InsightName> values)329   public static List<String> toStringList(List<InsightName> values) {
330     List<String> list = new ArrayList<>(values.size());
331     for (InsightName value : values) {
332       if (value == null) {
333         list.add("");
334       } else {
335         list.add(value.toString());
336       }
337     }
338     return list;
339   }
340 
isParsableFrom(String formattedString)341   public static boolean isParsableFrom(String formattedString) {
342     return PROJECT_LOCATION_INSIGHT_TYPE_INSIGHT.matches(formattedString)
343         || BILLING_ACCOUNT_LOCATION_INSIGHT_TYPE_INSIGHT.matches(formattedString)
344         || FOLDER_LOCATION_INSIGHT_TYPE_INSIGHT.matches(formattedString)
345         || ORGANIZATION_LOCATION_INSIGHT_TYPE_INSIGHT.matches(formattedString);
346   }
347 
348   @Override
getFieldValuesMap()349   public Map<String, String> getFieldValuesMap() {
350     if (fieldValuesMap == null) {
351       synchronized (this) {
352         if (fieldValuesMap == null) {
353           ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder();
354           if (project != null) {
355             fieldMapBuilder.put("project", project);
356           }
357           if (location != null) {
358             fieldMapBuilder.put("location", location);
359           }
360           if (insightType != null) {
361             fieldMapBuilder.put("insight_type", insightType);
362           }
363           if (insight != null) {
364             fieldMapBuilder.put("insight", insight);
365           }
366           if (billingAccount != null) {
367             fieldMapBuilder.put("billing_account", billingAccount);
368           }
369           if (folder != null) {
370             fieldMapBuilder.put("folder", folder);
371           }
372           if (organization != null) {
373             fieldMapBuilder.put("organization", organization);
374           }
375           fieldValuesMap = fieldMapBuilder.build();
376         }
377       }
378     }
379     return fieldValuesMap;
380   }
381 
getFieldValue(String fieldName)382   public String getFieldValue(String fieldName) {
383     return getFieldValuesMap().get(fieldName);
384   }
385 
386   @Override
toString()387   public String toString() {
388     return fixedValue != null ? fixedValue : pathTemplate.instantiate(getFieldValuesMap());
389   }
390 
391   @Override
equals(Object o)392   public boolean equals(Object o) {
393     if (o == this) {
394       return true;
395     }
396     if (o != null || getClass() == o.getClass()) {
397       InsightName that = ((InsightName) o);
398       return Objects.equals(this.project, that.project)
399           && Objects.equals(this.location, that.location)
400           && Objects.equals(this.insightType, that.insightType)
401           && Objects.equals(this.insight, that.insight)
402           && Objects.equals(this.billingAccount, that.billingAccount)
403           && Objects.equals(this.folder, that.folder)
404           && Objects.equals(this.organization, that.organization);
405     }
406     return false;
407   }
408 
409   @Override
hashCode()410   public int hashCode() {
411     int h = 1;
412     h *= 1000003;
413     h ^= Objects.hashCode(fixedValue);
414     h *= 1000003;
415     h ^= Objects.hashCode(project);
416     h *= 1000003;
417     h ^= Objects.hashCode(location);
418     h *= 1000003;
419     h ^= Objects.hashCode(insightType);
420     h *= 1000003;
421     h ^= Objects.hashCode(insight);
422     h *= 1000003;
423     h ^= Objects.hashCode(billingAccount);
424     h *= 1000003;
425     h ^= Objects.hashCode(folder);
426     h *= 1000003;
427     h ^= Objects.hashCode(organization);
428     return h;
429   }
430 
431   /**
432    * Builder for
433    * projects/{project}/locations/{location}/insightTypes/{insight_type}/insights/{insight}.
434    */
435   public static class Builder {
436     private String project;
437     private String location;
438     private String insightType;
439     private String insight;
440 
Builder()441     protected Builder() {}
442 
getProject()443     public String getProject() {
444       return project;
445     }
446 
getLocation()447     public String getLocation() {
448       return location;
449     }
450 
getInsightType()451     public String getInsightType() {
452       return insightType;
453     }
454 
getInsight()455     public String getInsight() {
456       return insight;
457     }
458 
setProject(String project)459     public Builder setProject(String project) {
460       this.project = project;
461       return this;
462     }
463 
setLocation(String location)464     public Builder setLocation(String location) {
465       this.location = location;
466       return this;
467     }
468 
setInsightType(String insightType)469     public Builder setInsightType(String insightType) {
470       this.insightType = insightType;
471       return this;
472     }
473 
setInsight(String insight)474     public Builder setInsight(String insight) {
475       this.insight = insight;
476       return this;
477     }
478 
Builder(InsightName insightName)479     private Builder(InsightName insightName) {
480       Preconditions.checkArgument(
481           Objects.equals(insightName.pathTemplate, PROJECT_LOCATION_INSIGHT_TYPE_INSIGHT),
482           "toBuilder is only supported when InsightName has the pattern of projects/{project}/locations/{location}/insightTypes/{insight_type}/insights/{insight}");
483       this.project = insightName.project;
484       this.location = insightName.location;
485       this.insightType = insightName.insightType;
486       this.insight = insightName.insight;
487     }
488 
build()489     public InsightName build() {
490       return new InsightName(this);
491     }
492   }
493 
494   /**
495    * Builder for
496    * billingAccounts/{billing_account}/locations/{location}/insightTypes/{insight_type}/insights/{insight}.
497    */
498   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
499   public static class BillingAccountLocationInsightTypeInsightBuilder {
500     private String billingAccount;
501     private String location;
502     private String insightType;
503     private String insight;
504 
BillingAccountLocationInsightTypeInsightBuilder()505     protected BillingAccountLocationInsightTypeInsightBuilder() {}
506 
getBillingAccount()507     public String getBillingAccount() {
508       return billingAccount;
509     }
510 
getLocation()511     public String getLocation() {
512       return location;
513     }
514 
getInsightType()515     public String getInsightType() {
516       return insightType;
517     }
518 
getInsight()519     public String getInsight() {
520       return insight;
521     }
522 
setBillingAccount( String billingAccount)523     public BillingAccountLocationInsightTypeInsightBuilder setBillingAccount(
524         String billingAccount) {
525       this.billingAccount = billingAccount;
526       return this;
527     }
528 
setLocation(String location)529     public BillingAccountLocationInsightTypeInsightBuilder setLocation(String location) {
530       this.location = location;
531       return this;
532     }
533 
setInsightType(String insightType)534     public BillingAccountLocationInsightTypeInsightBuilder setInsightType(String insightType) {
535       this.insightType = insightType;
536       return this;
537     }
538 
setInsight(String insight)539     public BillingAccountLocationInsightTypeInsightBuilder setInsight(String insight) {
540       this.insight = insight;
541       return this;
542     }
543 
build()544     public InsightName build() {
545       return new InsightName(this);
546     }
547   }
548 
549   /**
550    * Builder for
551    * folders/{folder}/locations/{location}/insightTypes/{insight_type}/insights/{insight}.
552    */
553   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
554   public static class FolderLocationInsightTypeInsightBuilder {
555     private String folder;
556     private String location;
557     private String insightType;
558     private String insight;
559 
FolderLocationInsightTypeInsightBuilder()560     protected FolderLocationInsightTypeInsightBuilder() {}
561 
getFolder()562     public String getFolder() {
563       return folder;
564     }
565 
getLocation()566     public String getLocation() {
567       return location;
568     }
569 
getInsightType()570     public String getInsightType() {
571       return insightType;
572     }
573 
getInsight()574     public String getInsight() {
575       return insight;
576     }
577 
setFolder(String folder)578     public FolderLocationInsightTypeInsightBuilder setFolder(String folder) {
579       this.folder = folder;
580       return this;
581     }
582 
setLocation(String location)583     public FolderLocationInsightTypeInsightBuilder setLocation(String location) {
584       this.location = location;
585       return this;
586     }
587 
setInsightType(String insightType)588     public FolderLocationInsightTypeInsightBuilder setInsightType(String insightType) {
589       this.insightType = insightType;
590       return this;
591     }
592 
setInsight(String insight)593     public FolderLocationInsightTypeInsightBuilder setInsight(String insight) {
594       this.insight = insight;
595       return this;
596     }
597 
build()598     public InsightName build() {
599       return new InsightName(this);
600     }
601   }
602 
603   /**
604    * Builder for
605    * organizations/{organization}/locations/{location}/insightTypes/{insight_type}/insights/{insight}.
606    */
607   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
608   public static class OrganizationLocationInsightTypeInsightBuilder {
609     private String organization;
610     private String location;
611     private String insightType;
612     private String insight;
613 
OrganizationLocationInsightTypeInsightBuilder()614     protected OrganizationLocationInsightTypeInsightBuilder() {}
615 
getOrganization()616     public String getOrganization() {
617       return organization;
618     }
619 
getLocation()620     public String getLocation() {
621       return location;
622     }
623 
getInsightType()624     public String getInsightType() {
625       return insightType;
626     }
627 
getInsight()628     public String getInsight() {
629       return insight;
630     }
631 
setOrganization(String organization)632     public OrganizationLocationInsightTypeInsightBuilder setOrganization(String organization) {
633       this.organization = organization;
634       return this;
635     }
636 
setLocation(String location)637     public OrganizationLocationInsightTypeInsightBuilder setLocation(String location) {
638       this.location = location;
639       return this;
640     }
641 
setInsightType(String insightType)642     public OrganizationLocationInsightTypeInsightBuilder setInsightType(String insightType) {
643       this.insightType = insightType;
644       return this;
645     }
646 
setInsight(String insight)647     public OrganizationLocationInsightTypeInsightBuilder setInsight(String insight) {
648       this.insight = insight;
649       return this;
650     }
651 
build()652     public InsightName build() {
653       return new InsightName(this);
654     }
655   }
656 }
657