View Javadoc
1   /*
2    *    Copyright 2006-2023 the original author or authors.
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  package org.mybatis.generator.api.dom.kotlin;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  import java.util.Objects;
21  import java.util.Optional;
22  
23  public class KotlinArg {
24  
25      private final String name;
26      private final String dataType;
27      private final String initializationString;
28      private final List<String> annotations;
29  
30      private KotlinArg(Builder builder) {
31          name = Objects.requireNonNull(builder.name);
32          dataType = builder.dataType;
33          initializationString = builder.initializationString;
34          annotations = builder.annotations;
35      }
36  
37      public String getName() {
38          return name;
39      }
40  
41      public Optional<String> getInitializationString() {
42          return Optional.ofNullable(initializationString);
43      }
44  
45      public Optional<String> getDataType() {
46          return Optional.ofNullable(dataType);
47      }
48  
49      public List<String> getAnnotations() {
50          return annotations;
51      }
52  
53      public static Builder newArg(String name) {
54          return new Builder(name);
55      }
56  
57      public static class Builder {
58          private final String name;
59          private String dataType;
60          private String initializationString;
61          private final List<String> annotations = new ArrayList<>();
62  
63          private Builder(String name) {
64              this.name = name;
65          }
66  
67          public Builder withInitializationString(String initializationString) {
68              this.initializationString = initializationString;
69              return this;
70          }
71  
72          public Builder withDataType(String dataType) {
73              this.dataType = dataType;
74              return this;
75          }
76  
77          public Builder withAnnotation(String annotation) {
78              annotations.add(annotation);
79              return this;
80          }
81  
82          public KotlinArg build() {
83              return new KotlinArg(this);
84          }
85      }
86  }