Explorar o código

refactor: 移除多余的方法和测试

825944942@qq.com %!s(int64=4) %!d(string=hai) anos
pai
achega
4359b2ca57

+ 2 - 2
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/ExceptionUtils.java

@@ -36,7 +36,7 @@ public final class ExceptionUtils {
      * @return 返回异常
      */
     public static MybatisPlusException mpe(String msg, Throwable t, Object... params) {
-        return new MybatisPlusException(StringUtils.format(msg, params), t);
+        return new MybatisPlusException(String.format(msg, params), t);
     }
 
     /**
@@ -46,7 +46,7 @@ public final class ExceptionUtils {
      * @return 返回异常
      */
     public static MybatisPlusException mpe(String msg, Object... params) {
-        return new MybatisPlusException(StringUtils.format(msg, params));
+        return new MybatisPlusException(String.format(msg, params));
     }
 
     /**

+ 0 - 555
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/IOUtils.java

@@ -1,555 +0,0 @@
-/*
- * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * <p>
- * https://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.baomidou.mybatisplus.core.toolkit;
-
-import org.apache.ibatis.logging.Log;
-import org.apache.ibatis.logging.LogFactory;
-
-import java.io.*;
-import java.net.HttpURLConnection;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.net.URLConnection;
-import java.nio.channels.Selector;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.Statement;
-
-/**
- * IOUtils Copy org.apache.commons.io.IOUtils
- *
- * @author Caratacus
- * @since 2016-11-23
- * @deprecated 3.3.0
- */
-@Deprecated
-public class IOUtils {
-
-    private static final Log logger = LogFactory.getLog(IOUtils.class);
-
-    private IOUtils() {
-    }
-
-    /**
-     * Closes a URLConnection.
-     *
-     * @param conn the connection to close.
-     * @since 2.4
-     */
-    public static void close(final URLConnection conn) {
-        if (conn instanceof HttpURLConnection) {
-            ((HttpURLConnection) conn).disconnect();
-        }
-    }
-
-    /**
-     * Closes an <code>Reader</code> unconditionally.
-     * <p>
-     * Equivalent to {@link Reader#close()}, except any exceptions will be ignored. This is typically used in finally
-     * blocks.
-     * <p>
-     * Example code:
-     * <p>
-     * <pre>
-     * char[] data = new char[1024];
-     * Reader in = null;
-     * try {
-     * 	in = new FileReader(&quot;foo.txt&quot;);
-     * 	in.read(data);
-     * 	in.close(); // close errors are handled
-     * } catch (Exception e) {
-     * 	// error handling
-     * } finally {
-     * 	IOUtils.closeQuietly(in);
-     * }
-     * </pre>
-     * </p>
-     *
-     * @param input the Reader to close, may be null or already closed
-     */
-    public static void closeQuietly(final Reader input) {
-        closeQuietly((Closeable) input);
-    }
-
-    /**
-     * Closes an <code>Writer</code> unconditionally.
-     * <p>
-     * Equivalent to {@link Writer#close()}, except any exceptions will be ignored. This is typically used in finally
-     * blocks.
-     * </p>
-     * <p>
-     * Example code:
-     * </p>
-     * <p>
-     * <pre>
-     * Writer out = null;
-     * try {
-     * 	out = new StringWriter();
-     * 	out.write(&quot;Hello World&quot;);
-     * 	out.close(); // close errors are handled
-     * } catch (Exception e) {
-     * 	// error handling
-     * } finally {
-     * 	IOUtils.closeQuietly(out);
-     * }
-     * </pre>
-     * </p>
-     *
-     * @param output the Writer to close, may be null or already closed
-     */
-    public static void closeQuietly(final Writer output) {
-        closeQuietly((Closeable) output);
-    }
-
-    /**
-     * Closes an <code>InputStream</code> unconditionally.
-     * <p>
-     * Equivalent to {@link InputStream#close()}, except any exceptions will be ignored. This is typically used in
-     * finally blocks.
-     * </p>
-     * <p>
-     * Example code:
-     * </p>
-     * <p>
-     * <pre>
-     * byte[] data = new byte[1024];
-     * InputStream in = null;
-     * try {
-     * 	in = new FileInputStream(&quot;foo.txt&quot;);
-     * 	in.read(data);
-     * 	in.close(); // close errors are handled
-     * } catch (Exception e) {
-     * 	// error handling
-     * } finally {
-     * 	IOUtils.closeQuietly(in);
-     * }
-     * </pre>
-     * </p>
-     *
-     * @param input the InputStream to close, may be null or already closed
-     */
-    public static void closeQuietly(final InputStream input) {
-        closeQuietly((Closeable) input);
-    }
-
-    /**
-     * Closes an <code>OutputStream</code> unconditionally.
-     * <p>
-     * Equivalent to {@link OutputStream#close()}, except any exceptions will be ignored. This is typically used in
-     * finally blocks.
-     * </p>
-     * <p>
-     * Example code:
-     * </p>
-     * <p>
-     * <pre>
-     * byte[] data = &quot;Hello, World&quot;.getBytes();
-     *
-     * OutputStream out = null;
-     * try {
-     * 	out = new FileOutputStream(&quot;foo.txt&quot;);
-     * 	out.write(data);
-     * 	out.close(); // close errors are handled
-     * } catch (IOException e) {
-     * 	// error handling
-     * } finally {
-     * 	IOUtils.closeQuietly(out);
-     * }
-     * </pre>
-     * </p>
-     *
-     * @param output the OutputStream to close, may be null or already closed
-     */
-    public static void closeQuietly(final OutputStream output) {
-        closeQuietly((Closeable) output);
-    }
-
-    /**
-     * Closes a <code>Closeable</code> unconditionally.
-     * <p>
-     * Equivalent to {@link Closeable#close()}, except any exceptions will be ignored. This is typically used in finally
-     * blocks.
-     * </p>
-     * <p>
-     * Example code:
-     * </p>
-     * <p>
-     * <pre>
-     * Closeable closeable = null;
-     * try {
-     * 	closeable = new FileReader(&quot;foo.txt&quot;);
-     * 	// process closeable
-     * 	closeable.close();
-     * } catch (Exception e) {
-     * 	// error handling
-     * } finally {
-     * 	IOUtils.closeQuietly(closeable);
-     * }
-     * </pre>
-     * </p>
-     * <p>
-     * Closing all streams:
-     * </p>
-     * <p>
-     * <pre>
-     * try {
-     * 	return IOUtils.copy(inputStream, outputStream);
-     * } finally {
-     * 	IOUtils.closeQuietly(inputStream);
-     * 	IOUtils.closeQuietly(outputStream);
-     * }
-     * </pre>
-     * </p>
-     *
-     * @param closeable the objects to close, may be null or already closed
-     * @since 2.0
-     */
-    public static void closeQuietly(final Closeable closeable) {
-        try {
-            if (closeable != null) {
-                closeable.close();
-            }
-        } catch (final IOException ioe) {
-            logger.error("error close io", ioe);
-        }
-    }
-
-    /**
-     * Closes a <code>Closeable</code> unconditionally.
-     * <p>
-     * Equivalent to {@link Closeable#close()}, except any exceptions will be ignored.
-     * </p>
-     * <p>
-     * This is typically used in finally blocks to ensure that the closeable is closed even if an Exception was thrown
-     * before the normal close statement was reached. <br>
-     * <b>It should not be used to replace the close statement(s) which should be present for the non-exceptional
-     * case.</b> <br>
-     * It is only intended to simplify tidying up where normal processing has already failed and reporting close failure
-     * as well is not necessary or useful.
-     * </p>
-     * <p>
-     * Example code:
-     * </p>
-     * <p>
-     * <pre>
-     * Closeable closeable = null;
-     * try {
-     *     closeable = new FileReader(&quot;foo.txt&quot;);
-     *     // processing using the closeable; may throw an Exception
-     *     closeable.close(); // Normal close - exceptions not ignored
-     * } catch (Exception e) {
-     *     // error handling
-     * } finally {
-     *     <b>IOUtils.closeQuietly(closeable); // In case normal close was skipped due to Exception</b>
-     * }
-     * </pre>
-     * </p>
-     * <p>
-     * Closing all streams: <br>
-     * </p>
-     * <p>
-     * <pre>
-     * try {
-     * 	return IOUtils.copy(inputStream, outputStream);
-     * } finally {
-     * 	IOUtils.closeQuietly(inputStream, outputStream);
-     * }
-     * </pre>
-     * </p>
-     *
-     * @param closeables the objects to close, may be null or already closed
-     * @see #closeQuietly(Closeable)
-     * @since 2.5
-     */
-    public static void closeQuietly(final Closeable... closeables) {
-        if (closeables == null) {
-            return;
-        }
-        for (final Closeable closeable : closeables) {
-            closeQuietly(closeable);
-        }
-    }
-
-    /**
-     * Closes a <code>Socket</code> unconditionally.
-     * <p>
-     * Equivalent to {@link Socket#close()}, except any exceptions will be ignored. This is typically used in finally
-     * blocks.
-     * </p>
-     * <p>
-     * Example code:
-     * </p>
-     * <p>
-     * <pre>
-     * Socket socket = null;
-     * try {
-     * 	socket = new Socket(&quot;https://www.foo.com/&quot;, 443);
-     * 	// process socket
-     * 	socket.close();
-     * } catch (Exception e) {
-     * 	// error handling
-     * } finally {
-     * 	IOUtils.closeQuietly(socket);
-     * }
-     * </pre>
-     * </p>
-     *
-     * @param sock the Socket to close, may be null or already closed
-     * @since 2.0
-     */
-    public static void closeQuietly(final Socket sock) {
-        if (sock != null) {
-            try {
-                sock.close();
-            } catch (final IOException ioe) {
-                logger.error("error close io", ioe);
-            }
-        }
-    }
-
-    /**
-     * Closes a <code>Selector</code> unconditionally.
-     * <p>
-     * Equivalent to {@link Selector#close()}, except any exceptions will be ignored. This is typically used in finally
-     * blocks.
-     * </p>
-     * <p>
-     * Example code:
-     * </p>
-     * <p>
-     * <pre>
-     * Selector selector = null;
-     * try {
-     * 	selector = Selector.open();
-     * 	// process socket
-     *
-     * } catch (Exception e) {
-     * 	// error handling
-     * } finally {
-     * 	IOUtils.closeQuietly(selector);
-     * }
-     * </pre>
-     * </p>
-     *
-     * @param selector the Selector to close, may be null or already closed
-     * @since 2.2
-     */
-    public static void closeQuietly(final Selector selector) {
-        if (selector != null) {
-            try {
-                selector.close();
-            } catch (final IOException ioe) {
-                logger.error("error close io", ioe);
-            }
-        }
-    }
-
-    /**
-     * Closes a <code>ServerSocket</code> unconditionally.
-     * <p>
-     * Equivalent to {@link ServerSocket#close()}, except any exceptions will be ignored. This is typically used in
-     * finally blocks.
-     * </p>
-     * <p>
-     * Example code:
-     * </p>
-     * <p>
-     * <pre>
-     * ServerSocket socket = null;
-     * try {
-     * 	socket = new ServerSocket();
-     * 	// process socket
-     * 	socket.close();
-     * } catch (Exception e) {
-     * 	// error handling
-     * } finally {
-     * 	IOUtils.closeQuietly(socket);
-     * }
-     * </pre>
-     * </p>
-     *
-     * @param sock the ServerSocket to close, may be null or already closed
-     * @since 2.2
-     */
-    public static void closeQuietly(final ServerSocket sock) {
-        if (sock != null) {
-            try {
-                sock.close();
-            } catch (final IOException ioe) {
-                logger.error("error close io", ioe);
-            }
-        }
-    }
-
-    /**
-     * Closes a <code>Connection</code> unconditionally.
-     * <p>
-     * Equivalent to {@link Connection#close()}, except any exceptions will be ignored. This is typically used in
-     * finally blocks.
-     * </p>
-     * <p>
-     * Example code:
-     * </p>
-     * <p>
-     * <pre>
-     * Connection conn = null;
-     * try {
-     * 	conn = new Connection();
-     * 	// process close
-     * 	conn.close();
-     * } catch (Exception e) {
-     * 	// error handling
-     * } finally {
-     * 	IOUtils.closeQuietly(conn);
-     * }
-     * </pre>
-     * </p>
-     *
-     * @param conn the Connection to close, may be null or already closed
-     * @since 2.2
-     */
-    public static void closeQuietly(final Connection conn) {
-        if (conn != null) {
-            try {
-                conn.close();
-            } catch (Exception e) {
-                logger.error("error close conn", e);
-            }
-        }
-    }
-
-    /**
-     * Closes a <code>AutoCloseable</code> unconditionally.
-     * <p>
-     * Equivalent to {@link ResultSet#close()}, except any exceptions will be ignored. This is typically used in finally
-     * blocks.
-     * </p>
-     * <p>
-     * Example code:
-     * </p>
-     * <p>
-     * <pre>
-     * AutoCloseable statement = null;
-     * try {
-     * 	statement = new Connection();
-     * 	// process close
-     * 	statement.close();
-     * } catch (Exception e) {
-     * 	// error handling
-     * } finally {
-     * 	IOUtils.closeQuietly(conn);
-     * }
-     * </pre>
-     * </p>
-     *
-     * @param resultSet the Connection to close, may be null or already closed
-     * @since 2.2
-     */
-    public static void closeQuietly(final ResultSet resultSet) {
-        if (resultSet != null) {
-            try {
-                resultSet.close();
-            } catch (Exception e) {
-                logger.error("error close resultSet", e);
-            }
-        }
-    }
-
-    /**
-     * Closes a <code>AutoCloseable</code> unconditionally.
-     * <p>
-     * Equivalent to {@link Statement#close()}, except any exceptions will be ignored. This is typically used in finally
-     * blocks.
-     * </p>
-     * <p>
-     * Example code:
-     * </p>
-     * <p>
-     * <pre>
-     * AutoCloseable statement = null;
-     * try {
-     * 	statement = new Connection();
-     * 	// process close
-     * 	statement.close();
-     * } catch (Exception e) {
-     * 	// error handling
-     * } finally {
-     * 	IOUtils.closeQuietly(conn);
-     * }
-     * </pre>
-     * </p>
-     *
-     * @param statement the Connection to close, may be null or already closed
-     * @since 2.2
-     */
-    public static void closeQuietly(final Statement statement) {
-        if (statement != null) {
-            try {
-                statement.close();
-            } catch (Exception e) {
-                logger.error("error close statement", e);
-            }
-        }
-    }
-
-    /**
-     * Closes a <code>AutoCloseable</code> unconditionally.
-     * <p>
-     * Equivalent to {@link AutoCloseable#close()}, except any exceptions will be ignored.
-     * </p>
-     * <p>
-     * This is typically used in finally blocks to ensure that the closeable is closed even if an Exception was thrown
-     * before the normal close statement was reached. <br>
-     * <b>It should not be used to replace the close statement(s) which should be present for the non-exceptional
-     * case.</b> <br>
-     * It is only intended to simplify tidying up where normal processing has already failed and reporting close failure
-     * as well is not necessary or useful.
-     * </p>
-     * <p>
-     * Example code:
-     * </p>
-     * <p>
-     * <pre>
-     * AutoCloseable closeable = null;
-     * try {
-     *     closeable = new AutoCloseable();
-     *     // processing using the closeable; may throw an Exception
-     *     closeable.close(); // Normal close - exceptions not ignored
-     * } catch (Exception e) {
-     *     // error handling
-     * } finally {
-     *     <b>IOUtils.closeQuietly(closeable); // In case normal close was skipped due to Exception</b>
-     * }
-     * </pre>
-     * </p>
-     * <p>
-     * Closing all streams: <br>
-     * </p>
-     *
-     * @param statements the objects to close, may be null or already closed
-     * @see #closeQuietly(Statement)
-     * @since 2.5
-     */
-    public static void closeQuietly(final Statement... statements) {
-        if (statements == null) {
-            return;
-        }
-        for (final Statement statement : statements) {
-            closeQuietly(statement);
-        }
-    }
-
-}

+ 19 - 106
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/ReflectionKit.java

@@ -18,7 +18,10 @@ package com.baomidou.mybatisplus.core.toolkit;
 import org.apache.ibatis.logging.Log;
 import org.apache.ibatis.logging.LogFactory;
 
-import java.lang.reflect.*;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
@@ -54,22 +57,6 @@ public final class ReflectionKit {
         PRIMITIVE_WRAPPER_TYPE_MAP.put(Short.class, short.class);
     }
 
-    /**
-     * <p>
-     * 反射 method 方法名,例如 getId
-     * </p>
-     *
-     * @param field
-     * @param str   属性字符串内容
-     * @deprecated 3.3.0 {@link #guessGetterName(Field, String)}
-     */
-    @Deprecated
-    public static String getMethodCapitalize(Field field, final String str) {
-        Class<?> fieldType = field.getType();
-        // fix #176
-        return StringUtils.guessGetterName(str, fieldType);
-    }
-
     /**
      * <p>
      * 反射 method 方法名,例如 setVersion
@@ -84,34 +71,7 @@ public final class ReflectionKit {
     public static String setMethodCapitalize(Field field, final String str) {
         return StringUtils.concatCapitalize("set", str);
     }
-    
-    /**
-     * <p>
-     * 获取 public get方法的值
-     * </p>
-     *
-     * @param cls    ignore
-     * @param entity 实体
-     * @param str    属性字符串内容
-     * @return Object
-     * @deprecated 3.3.2
-     */
-    @Deprecated
-    public static Object getMethodValue(Class<?> cls, Object entity, String str) {
-        Map<String, Field> fieldMaps = getFieldMap(cls);
-        try {
-            Assert.notEmpty(fieldMaps, "Error: NoSuchField in %s for %s.  Cause:", cls.getSimpleName(), str);
-            Method method = cls.getMethod(guessGetterName(fieldMaps.get(str), str));
-            return method.invoke(entity);
-        } catch (NoSuchMethodException e) {
-            throw ExceptionUtils.mpe("Error: NoSuchMethod in %s.  Cause:", e, cls.getSimpleName());
-        } catch (IllegalAccessException e) {
-            throw ExceptionUtils.mpe("Error: Cannot execute a private method. in %s.  Cause:", e, cls.getSimpleName());
-        } catch (InvocationTargetException e) {
-            throw ExceptionUtils.mpe("Error: InvocationTargetException on getMethodValue.  Cause:" + e);
-        }
-    }
-    
+
     /**
      * 获取字段值
      *
@@ -131,36 +91,6 @@ public final class ReflectionKit {
             throw ExceptionUtils.mpe("Error: Cannot read field in %s.  Cause:", e, cls.getSimpleName());
         }
     }
-    
-    /**
-     * 猜测方法名
-     *
-     * @param field 字段
-     * @param str   属性字符串内容
-     * @deprecated 3.3.2
-     */
-    @Deprecated
-    private static String guessGetterName(Field field, final String str) {
-        return StringUtils.guessGetterName(str, field.getType());
-    }
-    
-    /**
-     * <p>
-     * 获取 public get方法的值
-     * </p>
-     *
-     * @param entity 实体
-     * @param str    属性字符串内容
-     * @return Object
-     * @deprecated 3.3.2
-     */
-    @Deprecated
-    public static Object getMethodValue(Object entity, String str) {
-        if (null == entity) {
-            return null;
-        }
-        return getMethodValue(entity.getClass(), entity, str);
-    }
 
     /**
      * <p>
@@ -202,7 +132,7 @@ public final class ReflectionKit {
         List<Field> fieldList = getFieldList(clazz);
         return CollectionUtils.isNotEmpty(fieldList) ? fieldList.stream().collect(Collectors.toMap(Field::getName, field -> field)) : Collections.emptyMap();
     }
-    
+
     /**
      * <p>
      * 获取该类的所有属性列表
@@ -231,14 +161,14 @@ public final class ReflectionKit {
              * 中间表实体重写父类属性 ` private transient Date createTime; `
              */
             return fieldMap.values().stream()
-                /* 过滤静态属性 */
-                .filter(f -> !Modifier.isStatic(f.getModifiers()))
-                /* 过滤 transient关键字修饰的属性 */
-                .filter(f -> !Modifier.isTransient(f.getModifiers()))
-                .collect(Collectors.toList());
+                    /* 过滤静态属性 */
+                    .filter(f -> !Modifier.isStatic(f.getModifiers()))
+                    /* 过滤 transient关键字修饰的属性 */
+                    .filter(f -> !Modifier.isTransient(f.getModifiers()))
+                    .collect(Collectors.toList());
         });
     }
-    
+
     /**
      * <p>
      * 获取该类的所有属性列表
@@ -252,19 +182,19 @@ public final class ReflectionKit {
         if (clazz.getSuperclass() != null) {
             /* 排除重载属性 */
             Map<String, Field> fieldMap = excludeOverrideSuperField(clazz.getDeclaredFields(),
-                /* 处理父类字段 */
-                getFieldList(clazz.getSuperclass()));
+                    /* 处理父类字段 */
+                    getFieldList(clazz.getSuperclass()));
             /*
              * 重写父类属性过滤后处理忽略部分,支持过滤父类属性功能
              * 场景:中间表不需要记录创建时间,忽略父类 createTime 公共属性
              * 中间表实体重写父类属性 ` private transient Date createTime; `
              */
             return fieldMap.values().stream()
-                /* 过滤静态属性 */
-                .filter(f -> !Modifier.isStatic(f.getModifiers()))
-                /* 过滤 transient关键字修饰的属性 */
-                .filter(f -> !Modifier.isTransient(f.getModifiers()))
-                .collect(Collectors.toList());
+                    /* 过滤静态属性 */
+                    .filter(f -> !Modifier.isStatic(f.getModifiers()))
+                    /* 过滤 transient关键字修饰的属性 */
+                    .filter(f -> !Modifier.isTransient(f.getModifiers()))
+                    .collect(Collectors.toList());
         } else {
             return Collections.emptyList();
         }
@@ -289,23 +219,6 @@ public final class ReflectionKit {
                 .forEach(f -> fieldMap.put(f.getName(), f));
         return fieldMap;
     }
-    
-    /**
-     * 获取字段get方法
-     *
-     * @param cls   class
-     * @param field 字段
-     * @return Get方法
-     * @deprecated 3.3.2
-     */
-    @Deprecated
-    public static Method getMethod(Class<?> cls, Field field) {
-        try {
-            return cls.getDeclaredMethod(ReflectionKit.guessGetterName(field, field.getName()));
-        } catch (NoSuchMethodException e) {
-            throw ExceptionUtils.mpe("Error: NoSuchMethod in %s.  Cause:", e, cls.getName());
-        }
-    }
 
     /**
      * 判断是否为基本类型或基本包装类型

+ 10 - 9
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/Sequence.java

@@ -15,16 +15,17 @@
  */
 package com.baomidou.mybatisplus.core.toolkit;
 
+import org.apache.ibatis.logging.Log;
+import org.apache.ibatis.logging.LogFactory;
+
 import java.lang.management.ManagementFactory;
 import java.net.InetAddress;
 import java.net.NetworkInterface;
 import java.util.concurrent.ThreadLocalRandom;
 
-import org.apache.ibatis.logging.Log;
-import org.apache.ibatis.logging.LogFactory;
-
 /**
- * 分布式高效有序ID生产黑科技(sequence)
+ * 分布式高效有序 ID 生产黑科技(sequence)
+ *
  * <p>优化开源项目:https://gitee.com/yu120/sequence</p>
  *
  * @author hubin
@@ -84,9 +85,9 @@ public class Sequence {
      */
     public Sequence(long workerId, long datacenterId) {
         Assert.isFalse(workerId > maxWorkerId || workerId < 0,
-            String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
+                String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
         Assert.isFalse(datacenterId > maxDatacenterId || datacenterId < 0,
-            String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
+                String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
         this.workerId = workerId;
         this.datacenterId = datacenterId;
     }
@@ -174,9 +175,9 @@ public class Sequence {
 
         // 时间戳部分 | 数据中心部分 | 机器标识部分 | 序列号部分
         return ((timestamp - twepoch) << timestampLeftShift)
-            | (datacenterId << datacenterIdShift)
-            | (workerId << workerIdShift)
-            | sequence;
+                | (datacenterId << datacenterIdShift)
+                | (workerId << workerIdShift)
+                | sequence;
     }
 
     protected long tilNextMillis(long lastTimestamp) {

+ 12 - 371
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/StringUtils.java

@@ -18,12 +18,7 @@ package com.baomidou.mybatisplus.core.toolkit;
 import com.baomidou.mybatisplus.core.toolkit.sql.StringEscape;
 import com.baomidou.mybatisplus.core.toolkit.support.BiIntFunction;
 
-import java.nio.charset.StandardCharsets;
-import java.sql.Blob;
-import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -32,7 +27,7 @@ import static java.util.stream.Collectors.joining;
 /**
  * String 工具类
  *
- * @author D.Yang
+ * @author D.Yang, hcl
  * @author hcl
  * @since 2016-08-18
  */
@@ -64,57 +59,16 @@ public final class StringUtils {
      */
     private static final Pattern CAPITAL_MODE = Pattern.compile("^[0-9A-Z/_]+$");
 
-    private StringUtils() {
-    }
-
     /**
-     * 安全的进行字符串 format
+     * 判断字符串中是否全是空白字符
      *
-     * @param target 目标字符串
-     * @param params format 参数
-     * @return format 后的
+     * @param cs 需要判断的字符串
+     * @return 如果字符串序列是 null 或者全是空白,返回 true
      */
-    public static String format(String target, Object... params) {
-        return String.format(target, params);
-    }
-
-
-    /**
-     * Blob 转为 String 格式
-     *
-     * @param blob Blob 对象
-     * @return 转换后的
-     */
-    public static String blob2String(Blob blob) {
-        if (null != blob) {
-            try {
-                byte[] returnValue = blob.getBytes(1, (int) blob.length());
-                return new String(returnValue, StandardCharsets.UTF_8);
-            } catch (Exception e) {
-                throw ExceptionUtils.mpe("Blob Convert To String Error!");
-            }
-        }
-        return null;
-    }
-
-    /**
-     * 判断字符串是否为空
-     *
-     * @param cs 需要判断字符串
-     * @return 判断结果
-     */
-    @Deprecated
-    public static boolean isEmpty(CharSequence cs) {
-        return isBlank(cs);
-    }
-
-    public static boolean isBlank(final CharSequence cs) {
-        if (cs == null) {
-            return true;
-        }
-        int l = cs.length();
-        if (l > 0) {
-            for (int i = 0; i < l; i++) {
+    public static boolean isBlank(CharSequence cs) {
+        if (cs != null) {
+            int length = cs.length();
+            for (int i = 0; i < length; i++) {
                 if (!Character.isWhitespace(cs.charAt(i))) {
                     return false;
                 }
@@ -124,47 +78,12 @@ public final class StringUtils {
     }
 
     /**
-     * 判断字符串是否不为空
-     *
-     * @param cs 需要判断字符串
-     * @return 判断结果
+     * @see #isBlank(CharSequence)
      */
-    @Deprecated
-    public static boolean isNotEmpty(final CharSequence cs) {
-        return !isEmpty(cs);
-    }
-
-    public static boolean isNotBlank(final CharSequence cs) {
+    public static boolean isNotBlank(CharSequence cs) {
         return !isBlank(cs);
     }
 
-    /**
-     * 猜测方法属性对应的 Getter 名称,具体规则请参考 JavaBeans 规范
-     *
-     * @param name 属性名称
-     * @param type 属性类型
-     * @return 返回猜测的名称
-     * @deprecated 3.3.2
-     */
-    @Deprecated
-    public static String guessGetterName(String name, Class<?> type) {
-        return boolean.class == type ? name.startsWith("is") ? name : "is" + upperFirst(name) : "get" + upperFirst(name);
-    }
-
-    /**
-     * 大写第一个字母
-     *
-     * @param src 源字符串
-     * @return 返回第一个大写后的字符串
-     */
-    public static String upperFirst(String src) {
-        if (Character.isLowerCase(src.charAt(0))) {
-            return 1 == src.length() ? src.toUpperCase() : Character.toUpperCase(src.charAt(0)) + src.substring(1);
-        }
-        return src;
-    }
-
-
     /**
      * 判断字符串是不是驼峰命名
      *
@@ -175,13 +94,9 @@ public final class StringUtils {
      * @return 结果
      */
     public static boolean isCamel(String str) {
-        if (str.contains(StringPool.UNDERSCORE)) {
-            return false;
-        }
-        return Character.isLowerCase(str.charAt(0));
+        return Character.isLowerCase(str.charAt(0)) && !str.contains(StringPool.UNDERSCORE);
     }
 
-
     /**
      * 判断字符串是否符合数据库字段的命名
      *
@@ -227,23 +142,6 @@ public final class StringUtils {
         return sb.toString();
     }
 
-    /**
-     * 解析 getMethodName -> propertyName
-     *
-     * @param getMethodName 需要解析的
-     * @return 返回解析后的字段名称
-     */
-    public static String resolveFieldName(String getMethodName) {
-        if (getMethodName.startsWith("get")) {
-            getMethodName = getMethodName.substring(3);
-        } else if (getMethodName.startsWith(IS)) {
-            getMethodName = getMethodName.substring(2);
-        }
-        // 小写第一个字母
-        return StringUtils.firstToLowerCase(getMethodName);
-    }
-
-
     /**
      * 字符串下划线转驼峰格式
      *
@@ -283,16 +181,6 @@ public final class StringUtils {
         return param.substring(0, 1).toLowerCase() + param.substring(1);
     }
 
-    /**
-     * 判断字符串是否为纯大写字母
-     *
-     * @param str 要匹配的字符串
-     * @return
-     */
-    public static boolean isUpperCase(String str) {
-        return matches("^[A-Z]+$", str);
-    }
-
     /**
      * 正则表达式匹配
      *
@@ -357,9 +245,6 @@ public final class StringUtils {
 
     /**
      * 获取SQL PARAMS字符串
-     *
-     * @param obj
-     * @return
      */
     public static String sqlParam(Object obj) {
         String repStr;
@@ -417,16 +302,6 @@ public final class StringUtils {
         return concatStr + Character.toTitleCase(firstChar) + str.substring(1);
     }
 
-    /**
-     * 字符串第一个字母大写
-     *
-     * @param str 被处理的字符串
-     * @return 首字母大写后的字符串
-     */
-    public static String capitalize(final String str) {
-        return concatCapitalize(null, str);
-    }
-
     /**
      * 判断对象是否不为空
      *
@@ -514,36 +389,6 @@ public final class StringUtils {
         return endsWith(str, suffix, false);
     }
 
-
-    /**
-     * 判断是否以某个字符串结尾(不区分大小写)
-     * Case insensitive check if a String ends with a specified suffix.
-     * <p>
-     * <code>null</code>s are handled without exceptions. Two <code>null</code>
-     * references are considered to be equal. The comparison is case
-     * insensitive.
-     * </p>
-     * <p>
-     * <pre>
-     * StringUtils.endsWithIgnoreCase(null, null)      = true
-     * StringUtils.endsWithIgnoreCase(null, "abcdef")  = false
-     * StringUtils.endsWithIgnoreCase("def", null)     = false
-     * StringUtils.endsWithIgnoreCase("def", "abcdef") = true
-     * StringUtils.endsWithIgnoreCase("def", "ABCDEF") = false
-     * </pre>
-     * </p>
-     *
-     * @param str    the String to check, may be null
-     * @param suffix the suffix to find, may be null
-     * @return <code>true</code> if the String ends with the suffix, case
-     * insensitive, or both <code>null</code>
-     * @see String#endsWith(String)
-     * @since 2.4
-     */
-    public static boolean endsWithIgnoreCase(String str, String suffix) {
-        return endsWith(str, suffix, true);
-    }
-
     /**
      * Check if a String ends with a specified suffix (optionally case
      * insensitive).
@@ -567,140 +412,6 @@ public final class StringUtils {
         return str.regionMatches(ignoreCase, strOffset, suffix, 0, suffix.length());
     }
 
-    /**
-     * Splits the provided text into an array, separators specified. This is an
-     * alternative to using StringTokenizer.
-     * <p>
-     * The separator is not included in the returned String array. Adjacent
-     * separators are treated as one separator. For more control over the split
-     * use the StrTokenizer class.
-     * </p>
-     * <p>
-     * A {@code null} input String returns {@code null}. A {@code null}
-     * separatorChars splits on whitespace.
-     * </p>
-     * <p>
-     * <pre>
-     * StringUtils.split(null, *)         = null
-     * StringUtils.split("", *)           = []
-     * StringUtils.split("abc def", null) = ["abc", "def"]
-     * StringUtils.split("abc def", " ")  = ["abc", "def"]
-     * StringUtils.split("abc  def", " ") = ["abc", "def"]
-     * StringUtils.split("ab:cd:ef", ":") = ["ab", "cd", "ef"]
-     * </pre>
-     * </p>
-     *
-     * @param str            the String to parse, may be null
-     * @param separatorChars the characters used as the delimiters, {@code null} splits on
-     *                       whitespace
-     * @return an array of parsed Strings, {@code null} if null String input
-     */
-    public static String[] split(final String str, final String separatorChars) {
-        List<String> strings = splitWorker(str, separatorChars, -1, false);
-        return strings.toArray(new String[0]);
-    }
-
-    /**
-     * Performs the logic for the {@code split} and
-     * {@code splitPreserveAllTokens} methods that return a maximum array
-     * length.
-     *
-     * @param str               the String to parse, may be {@code null}
-     * @param separatorChars    the separate character
-     * @param max               the maximum number of elements to include in the array. A zero
-     *                          or negative value implies no limit.
-     * @param preserveAllTokens if {@code true}, adjacent separators are treated as empty
-     *                          token separators; if {@code false}, adjacent separators are
-     *                          treated as one separator.
-     * @return an array of parsed Strings, {@code null} if null String input
-     */
-    public static List<String> splitWorker(final String str, final String separatorChars, final int max,
-                                           final boolean preserveAllTokens) {
-        // Performance tuned for 2.0 (JDK1.4)
-        // Direct code is quicker than StringTokenizer.
-        // Also, StringTokenizer uses isSpace() not isWhitespace()
-
-        if (str == null) {
-            return null;
-        }
-        final int len = str.length();
-        if (len == 0) {
-            return Collections.emptyList();
-        }
-        final List<String> list = new ArrayList<>();
-        int sizePlus1 = 1;
-        int i = 0, start = 0;
-        boolean match = false;
-        boolean lastMatch = false;
-        if (separatorChars == null) {
-            // Null separator means use whitespace
-            while (i < len) {
-                if (Character.isWhitespace(str.charAt(i))) {
-                    if (match || preserveAllTokens) {
-                        lastMatch = true;
-                        if (sizePlus1++ == max) {
-                            i = len;
-                            lastMatch = false;
-                        }
-                        list.add(str.substring(start, i));
-                        match = false;
-                    }
-                    start = ++i;
-                    continue;
-                }
-                lastMatch = false;
-                match = true;
-                i++;
-            }
-        } else if (separatorChars.length() == 1) {
-            // Optimise 1 character case
-            final char sep = separatorChars.charAt(0);
-            while (i < len) {
-                if (str.charAt(i) == sep) {
-                    if (match || preserveAllTokens) {
-                        lastMatch = true;
-                        if (sizePlus1++ == max) {
-                            i = len;
-                            lastMatch = false;
-                        }
-                        list.add(str.substring(start, i));
-                        match = false;
-                    }
-                    start = ++i;
-                    continue;
-                }
-                lastMatch = false;
-                match = true;
-                i++;
-            }
-        } else {
-            // standard case
-            while (i < len) {
-                if (separatorChars.indexOf(str.charAt(i)) >= 0) {
-                    if (match || preserveAllTokens) {
-                        lastMatch = true;
-                        if (sizePlus1++ == max) {
-                            i = len;
-                            lastMatch = false;
-                        }
-                        list.add(str.substring(start, i));
-                        match = false;
-                    }
-                    start = ++i;
-                    continue;
-                }
-                lastMatch = false;
-                match = true;
-                i++;
-            }
-        }
-        if (match || preserveAllTokens && lastMatch) {
-            list.add(str.substring(start, i));
-        }
-        return list;
-    }
-
-
     /**
      * 是否为CharSequence类型
      *
@@ -711,49 +422,6 @@ public final class StringUtils {
         return clazz != null && CharSequence.class.isAssignableFrom(clazz);
     }
 
-    /**
-     * 去除boolean类型is开头的字符串
-     *
-     * @param propertyName 字段名
-     * @param propertyType 字段类型
-     */
-    public static String removeIsPrefixIfBoolean(String propertyName, Class<?> propertyType) {
-        if (ClassUtils.isBoolean(propertyType) && propertyName.startsWith(IS)) {
-            String property = propertyName.replaceFirst(IS, EMPTY);
-            if (isBlank(property)) {
-                return propertyName;
-            } else {
-                String firstCharToLowerStr = firstCharToLower(property);
-                return property.equals(firstCharToLowerStr) ? propertyName : firstCharToLowerStr;
-            }
-        }
-        return propertyName;
-    }
-
-    /**
-     * 是否为Boolean类型(包含普通类型)
-     *
-     * @param propertyCls ignore
-     * @return ignore
-     * @deprecated 3.3.0 {@link ClassUtils#isBoolean(Class)}
-     */
-    @Deprecated
-    public static boolean isBoolean(Class<?> propertyCls) {
-        return propertyCls != null && (boolean.class.isAssignableFrom(propertyCls) || Boolean.class.isAssignableFrom(propertyCls));
-    }
-
-    /**
-     * 第一个首字母小写,之后字符大小写的不变
-     * <p>StringUtils.firstCharToLower( "UserService" )     = userService</p>
-     * <p>StringUtils.firstCharToLower( "UserServiceImpl" ) = userServiceImpl</p>
-     *
-     * @param rawString 需要处理的字符串
-     * @return ignore
-     */
-    public static String firstCharToLower(String rawString) {
-        return prefixToLower(rawString, 1);
-    }
-
     /**
      * 前n个首字母小写,之后字符大小写的不变
      *
@@ -793,21 +461,16 @@ public final class StringUtils {
     }
 
     private static String wordsAndHyphenAndCamelToConstantCase(String input) {
-        boolean betweenUpperCases = false;
-        boolean containsLowerCase = containsLowerCase(input);
-
         StringBuilder buf = new StringBuilder();
         char previousChar = ' ';
         char[] chars = input.toCharArray();
         for (char c : chars) {
-            boolean isUpperCaseAndPreviousIsUpperCase = (Character.isUpperCase(previousChar)) && (Character.isUpperCase(c));
             boolean isUpperCaseAndPreviousIsLowerCase = (Character.isLowerCase(previousChar)) && (Character.isUpperCase(c));
 
             boolean previousIsWhitespace = Character.isWhitespace(previousChar);
             boolean lastOneIsNotUnderscore = (buf.length() > 0) && (buf.charAt(buf.length() - 1) != '_');
             boolean isNotUnderscore = c != '_';
-            if (lastOneIsNotUnderscore && (isUpperCaseAndPreviousIsLowerCase || previousIsWhitespace
-                || (betweenUpperCases && containsLowerCase && isUpperCaseAndPreviousIsUpperCase))) {
+            if (lastOneIsNotUnderscore && (isUpperCaseAndPreviousIsLowerCase || previousIsWhitespace)) {
                 buf.append(StringPool.UNDERSCORE);
             } else if ((Character.isDigit(previousChar) && Character.isLetter(c))) {
                 buf.append('_');
@@ -825,15 +488,6 @@ public final class StringUtils {
         return buf.toString();
     }
 
-    public static boolean containsLowerCase(String s) {
-        for (char c : s.toCharArray()) {
-            if (Character.isLowerCase(c)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
     private static boolean shouldReplace(char c) {
         return (c == '.') || (c == '_') || (c == '-');
     }
@@ -862,17 +516,4 @@ public final class StringUtils {
         return buf.toString();
     }
 
-    /**
-     * 从字符串中移除一个单词及随后的一个逗号
-     *
-     * @param s 原字符串
-     * @param p 移除的单词
-     * @return ignore
-     * @deprecated 3.1.1
-     */
-    @Deprecated
-    public static String removeWordWithComma(String s, String p) {
-        String match = "\\s*" + p + "\\s*,{0,1}";
-        return s.replaceAll(match, "");
-    }
 }

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/TableNameParser.java

@@ -23,6 +23,7 @@ import java.util.regex.Pattern;
  * SQL 表名解析
  * <p>
  * https://github.com/mnadeem/sql-table-name-parser
+ * <p>
  * Ultra light, Ultra fast parser to extract table name out SQLs, supports oracle dialect SQLs as well.
  * USE: new TableNameParser(sql).tables()
  *
@@ -243,7 +244,6 @@ public final class TableNameParser {
      * @return table names extracted out of sql
      * @see #accept(TableNameVisitor)
      */
-    @Deprecated
     public Collection<String> tables() {
         Map<String, String> tableMap = new HashMap<>();
         accept(token -> {

+ 18 - 31
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/toolkit/ReflectionKitTest.java

@@ -63,47 +63,47 @@ class ReflectionKitTest {
         private String sex;
 
     }
-    
+
     @Data
     private static class EntityByLombok {
-        
+
         private Long id;
-        
+
         private String pId;
-        
+
         private String parentId;
-        
+
     }
-    
+
     private static class Entity {
-        
+
         private Long id;
-        
+
         private String pId;
-        
+
         private String parentId;
-    
-    
+
+
         public Long getId() {
             return id;
         }
-    
+
         public void setId(Long id) {
             this.id = id;
         }
-    
+
         public String getpId() {
             return pId;
         }
-    
+
         public void setpId(String pId) {
             this.pId = pId;
         }
-    
+
         public String getParentId() {
             return parentId;
         }
-    
+
         public void setParentId(String parentId) {
             this.parentId = parentId;
         }
@@ -124,19 +124,6 @@ class ReflectionKitTest {
         Assertions.assertEquals(fieldMap.get("name"), A.class.getDeclaredField("name"));
     }
 
-    @Test
-    void testGetMethodCapitalize() throws NoSuchFieldException {
-        Field field = C.class.getDeclaredField("sex");
-        String getMethod = ReflectionKit.getMethodCapitalize(field, "sex");
-        Assertions.assertEquals("getSex", getMethod);
-        field = A.class.getDeclaredField("testWrap");
-        getMethod = ReflectionKit.getMethodCapitalize(field, "testWrap");
-        Assertions.assertEquals("getTestWrap", getMethod);
-        field = A.class.getDeclaredField("testSimple");
-        getMethod = ReflectionKit.getMethodCapitalize(field, "testSimple");
-        Assertions.assertEquals("isTestSimple", getMethod);
-    }
-    
     @Test
     void testGetFieldValue() {
         C c = new C();
@@ -145,13 +132,13 @@ class ReflectionKitTest {
         c.setAge(18);
         Assertions.assertEquals(c.getSex(), ReflectionKit.getFieldValue(c, "sex"));
         Assertions.assertEquals(c.getAge(), ReflectionKit.getFieldValue(c, "age"));
-        
+
         EntityByLombok entityByLombok = new EntityByLombok();
         entityByLombok.setPId("6666");
         entityByLombok.setParentId("123");
         Assertions.assertEquals(entityByLombok.getPId(), ReflectionKit.getFieldValue(entityByLombok, "pId"));
         Assertions.assertEquals(entityByLombok.getParentId(), ReflectionKit.getFieldValue(entityByLombok, "parentId"));
-        
+
         Entity entity = new Entity();
         entity.setpId("6666");
         entity.setParentId("123");

+ 1 - 10
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/toolkit/StringUtilsTest.java

@@ -33,20 +33,11 @@ class StringUtilsTest {
     }
 
     @Test
-    void isCapitalModeTest(){
+    void isCapitalModeTest() {
         Assertions.assertFalse(StringUtils.isCapitalMode("test"));
         Assertions.assertFalse(StringUtils.isCapitalMode("Test"));
         Assertions.assertFalse(StringUtils.isCapitalMode("teSt"));
         Assertions.assertTrue(StringUtils.isCapitalMode("TEST"));
     }
 
-    @Test
-    void testGuessGetterName(){
-        Assertions.assertEquals("getSex",StringUtils.guessGetterName("sex",String.class));
-        Assertions.assertEquals("getIsSex",StringUtils.guessGetterName("isSex",String.class));
-        Assertions.assertEquals("getTestWrap",StringUtils.guessGetterName("testWrap",Boolean.class));
-        Assertions.assertEquals("getIsTestWrap",StringUtils.guessGetterName("isTestWrap",Boolean.class));
-        Assertions.assertEquals("isTestSimple",StringUtils.guessGetterName("testSimple",boolean.class));
-        Assertions.assertEquals("isTestSimple",StringUtils.guessGetterName("isTestSimple",boolean.class));
-    }
 }