• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 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 io.grafeas.v1beta1;
18 
19 import com.google.api.pathtemplate.PathTemplate;
20 import com.google.common.base.Preconditions;
21 import com.google.common.collect.ImmutableMap;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.Map;
25 
26 /** AUTO-GENERATED DOCUMENTATION AND CLASS */
27 @javax.annotation.Generated("by GAPIC protoc plugin")
28 public class NoteName extends IamResourceName {
29 
30   private static final PathTemplate PATH_TEMPLATE =
31       PathTemplate.createWithoutUrlEncoding("projects/{project}/notes/{note}");
32 
33   private volatile Map<String, String> fieldValuesMap;
34 
35   private final String project;
36   private final String note;
37 
getProject()38   public String getProject() {
39     return project;
40   }
41 
getNote()42   public String getNote() {
43     return note;
44   }
45 
newBuilder()46   public static Builder newBuilder() {
47     return new Builder();
48   }
49 
toBuilder()50   public Builder toBuilder() {
51     return new Builder(this);
52   }
53 
NoteName(Builder builder)54   private NoteName(Builder builder) {
55     project = Preconditions.checkNotNull(builder.getProject());
56     note = Preconditions.checkNotNull(builder.getNote());
57   }
58 
of(String project, String note)59   public static NoteName of(String project, String note) {
60     return newBuilder().setProject(project).setNote(note).build();
61   }
62 
format(String project, String note)63   public static String format(String project, String note) {
64     return newBuilder().setProject(project).setNote(note).build().toString();
65   }
66 
parse(String formattedString)67   public static NoteName parse(String formattedString) {
68     if (formattedString.isEmpty()) {
69       return null;
70     }
71     Map<String, String> matchMap =
72         PATH_TEMPLATE.validatedMatch(
73             formattedString, "NoteName.parse: formattedString not in valid format");
74     return of(matchMap.get("project"), matchMap.get("note"));
75   }
76 
parseList(List<String> formattedStrings)77   public static List<NoteName> parseList(List<String> formattedStrings) {
78     List<NoteName> list = new ArrayList<>(formattedStrings.size());
79     for (String formattedString : formattedStrings) {
80       list.add(parse(formattedString));
81     }
82     return list;
83   }
84 
toStringList(List<NoteName> values)85   public static List<String> toStringList(List<NoteName> values) {
86     List<String> list = new ArrayList<String>(values.size());
87     for (NoteName value : values) {
88       if (value == null) {
89         list.add("");
90       } else {
91         list.add(value.toString());
92       }
93     }
94     return list;
95   }
96 
isParsableFrom(String formattedString)97   public static boolean isParsableFrom(String formattedString) {
98     return PATH_TEMPLATE.matches(formattedString);
99   }
100 
getFieldValuesMap()101   public Map<String, String> getFieldValuesMap() {
102     if (fieldValuesMap == null) {
103       synchronized (this) {
104         if (fieldValuesMap == null) {
105           ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder();
106           fieldMapBuilder.put("project", project);
107           fieldMapBuilder.put("note", note);
108           fieldValuesMap = fieldMapBuilder.build();
109         }
110       }
111     }
112     return fieldValuesMap;
113   }
114 
getFieldValue(String fieldName)115   public String getFieldValue(String fieldName) {
116     return getFieldValuesMap().get(fieldName);
117   }
118 
119   @Override
toString()120   public String toString() {
121     return PATH_TEMPLATE.instantiate("project", project, "note", note);
122   }
123 
124   /** Builder for NoteName. */
125   public static class Builder {
126 
127     private String project;
128     private String note;
129 
getProject()130     public String getProject() {
131       return project;
132     }
133 
getNote()134     public String getNote() {
135       return note;
136     }
137 
setProject(String project)138     public Builder setProject(String project) {
139       this.project = project;
140       return this;
141     }
142 
setNote(String note)143     public Builder setNote(String note) {
144       this.note = note;
145       return this;
146     }
147 
Builder()148     private Builder() {}
149 
Builder(NoteName noteName)150     private Builder(NoteName noteName) {
151       project = noteName.project;
152       note = noteName.note;
153     }
154 
build()155     public NoteName build() {
156       return new NoteName(this);
157     }
158   }
159 
160   @Override
equals(Object o)161   public boolean equals(Object o) {
162     if (o == this) {
163       return true;
164     }
165     if (o instanceof NoteName) {
166       NoteName that = (NoteName) o;
167       return (this.project.equals(that.project)) && (this.note.equals(that.note));
168     }
169     return false;
170   }
171 
172   @Override
hashCode()173   public int hashCode() {
174     int h = 1;
175     h *= 1000003;
176     h ^= project.hashCode();
177     h *= 1000003;
178     h ^= note.hashCode();
179     return h;
180   }
181 }
182