View Javadoc
1   /*
2    *    Copyright 2016-2025 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.dynamic.sql.util;
17  
18  import java.util.Collection;
19  
20  import org.jspecify.annotations.Nullable;
21  import org.mybatis.dynamic.sql.exception.InvalidSqlException;
22  
23  public class Validator {
24      private Validator() {}
25  
26      public static void assertNotEmpty(Collection<?> collection, String messageNumber) {
27          assertFalse(collection.isEmpty(), messageNumber);
28      }
29  
30      public static void assertNotEmpty(Collection<?> collection, String messageNumber, String p1) {
31          assertFalse(collection.isEmpty(), messageNumber, p1);
32      }
33  
34      public static void assertFalse(boolean condition, String messageNumber) {
35          if (condition) {
36              throw new InvalidSqlException(Messages.getString(messageNumber));
37          }
38      }
39  
40      public static void assertFalse(boolean condition, String messageNumber, String p1) {
41          if (condition) {
42              throw new InvalidSqlException(Messages.getString(messageNumber, p1));
43          }
44      }
45  
46      public static void assertTrue(boolean condition, String messageNumber) {
47          assertFalse(!condition, messageNumber);
48      }
49  
50      public static void assertTrue(boolean condition, String messageNumber, String p1) {
51          assertFalse(!condition, messageNumber, p1);
52      }
53  
54      public static void assertNull(@Nullable Object object, String messageNumber) {
55          if (object != null) {
56              throw new InvalidSqlException(Messages.getString(messageNumber));
57          }
58      }
59  }