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.runtime.dynamic.sql.elements;
17  
18  import java.util.HashSet;
19  import java.util.Set;
20  
21  import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
22  import org.mybatis.generator.api.dom.java.Method;
23  
24  public class MethodAndImports {
25  
26      private final Method method;
27      private final Set<FullyQualifiedJavaType> imports;
28      private final Set<String> staticImports;
29  
30      private MethodAndImports(Builder builder) {
31          method = builder.method;
32          imports = builder.imports;
33          staticImports = builder.staticImports;
34      }
35  
36      public Method getMethod() {
37          return method;
38      }
39  
40      public Set<FullyQualifiedJavaType> getImports() {
41          return imports;
42      }
43  
44      public Set<String> getStaticImports() {
45          return staticImports;
46      }
47  
48      public static Builder withMethod(Method method) {
49          return new Builder().withMethod(method);
50      }
51  
52      public static class Builder {
53          private Method method;
54          private final Set<FullyQualifiedJavaType> imports = new HashSet<>();
55          private final Set<String> staticImports = new HashSet<>();
56  
57          public Builder withMethod(Method method) {
58              this.method = method;
59              return this;
60          }
61  
62          public Builder withImport(FullyQualifiedJavaType importedType) {
63              this.imports.add(importedType);
64              return this;
65          }
66  
67          public Builder withImports(Set<FullyQualifiedJavaType> imports) {
68              this.imports.addAll(imports);
69              return this;
70          }
71  
72          public Builder withStaticImport(String staticImport) {
73              this.staticImports.add(staticImport);
74              return this;
75          }
76  
77          public Builder withStaticImports(Set<String> staticImports) {
78              this.staticImports.addAll(staticImports);
79              return this;
80          }
81  
82          public MethodAndImports build() {
83              return new MethodAndImports(this);
84          }
85      }
86  }