View Javadoc
1   /*
2    *    Copyright 2006-2026 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  import java.util.Objects;
24  
25  import org.jspecify.annotations.Nullable;
26  
27  public class IgnoredColumn {
28      protected final String columnName;
29      private final boolean isColumnNameDelimited;
30  
31      public IgnoredColumn(@Nullable String columnName, boolean isColumnNameDelimited) {
32          this.columnName = Objects.requireNonNull(columnName);
33          this.isColumnNameDelimited = isColumnNameDelimited || stringContainsSpace(columnName);
34      }
35  
36      public String getColumnName() {
37          return columnName;
38      }
39  
40      @Override
41      public boolean equals(Object obj) {
42          if (!(obj instanceof IgnoredColumn)) {
43              return false;
44          }
45  
46          return columnName.equals(((IgnoredColumn) obj).getColumnName());
47      }
48  
49      @Override
50      public int hashCode() {
51          return columnName.hashCode();
52      }
53  
54      public void validate(List<String> errors, String tableName) {
55          if (!stringHasValue(columnName)) {
56              errors.add(getString("ValidationError.21", tableName)); //$NON-NLS-1$
57          }
58      }
59  
60      public boolean matches(String columnName) {
61          if (isColumnNameDelimited) {
62              return this.columnName.equals(columnName);
63          } else {
64              return this.columnName.equalsIgnoreCase(columnName);
65          }
66      }
67  }