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.config;
17  
18  import static org.mybatis.generator.internal.util.StringUtility.stringContainsSpace;
19  import static org.mybatis.generator.internal.util.StringUtility.stringHasValue;
20  import static org.mybatis.generator.internal.util.messages.Messages.getString;
21  
22  import java.util.List;
23  
24  public class IgnoredColumn {
25  
26      protected final String columnName;
27  
28      private boolean isColumnNameDelimited;
29  
30      public IgnoredColumn(String columnName) {
31          super();
32          this.columnName = columnName;
33          isColumnNameDelimited = stringContainsSpace(columnName);
34      }
35  
36      public String getColumnName() {
37          return columnName;
38      }
39  
40      public void setColumnNameDelimited(boolean isColumnNameDelimited) {
41          this.isColumnNameDelimited = isColumnNameDelimited;
42      }
43  
44      @Override
45      public boolean equals(Object obj) {
46          if (!(obj instanceof IgnoredColumn)) {
47              return false;
48          }
49  
50          return columnName.equals(((IgnoredColumn) obj).getColumnName());
51      }
52  
53      @Override
54      public int hashCode() {
55          return columnName.hashCode();
56      }
57  
58      public void validate(List<String> errors, String tableName) {
59          if (!stringHasValue(columnName)) {
60              errors.add(getString("ValidationError.21", //$NON-NLS-1$
61                      tableName));
62          }
63      }
64  
65      public boolean matches(String columnName) {
66          if (isColumnNameDelimited) {
67              return this.columnName.equals(columnName);
68          } else {
69              return this.columnName.equalsIgnoreCase(columnName);
70          }
71      }
72  }