Ver código fonte

[chg] VerifyProcessor优化

wcz 5 anos atrás
pai
commit
dfc9c6b5cd

+ 0 - 8
lift-common/src/main/java/cn.com.ty.lift.common/sql/IllegalRule.java

@@ -437,14 +437,6 @@ public class IllegalRule {
         indexInfo.setColumnName(columnName);
         indexInfos.add(indexInfo);
     }
-
-    /**
-     * check whether the sql is verifiable.
-     */
-    public boolean verifiable() {
-        return !verifyInfos.isEmpty();
-    }
-
     /**
      * verify the where exp & index info parse from the sql. return finally.
      */

+ 1 - 14
lift-common/src/main/java/cn.com.ty.lift.common/sql/SqlIllegalInterceptor.java

@@ -115,12 +115,6 @@ public class SqlIllegalInterceptor implements Interceptor {
         //the illegal rule.
         IllegalRule illegalRule = new IllegalRule(con.getMetaData(), con.getCatalog(), con.getSchema(), originalSql);
 
-        // if any to verify, just return.
-        if (!illegalRule.verifiable()) {
-            illegalRule.error();
-            return invocation.proceed();
-        }
-
         // if the sql is legal, cache the sql encode.
         if (illegalRule.verify()) {
             legalSqlCacheSet.add(sqlEncode);
@@ -310,7 +304,7 @@ public class SqlIllegalInterceptor implements Interceptor {
             String fullyQualifiedTable = indexInfo.fullyQualifiedTable();
             // if new create index on the column. must to reload index,
             if (indexInfo.fullyTable() && tableCacheSet.contains(fullyQualifiedTable)) {
-                addMessage("Index not use on %s. Example sql: CREATE [UNIQUE|CLUSTERED] INDEX idx_%s ON %s(%s)", fullyQualifiedColumn, indexInfo.columnName, indexInfo.tableName, indexInfo.columnName);
+                addMessage("Index not use on %s. Example sql: CREATE [UNIQUE|FULLTEXT|SPATIAL] INDEX idx_%s ON %s(%s)", fullyQualifiedColumn, indexInfo.columnName, indexInfo.tableName, indexInfo.columnName);
                 return 0;
             }
             //get index info from the connection.
@@ -578,13 +572,6 @@ public class SqlIllegalInterceptor implements Interceptor {
             indexInfos.add(indexInfo);
         }
 
-        /**
-         * check whether the sql is verifiable.
-         */
-        private boolean verifiable() {
-            return !verifyInfos.isEmpty();
-        }
-
         /**
          * verify the where exp & index info parse from the sql. return finally.
          */

+ 335 - 0
lift-common/src/main/java/cn.com.ty.lift.common/utils/CollectionHelper.java

@@ -0,0 +1,335 @@
+/*
+ * Hibernate Validator, declare and validate application constraints
+ *
+ * License: Apache License, Version 2.0
+ * See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
+ */
+package cn.com.ty.lift.common.utils;
+
+import java.util.*;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Provides some methods for simplified collection instantiation.
+ *
+ * @author Gunnar Morling
+ * @author Kevin Pollet &lt;kevin.pollet@serli.com&gt; (C) 2011 SERLI
+ * @author Hardy Ferentschik
+ * @author Guillaume Smet
+ */
+public final class CollectionHelper {
+
+    private CollectionHelper() {
+    }
+
+    public static <K, V> HashMap<K, V> newHashMap() {
+        return new HashMap<K, V>();
+    }
+
+    public static <K, V> HashMap<K, V> newHashMap(int size) {
+        return new HashMap<K, V>(getInitialCapacityFromExpectedSize(size));
+    }
+
+    public static <K, V> HashMap<K, V> newHashMap(Map<K, V> map) {
+        return new HashMap<K, V>(map);
+    }
+
+    public static <K, V> ConcurrentHashMap<K, V> newConcurrentHashMap() {
+        return new ConcurrentHashMap<K, V>();
+    }
+
+    public static <T> HashSet<T> newHashSet() {
+        return new HashSet<T>();
+    }
+
+    public static <T> HashSet<T> newHashSet(int size) {
+        return new HashSet<T>(getInitialCapacityFromExpectedSize(size));
+    }
+
+    public static <T> HashSet<T> newHashSet(Collection<? extends T> c) {
+        return new HashSet<T>(c);
+    }
+
+    public static <T> HashSet<T> newHashSet(Iterable<? extends T> iterable) {
+        HashSet<T> set = newHashSet();
+        for (T t : iterable) {
+            set.add(t);
+        }
+        return set;
+    }
+
+    public static <T> ArrayList<T> newArrayList() {
+        return new ArrayList<T>();
+    }
+
+    public static <T> ArrayList<T> newArrayList(int size) {
+        return new ArrayList<T>(size);
+    }
+
+    @SafeVarargs
+    public static <T> ArrayList<T> newArrayList(Iterable<T>... iterables) {
+        ArrayList<T> resultList = newArrayList();
+        for (Iterable<T> oneIterable : iterables) {
+            for (T oneElement : oneIterable) {
+                resultList.add(oneElement);
+            }
+        }
+        return resultList;
+    }
+
+    @SafeVarargs
+    public static <T> Set<T> asSet(T... ts) {
+        return new HashSet<>(Arrays.asList(ts));
+    }
+
+    public static <T> List<T> toImmutableList(List<? extends T> list) {
+        switch (list.size()) {
+            case 0:
+                return Collections.emptyList();
+            case 1:
+                return Collections.singletonList(list.get(0));
+            default:
+                return Collections.unmodifiableList(list);
+        }
+    }
+
+    public static <T> Set<T> toImmutableSet(Set<? extends T> set) {
+        switch (set.size()) {
+            case 0:
+                return Collections.emptySet();
+            case 1:
+                return Collections.singleton(set.iterator().next());
+            default:
+                return Collections.unmodifiableSet(set);
+        }
+    }
+
+    public static <K, V> Map<K, V> toImmutableMap(Map<K, V> map) {
+        switch (map.size()) {
+            case 0:
+                return Collections.emptyMap();
+            case 1:
+                Entry<K, V> entry = map.entrySet().iterator().next();
+                return Collections.singletonMap(entry.getKey(), entry.getValue());
+            default:
+                return Collections.unmodifiableMap(map);
+        }
+    }
+
+    /**
+     * As the default loadFactor is of 0.75, we need to calculate the initial capacity from the expected size to avoid
+     * resizing the collection when we populate the collection with all the initial elements. We use a calculation
+     * similar to what is done in {@link HashMap#putAll(Map)}.
+     *
+     * @param expectedSize the expected size of the collection
+     * @return the initial capacity of the collection
+     */
+    private static int getInitialCapacityFromExpectedSize(int expectedSize) {
+        if (expectedSize < 3) {
+            return expectedSize + 1;
+        }
+        return (int) ((float) expectedSize / 0.75f + 1.0f);
+    }
+
+    /**
+     * Builds an {@link Iterator} for a given array. It is (un)necessarily ugly because we have to deal with array of primitives.
+     *
+     * @param object a given array
+     * @return an {@code Iterator} iterating over the array
+     */
+    @SuppressWarnings({"unchecked", "rawtypes"}) // Reflection is used to ensure the correct types are used
+    public static Iterator<?> iteratorFromArray(Object object) {
+        return new ArrayIterator(accessorFromArray(object), object);
+    }
+
+    /**
+     * Builds an {@link Iterable} for a given array. It is (un)necessarily ugly because we have to deal with array of primitives.
+     *
+     * @param object a given array
+     * @return an {@code Iterable} providing iterators over the array
+     */
+    @SuppressWarnings({"unchecked", "rawtypes"}) // Reflection is used to ensure the correct types are used
+    public static Iterable<?> iterableFromArray(Object object) {
+        return new ArrayIterable(accessorFromArray(object), object);
+    }
+
+    private static ArrayAccessor<?, ?> accessorFromArray(Object object) {
+        ArrayAccessor<?, ?> accessor;
+        if (Object.class.isAssignableFrom(object.getClass().getComponentType())) {
+            accessor = ArrayAccessor.OBJECT;
+        } else if (object.getClass() == boolean[].class) {
+            accessor = ArrayAccessor.BOOLEAN;
+        } else if (object.getClass() == int[].class) {
+            accessor = ArrayAccessor.INT;
+        } else if (object.getClass() == long[].class) {
+            accessor = ArrayAccessor.LONG;
+        } else if (object.getClass() == double[].class) {
+            accessor = ArrayAccessor.DOUBLE;
+        } else if (object.getClass() == float[].class) {
+            accessor = ArrayAccessor.FLOAT;
+        } else if (object.getClass() == byte[].class) {
+            accessor = ArrayAccessor.BYTE;
+        } else if (object.getClass() == short[].class) {
+            accessor = ArrayAccessor.SHORT;
+        } else if (object.getClass() == char[].class) {
+            accessor = ArrayAccessor.CHAR;
+        } else {
+            throw new IllegalArgumentException("Provided object " + object + " is not a supported array type");
+        }
+        return accessor;
+    }
+
+    private static class ArrayIterable<A, T> implements Iterable<T> {
+        private final ArrayAccessor<A, T> accessor;
+        private final A                   values;
+
+        public ArrayIterable(ArrayAccessor<A, T> accessor, A values) {
+            this.accessor = accessor;
+            this.values = values;
+        }
+
+        @Override
+        public final Iterator<T> iterator() {
+            return new ArrayIterator<>(accessor, values);
+        }
+    }
+
+    private static class ArrayIterator<A, T> implements Iterator<T> {
+        private final ArrayAccessor<A, T> accessor;
+        private final A                   values;
+        private       int                 current = 0;
+
+        public ArrayIterator(ArrayAccessor<A, T> accessor, A values) {
+            this.accessor = accessor;
+            this.values = values;
+        }
+
+        @Override
+        public boolean hasNext() {
+            return current < accessor.size(values);
+        }
+
+        @Override
+        public T next() {
+            T result = accessor.get(values, current);
+            current++;
+            return result;
+        }
+    }
+
+    private interface ArrayAccessor<A, T> {
+
+        int size(A array);
+
+        T get(A array, int index);
+
+        ArrayAccessor<Object[], Object> OBJECT = new ArrayAccessor<Object[], Object>() {
+            @Override
+            public int size(Object[] array) {
+                return array.length;
+            }
+
+            @Override
+            public Object get(Object[] array, int index) {
+                return array[index];
+            }
+        };
+
+        ArrayAccessor<boolean[], Boolean> BOOLEAN = new ArrayAccessor<boolean[], Boolean>() {
+            @Override
+            public int size(boolean[] array) {
+                return array.length;
+            }
+
+            @Override
+            public Boolean get(boolean[] array, int index) {
+                return array[index];
+            }
+        };
+
+        ArrayAccessor<int[], Integer> INT = new ArrayAccessor<int[], Integer>() {
+            @Override
+            public int size(int[] array) {
+                return array.length;
+            }
+
+            @Override
+            public Integer get(int[] array, int index) {
+                return array[index];
+            }
+        };
+
+        ArrayAccessor<long[], Long> LONG = new ArrayAccessor<long[], Long>() {
+            @Override
+            public int size(long[] array) {
+                return array.length;
+            }
+
+            @Override
+            public Long get(long[] array, int index) {
+                return array[index];
+            }
+        };
+
+        ArrayAccessor<double[], Double> DOUBLE = new ArrayAccessor<double[], Double>() {
+            @Override
+            public int size(double[] array) {
+                return array.length;
+            }
+
+            @Override
+            public Double get(double[] array, int index) {
+                return array[index];
+            }
+        };
+
+        ArrayAccessor<float[], Float> FLOAT = new ArrayAccessor<float[], Float>() {
+            @Override
+            public int size(float[] array) {
+                return array.length;
+            }
+
+            @Override
+            public Float get(float[] array, int index) {
+                return array[index];
+            }
+        };
+
+        ArrayAccessor<byte[], Byte> BYTE = new ArrayAccessor<byte[], Byte>() {
+            @Override
+            public int size(byte[] array) {
+                return array.length;
+            }
+
+            @Override
+            public Byte get(byte[] array, int index) {
+                return array[index];
+            }
+        };
+
+        ArrayAccessor<short[], Short> SHORT = new ArrayAccessor<short[], Short>() {
+            @Override
+            public int size(short[] array) {
+                return array.length;
+            }
+
+            @Override
+            public Short get(short[] array, int index) {
+                return array[index];
+            }
+        };
+
+        ArrayAccessor<char[], Character> CHAR = new ArrayAccessor<char[], Character>() {
+            @Override
+            public int size(char[] array) {
+                return array.length;
+            }
+
+            @Override
+            public Character get(char[] array, int index) {
+                return array[index];
+            }
+        };
+    }
+}

+ 29 - 48
lift-common/src/main/java/cn.com.ty.lift.common/verify/Verifies.java

@@ -78,21 +78,11 @@ public class Verifies {
     private static final short SHORT_ZERO = (short) 0;
 
     private static final byte BYTE_ZERO = (byte) 0;
+
+    private static final Clock SYSTEM_DEFAULT_CLOCK = Clock.offset(Clock.systemDefaultZone(), Duration.ZERO.abs().negated());
     
     private Verifies(){}
 
-    private static Clock getClock() {
-        return Clock.systemDefaultZone();
-    }
-
-    private static Duration getDuration() {
-        return Duration.ZERO.abs();
-    }
-
-    private static Clock getClock(Duration offset) {
-        return Clock.offset(getClock(), offset.negated());
-    }
-
     public static boolean isNull(Object value) {
         return null == value;
     }
@@ -836,38 +826,37 @@ public class Verifies {
 
     //java.time.temporal.TemporalAccessor
     public static int dateComparator(TemporalAccessor value) {
-        Clock clock = getClock(getDuration());
         int compare;
         if (value instanceof Instant) {
-            compare = ((Instant) value).compareTo(Instant.now(clock));
+            compare = ((Instant) value).compareTo(Instant.now(SYSTEM_DEFAULT_CLOCK));
         } else if (value instanceof LocalDateTime) {
-            compare = ((LocalDateTime) value).compareTo(LocalDateTime.now(clock));
+            compare = ((LocalDateTime) value).compareTo(LocalDateTime.now(SYSTEM_DEFAULT_CLOCK));
         } else if (value instanceof LocalDate) {
-            compare = ((LocalDate) value).compareTo(LocalDate.now(clock));
+            compare = ((LocalDate) value).compareTo(LocalDate.now(SYSTEM_DEFAULT_CLOCK));
         } else if (value instanceof LocalTime) {
-            compare = ((LocalTime) value).compareTo(LocalTime.now(clock));
+            compare = ((LocalTime) value).compareTo(LocalTime.now(SYSTEM_DEFAULT_CLOCK));
         } else if (value instanceof MonthDay) {
-            compare = ((MonthDay) value).compareTo(MonthDay.now(clock));
+            compare = ((MonthDay) value).compareTo(MonthDay.now(SYSTEM_DEFAULT_CLOCK));
         } else if (value instanceof HijrahDate) {
-            compare = ((HijrahDate) value).compareTo(HijrahDate.now(clock));
+            compare = ((HijrahDate) value).compareTo(HijrahDate.now(SYSTEM_DEFAULT_CLOCK));
         } else if (value instanceof JapaneseDate) {
-            compare = ((JapaneseDate) value).compareTo(JapaneseDate.now(clock));
+            compare = ((JapaneseDate) value).compareTo(JapaneseDate.now(SYSTEM_DEFAULT_CLOCK));
         } else if (value instanceof MinguoDate) {
-            compare = ((MinguoDate) value).compareTo(MinguoDate.now(clock));
+            compare = ((MinguoDate) value).compareTo(MinguoDate.now(SYSTEM_DEFAULT_CLOCK));
         } else if (value instanceof OffsetDateTime) {
-            compare = ((OffsetDateTime) value).compareTo(OffsetDateTime.now(clock));
+            compare = ((OffsetDateTime) value).compareTo(OffsetDateTime.now(SYSTEM_DEFAULT_CLOCK));
         } else if (value instanceof OffsetTime) {
-            compare = ((OffsetTime) value).compareTo(OffsetTime.now(clock));
+            compare = ((OffsetTime) value).compareTo(OffsetTime.now(SYSTEM_DEFAULT_CLOCK));
         } else if (value instanceof ThaiBuddhistDate) {
-            compare = ((ThaiBuddhistDate) value).compareTo(ThaiBuddhistDate.now(clock));
+            compare = ((ThaiBuddhistDate) value).compareTo(ThaiBuddhistDate.now(SYSTEM_DEFAULT_CLOCK));
         } else if (value instanceof Year) {
-            compare = ((Year) value).compareTo(Year.now(clock));
+            compare = ((Year) value).compareTo(Year.now(SYSTEM_DEFAULT_CLOCK));
         } else if (value instanceof YearMonth) {
-            compare = ((YearMonth) value).compareTo(YearMonth.now(clock));
+            compare = ((YearMonth) value).compareTo(YearMonth.now(SYSTEM_DEFAULT_CLOCK));
         } else if (value instanceof ZonedDateTime) {
-            compare = ((ZonedDateTime) value).compareTo(ZonedDateTime.now(clock));
+            compare = ((ZonedDateTime) value).compareTo(ZonedDateTime.now(SYSTEM_DEFAULT_CLOCK));
         } else {
-            compare = -2;
+            compare = Integer.MAX_VALUE;
         }
         return compare;
     }
@@ -876,23 +865,21 @@ public class Verifies {
     public static void future(TemporalAccessor value, String message) {
         VerifyUtils.isNull(value, message);
         int compare = dateComparator(value);
-        IllegalArg.isTrue(-2 == compare, value.getClass().toString() + " is not a supported date class temporarily.");
+        IllegalArg.isTrue(Integer.MAX_VALUE == compare, value.getClass().toString() + " is not a supported TemporalAccessor class temporarily.");
         VerifyUtils.notTrue(gt0(compare), message);
     }
 
     //Future : java.util.Date,
     public static void future(Date value, String message) {
         VerifyUtils.isNull(value, message);
-        Clock clock = getClock(getDuration());
-        int compare = value.toInstant().compareTo(Instant.now(clock));
+        int compare = value.toInstant().compareTo(Instant.now(SYSTEM_DEFAULT_CLOCK));
         VerifyUtils.notTrue(gt0(compare), message);
     }
 
     //Future : java.util.Calendar
     public static void future(Calendar value, String message) {
         VerifyUtils.isNull(value, message);
-        Clock clock = getClock(getDuration());
-        int compare = value.toInstant().compareTo(Instant.now(clock));
+        int compare = value.toInstant().compareTo(Instant.now(SYSTEM_DEFAULT_CLOCK));
         VerifyUtils.notTrue(gte0(compare), message);
     }
 
@@ -900,23 +887,21 @@ public class Verifies {
     public static void futureOrPresent(TemporalAccessor value, String message) {
         VerifyUtils.isNull(value, message);
         int compare = dateComparator(value);
-        IllegalArg.isTrue(-2 == compare, value.getClass().toString() + " is not a supported date class temporarily.");
+        IllegalArg.isTrue(Integer.MAX_VALUE == compare, value.getClass().toString() + " is not a supported TemporalAccessor class temporarily.");
         VerifyUtils.notTrue(gte0(compare), message);
     }
 
     //FutureOrPresent : java.util.Date,
     public static void futureOrPresent(Date value, String message) {
         VerifyUtils.isNull(value, message);
-        Clock clock = getClock(getDuration());
-        int compare = value.toInstant().compareTo(Instant.now(clock));
+        int compare = value.toInstant().compareTo(Instant.now(SYSTEM_DEFAULT_CLOCK));
         VerifyUtils.notTrue(gt0(compare), message);
     }
 
     //FutureOrPresent : java.util.Calendar
     public static void futureOrPresent(Calendar value, String message) {
         VerifyUtils.isNull(value, message);
-        Clock clock = getClock(getDuration());
-        int compare = value.toInstant().compareTo(Instant.now(clock));
+        int compare = value.toInstant().compareTo(Instant.now(SYSTEM_DEFAULT_CLOCK));
         VerifyUtils.notTrue(gte0(compare), message);
     }
 
@@ -925,23 +910,21 @@ public class Verifies {
     public static void past(TemporalAccessor value, String message) {
         VerifyUtils.isNull(value, message);
         int compare = dateComparator(value);
-        IllegalArg.isNull(-2 == compare, value.getClass().toString() + " is not a supported date class temporarily.");
+        IllegalArg.isNull(Integer.MAX_VALUE == compare, value.getClass().toString() + " is not a supported TemporalAccessor class temporarily.");
         VerifyUtils.notTrue(lt0(compare), message);
     }
 
     //past : java.util.Date,
     public static void past(Date value, String message) {
         VerifyUtils.isNull(value, message);
-        Clock clock = getClock(getDuration());
-        int compare = value.toInstant().compareTo(Instant.now(clock));
+        int compare = value.toInstant().compareTo(Instant.now(SYSTEM_DEFAULT_CLOCK));
         VerifyUtils.notTrue(lt0(compare), message);
     }
 
     //past : java.util.Calendar
     public static void past(Calendar value, String message) {
         VerifyUtils.isNull(value, message);
-        Clock clock = getClock(getDuration());
-        int compare = value.toInstant().compareTo(Instant.now(clock));
+        int compare = value.toInstant().compareTo(Instant.now(SYSTEM_DEFAULT_CLOCK));
         VerifyUtils.notTrue(lt0(compare), message);
     }
 
@@ -949,23 +932,21 @@ public class Verifies {
     public static void pastOrPresent(TemporalAccessor value, String message) {
         VerifyUtils.isNull(value, message);
         int compare = dateComparator(value);
-        IllegalArg.isTrue(-2 == compare, value.getClass().toString() + " is not a supported date class temporarily.");
+        IllegalArg.isTrue(Integer.MAX_VALUE == compare, value.getClass().toString() + " is not a supported TemporalAccessor class temporarily.");
         VerifyUtils.notTrue(lte0(compare), message);
     }
 
     //PastOrPresent : java.util.Date,
     public static void pastOrPresent(Date value, String message) {
         VerifyUtils.isNull(value, message);
-        Clock clock = getClock(getDuration());
-        int compare = value.toInstant().compareTo(Instant.now(clock));
+        int compare = value.toInstant().compareTo(Instant.now(SYSTEM_DEFAULT_CLOCK));
         VerifyUtils.notTrue(lt0(compare), message);
     }
 
     //PastOrPresent : java.util.Calendar
     public static void pastOrPresent(Calendar value, String message) {
         VerifyUtils.isNull(value, message);
-        Clock clock = getClock(getDuration());
-        int compare = value.toInstant().compareTo(Instant.now(clock));
+        int compare = value.toInstant().compareTo(Instant.now(SYSTEM_DEFAULT_CLOCK));
         VerifyUtils.notTrue(lte0(compare), message);
     }
 

+ 104 - 102
lift-common/src/main/java/cn.com.ty.lift.common/verify/VerifyProcessor.java

@@ -1,7 +1,5 @@
 package cn.com.ty.lift.common.verify;
 
-import cn.hutool.core.collection.IterUtil;
-import cn.hutool.core.util.ArrayUtil;
 import lombok.extern.slf4j.Slf4j;
 
 import javax.validation.constraints.*;
@@ -10,7 +8,10 @@ import java.lang.annotation.Annotation;
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
 import java.lang.invoke.MethodType;
-import java.lang.reflect.*;
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.net.IDN;
@@ -29,7 +30,7 @@ import java.util.stream.Collectors;
 import static java.util.regex.Pattern.CASE_INSENSITIVE;
 
 /**
- * the validation for parameter implements javax.validation.constraints.*,
+ * the validation for parameter implements {@linkplain javax.validation.constraints},
  * reform from hibernate validator (v6.0.16.Final)
  *
  * @author wcz
@@ -40,35 +41,35 @@ public class VerifyProcessor {
     /**
      * the name of the verify method.
      */
-    private final String                      verifyMethod                  = "verify";
+    private final String                  verifyMethod                  = "verify";
     /**
      * the list of validation annotation & method can be work in {@code javax.validation.constraints.*}
      */
-    private final Map<Class<?>, Method>       verifyMethodMap               = new ConcurrentHashMap<>();
+    private final Map<Class<?>, Method>   verifyMethodMap               = new ConcurrentHashMap<>();
     /**
      * whether write log to file. it's {@code true} by default.
      */
-    private       boolean                     logWrite                      = true;
+    private       boolean                 logWrite                      = true;
     /**
      * the message to complete verify.
      */
-    private final ThreadLocal<String>         message                       = new ThreadLocal<>();
+    private final ThreadLocal<String>     message                       = new ThreadLocal<>();
     /**
      * the type of message ,1: verify ,2: illegal argument
      */
-    private final ThreadLocal<Integer>        code                          = new ThreadLocal<>();
+    private final ThreadLocal<Integer>    code                          = new ThreadLocal<>();
     /**
      * the max length for a valid email address local part.
      */
-    private final int                         MAX_LOCAL_PART_LENGTH         = 64;
+    private final int                     MAX_LOCAL_PART_LENGTH         = 64;
     /**
      * the regular expression for local part of a valid email address.
      */
-    private final String                      LOCAL_PART_ATOM               = "[a-z0-9!#$%&'*+/=?^_`{|}~\u0080-\uFFFF-]";
+    private final String                  LOCAL_PART_ATOM               = "[a-z0-9!#$%&'*+/=?^_`{|}~\u0080-\uFFFF-]";
     /**
      * the regular expression for the local part of an email address.
      */
-    private final String                      LOCAL_PART_INSIDE_QUOTES_ATOM = "([a-z0-9!#$%&'*.(),<>\\[\\]:;  @+/=?^_`{|}~\u0080-\uFFFF-]|\\\\\\\\|\\\\\\\")";
+    private final String                  LOCAL_PART_INSIDE_QUOTES_ATOM = "([a-z0-9!#$%&'*.(),<>\\[\\]:;  @+/=?^_`{|}~\u0080-\uFFFF-]|\\\\\\\\|\\\\\\\")";
     /**
      * Regular expression for the local part of an email address (everything before '@')
      */
@@ -107,40 +108,40 @@ public class VerifyProcessor {
     private final java.util.regex.Pattern EMAIL_DOMAIN_PATTERN = java.util.regex.Pattern.compile(
             DOMAIN + "|\\[" + IP_DOMAIN + "\\]|" + "\\[IPv6:" + IP_V6_DOMAIN + "\\]", CASE_INSENSITIVE
     );
-
     /**
      * the minimum value of compare two number for the infinity check when double or float.
      */
-    private final OptionalInt LESS_THAN    = OptionalInt.of(-1);
+    private final OptionalInt             LESS_THAN            = OptionalInt.of(-1);
     /**
      * the empty OptionalInt(value = 0) of compare two number for the infinity check when double or float.
      */
-    private final OptionalInt FINITE_VALUE = OptionalInt.empty();
+    private final OptionalInt             FINITE_VALUE         = OptionalInt.empty();
     /**
      * the maximun value of compare two number for the infinity check when double or float.
      */
-    private final OptionalInt GREATER_THAN = OptionalInt.of(1);
+    private final OptionalInt             GREATER_THAN         = OptionalInt.of(1);
     /**
      * short 0
      */
-    private final short       SHORT_ZERO   = (short) 0;
+    private final short                   SHORT_ZERO           = (short) 0;
     /**
      * byte 0
      */
-    private final byte        BYTE_ZERO    = (byte) 0;
+    private final byte                    BYTE_ZERO            = (byte) 0;
     /**
      * to private the constrctor.
      */
     private VerifyProcessor() {
-        collectVerifyAnnotation();
+        collectVerifyClassMethod();
     }
+
     /**
      * collect all vaild validation annotation from the methods.
      */
-    private void collectVerifyAnnotation() {
+    private void collectVerifyClassMethod() {
         Method[] declaredMethods = this.getClass().getDeclaredMethods();
         List<Method> verifyMethods = Arrays.stream(declaredMethods).filter(method -> verifyMethod.equals(method.getName())).collect(Collectors.toList());
-        isTrue(verifyMethods.isEmpty(), "There is no method named 'verify' in VerifyProcessor.");
+        isTrue(verifyMethods.isEmpty(), "No any method named 'verify' in VerifyProcessor.");
         for (Method method : verifyMethods) {
             Optional<Class<?>> classOptional = Arrays.stream(method.getParameterTypes()).filter(type -> Annotation.class.isAssignableFrom(type)).findFirst();
             classOptional.ifPresent(verifyClass -> {
@@ -163,12 +164,27 @@ public class VerifyProcessor {
     /**
      * get the singleton instance of this
      */
-    private static VerifyProcessor getInstance() {
+    private static VerifyProcessor processor() {
         return Builder.INSTANCE;
     }
+
+    /**
+     * to do verify by using the singleton instance.
+     *
+     * @param logWrite {@code true} log information, otherwise no log to file.
+     * @param object   the target object to verify.
+     * @param fields   the list of fields to verify.
+     */
     public static void perform(final boolean logWrite, final Object object, final String... fields) {
         Builder.INSTANCE.logWrite(logWrite).action(object, fields);
     }
+
+    /**
+     * to do verify by using the singleton instance.
+     *
+     * @param object the target object to verify.
+     * @param fields the list of fields to verify.
+     */
     public static void perform(final Object object, final String... fields) {
         Builder.INSTANCE.action(object, fields);
     }
@@ -562,7 +578,6 @@ public class VerifyProcessor {
         }
         return result;
     }
-
     /**
      * Checks the validity of the domain name used in an email. To be valid it should be either a valid host name, or an
      * IP address wrapped in [].
@@ -714,11 +729,11 @@ public class VerifyProcessor {
             setIllegalArg("The value of @DecimalMax is null, a invalid BigDecimal format.");
             return false;
         }
-        BigDecimal max = newBigDecimal(maxValue);
+        final BigDecimal max = newBigDecimal(maxValue);
         if (isNull(max)) {
             return false;
         }
-        BigDecimal val;
+        final BigDecimal val;
         if (isNumber) {
             val = newBigDecimal((Number) value);
         } else {
@@ -727,8 +742,8 @@ public class VerifyProcessor {
         if (isNull(val)) {
             return false;
         }
-        int compare = decimalComparator(value, val, max, GREATER_THAN);
-        boolean inclusive = annotation.inclusive();
+        final int compare = decimalComparator(value, val, max, GREATER_THAN);
+        final boolean inclusive = annotation.inclusive();
         //inclusive ? comparisonResult <= 0 : comparisonResult < 0;
         if (inclusive) {
             return lte0(compare);
@@ -763,11 +778,11 @@ public class VerifyProcessor {
             setIllegalArg("The value of @DecimalMin is null, a invalid BigDecimal format.");
             return false;
         }
-        BigDecimal min = newBigDecimal(minValue);
+        final BigDecimal min = newBigDecimal(minValue);
         if (isNull(min)) {
             return false;
         }
-        BigDecimal val;
+        final BigDecimal val;
         if (isNumber) {
             val = newBigDecimal((Number) value);
         } else {
@@ -776,8 +791,8 @@ public class VerifyProcessor {
         if (isNull(val)) {
             return false;
         }
-        int compare = decimalComparator(value, val, min, LESS_THAN);
-        boolean inclusive = annotation.inclusive();
+        final int compare = decimalComparator(value, val, min, LESS_THAN);
+        final boolean inclusive = annotation.inclusive();
         //inclusive ? comparisonResult >= 0 : comparisonResult > 0;
         if (inclusive) {
             return gte0(compare);
@@ -836,7 +851,7 @@ public class VerifyProcessor {
         if (isNull(value)) {
             return false;
         }
-        int length = length(value);
+        final int length = length(value);
         if(-1 == length){
             setIllegalArg("The @NotEmpty only supports CharSequence & Collection & Map & Array & Iterator & Enumeration.");
             return false;
@@ -903,7 +918,7 @@ public class VerifyProcessor {
         final int min = annotation.min();
         final int max = annotation.max();
         String message = annotation.message();
-        if(null != message && !message.trim().isEmpty()){
+        if (notBlank(message)) {
             if(message.contains("{min}")){
                 message = message.replace("{min}", String.valueOf(min));
             }
@@ -927,7 +942,7 @@ public class VerifyProcessor {
             setIllegalArg("The min (%s) and max (%s) length of @Size cannot be negative.", min, max);
             return false;
         }
-        int length = length(value);
+        final int length = length(value);
         if(-1 == length){
             setIllegalArg("The @Size only supports CharSequence & Collection & Map & Array & Iterator & Enumeration.");
             return false;
@@ -950,7 +965,7 @@ public class VerifyProcessor {
         final int maxInteger = annotation.integer();
         final int maxFraction = annotation.fraction();
         String message = annotation.message();
-        if(null != message && !message.trim().isEmpty()){
+        if (notBlank(message)) {
             if(message.contains("{integer}")){
                 message = message.replace("{integer}", String.valueOf(maxInteger));
             }
@@ -1154,7 +1169,7 @@ public class VerifyProcessor {
             return false;
         }
         final long max = annotation.value();
-        int compare;
+        final int compare;
         if (isNumber) {
             compare = numberComparator((Number) value, max, GREATER_THAN);
         } else {
@@ -1194,7 +1209,7 @@ public class VerifyProcessor {
             return false;
         }
         final long min = annotation.value();
-        int compare;
+        final int compare;
         if (isNumber) {
             compare = numberComparator((Number) value, min, LESS_THAN);
         } else {
@@ -1217,7 +1232,7 @@ public class VerifyProcessor {
      *
      * @param value      any number value
      * @param bounds   the other value
-     * @param treatNanAs return when the value equal the infinity.
+     * @param treatNanAs return when the value is {@code NaN}.
      * @return {@code -1} value less than limit, {@code 0} value equal limit, {@code 1} value greater than limit.
      */
     private int numberComparator(Number value, long bounds, OptionalInt treatNanAs) {
@@ -1455,7 +1470,7 @@ public class VerifyProcessor {
             setIllegalArg("The @Future only supports TemporalAccessor & Calendar & Date.");
             return false;
         }
-        int compare = dateComparator(value, isTemporalAccessor, isDate);
+        final int compare = dateComparator(value, isTemporalAccessor, isDate);
         if (Integer.MAX_VALUE == compare) {
             return false;
         }
@@ -1485,7 +1500,7 @@ public class VerifyProcessor {
             setIllegalArg("The @FutureOrPresent only supports TemporalAccessor & Calendar & Date.");
             return false;
         }
-        int compare = dateComparator(value, isTemporalAccessor, isDate);
+        final int compare = dateComparator(value, isTemporalAccessor, isDate);
         if (Integer.MAX_VALUE == compare) {
             return false;
         }
@@ -1515,7 +1530,7 @@ public class VerifyProcessor {
             setIllegalArg("The @Past only supports TemporalAccessor & Calendar & Date.");
             return false;
         }
-        int compare = dateComparator(value, isTemporalAccessor, isDate);
+        final int compare = dateComparator(value, isTemporalAccessor, isDate);
         if (Integer.MAX_VALUE == compare) {
             return false;
         }
@@ -1545,7 +1560,7 @@ public class VerifyProcessor {
             setIllegalArg("The @PastOrPresent only supports TemporalAccessor & Calendar & Date.");
             return false;
         }
-        int compare = dateComparator(value, isTemporalAccessor, isDate);
+        final int compare = dateComparator(value, isTemporalAccessor, isDate);
         if (Integer.MAX_VALUE == compare) {
             return false;
         }
@@ -1562,30 +1577,21 @@ public class VerifyProcessor {
     private List<Field> fieldFilter(final Object object, final String... fields) {
         Class<?> objectClass = object.getClass();
         // get fields, if has specify fields, otherwise get all fields on the object.
-        if(ArrayUtil.isEmpty(fields)){
+        if (isEmpty(fields)) {
             return Collections.unmodifiableList(Arrays.asList(objectClass.getDeclaredFields()));
         }
         List<Field> verifyFields = new ArrayList<>();
         for (String field : fields) {
-            Field verifyField = null;
-            //1 get the declared field on this class.
             try {
-                verifyField = objectClass.getDeclaredField(field);
+                Field verifyField = objectClass.getDeclaredField(field);
+                verifyFields.add(verifyField);
             } catch (NoSuchFieldException e) {
+                throw newIllegalArgException("No such field '%s' in : %s.", field, objectClass.getCanonicalName());
             }
-            // 2 get from the private field on the superclass.
-            if (isNull(verifyField)) {
-                try {
-                    verifyField = objectClass.getSuperclass().getDeclaredField(field);
-                } catch (NoSuchFieldException e) {
-                    throw illegalArgException("No such field [%s] in : %s.", field, objectClass.getCanonicalName());
-                }
-            }
-            verifyFields.add(verifyField);
         }
         //if vaild fields is empty
         if (verifyFields.isEmpty()) {
-            throw illegalArgException("No field specify to verify.");
+            throw newIllegalArgException("No field specify to verify.");
         }
         return Collections.unmodifiableList(verifyFields);
     }
@@ -1602,12 +1608,12 @@ public class VerifyProcessor {
         }
         //get all annotation of the field
         Annotation[] annotations = field.getDeclaredAnnotations();
-        if(ArrayUtil.isEmpty(annotations)){
+        if (isEmpty(annotations)) {
             return null;
         }
         //filter the validation annotation
         List<Annotation> verifyAnnos = Arrays.stream(annotations).filter(anno -> verifyMethodMap.keySet().contains(anno.annotationType())).collect(Collectors.toList());
-        if(IterUtil.isEmpty(verifyAnnos)){
+        if (verifyAnnos.isEmpty()) {
             return null;
         }
         return Collections.unmodifiableList(verifyAnnos);
@@ -1621,56 +1627,43 @@ public class VerifyProcessor {
      * @return the value
      */
     private Object getFieldValue(final Object object, final Field field) {
-        Object value;
+        final Object value;
         try {
             value = field.get(object);
         } catch (IllegalAccessException e) {
-            throw illegalArgException("Illegal Access [%s] in : %s.", field.getName(), object.getClass().getCanonicalName());
+            throw newIllegalArgException("Illegal Access '%s' in : %s.", field.getName(), object.getClass().getCanonicalName());
         }
         return value;
     }
 
-    /**
-     * find the method for the verify
-     *
-     * @param lookup     method handle of lookup {@link java.lang.invoke.MethodHandles.Lookup}
-     * @param methodName the name of the method
-     * @param methodType the return and the args class for the method
-     * @return method handle
-     */
     private MethodHandle methodFilter(final MethodHandles.Lookup lookup, final String methodName, final MethodType methodType) {
-        MethodHandle methodHandle;
+        final MethodHandle methodHandle;
         try {
             methodHandle = lookup.findVirtual(lookup.lookupClass(), methodName, methodType);
         } catch (NoSuchMethodException | IllegalAccessException e) {
-            throw illegalArgException("No such method [%s(%s)] in VerifyProcessor.", methodName, methodType);
+            throw newIllegalArgException("No such method %s%s in VerifyProcessor.", methodName, methodType);
         }
         return methodHandle;
     }
-    /**
-     * invoke the method bind with the target object
-     *
-     * @param methodHandle method handle{@link MethodHandle}
-     * @param target       the target object
-     * @param args         the list of args
-     * @return result
-     */
-    private boolean invokeMethod(final MethodHandle methodHandle, final Object target, final Object... args) {
-        boolean invoke;
+
+    private boolean invokeMethod(final Object target, final MethodHandle methodHandle, final Object... args) {
+        final boolean invoke;
         try {
             invoke = (boolean) methodHandle.bindTo(target).invokeWithArguments(args);
         } catch (Throwable throwable) {
-            throw illegalArgException("Invoke the target method [%s] failed.", methodHandle);
+            throw newIllegalArgException("Invoke the target method [%s] failed.", methodHandle);
         }
         return invoke;
     }
-
-    private boolean invokeMethod(final Method method, final Object target, final Object value, final Annotation verifyAnno) {
-        boolean invoke = true;
+    /**
+     * invoke the target method to verify.
+     */
+    private boolean invokeMethod(final Object target, final Method method, final Object value, final Annotation annotation) {
+        final boolean invoke;
         try {
-            invoke = (boolean) method.invoke(target, value, verifyAnno);
+            invoke = (boolean) method.invoke(target, value, annotation);
         } catch (IllegalAccessException | InvocationTargetException e) {
-            throw illegalArgException("Invoke the target method [%s(Object,%s)] failed.", method.getName(), verifyAnno.annotationType().getName());
+            throw newIllegalArgException("Invoke the target method [%s(Object,%s)] failed.", method.getName(), annotation.annotationType().getName());
         }
         return invoke;
     }
@@ -1688,7 +1681,7 @@ public class VerifyProcessor {
         for (Field verifyField : verifyFields) {
             //filter the validation annotation
             List<Annotation> verifyAnnos = annotationFilter(verifyField);
-            if (IterUtil.isEmpty(verifyAnnos)) continue;
+            if (isEmpty(verifyAnnos)) continue;
             //get value.
             Object value = getFieldValue(object, verifyField);
             for (Annotation verifyAnno : verifyAnnos) {
@@ -1696,15 +1689,15 @@ public class VerifyProcessor {
                 //get method
                 Method method = verifyMethodMap.get(annotationType);
                 // result.
-                boolean invoke = invokeMethod(method, this, value, verifyAnno);
+                boolean invoke = invokeMethod(this, method, value, verifyAnno);
                 if (invoke) continue;
                 if (logWrite) {
                     info(verifyField, value, method, verifyAnno);
                 }
                 if(1 == code.get()){
-                    throw verifyException(message.get());
+                    throw newVerifyException(message.get());
                 }else{
-                    throw illegalArgException(message.get());
+                    throw newIllegalArgException(message.get());
                 }
             }
         }
@@ -1714,16 +1707,9 @@ public class VerifyProcessor {
      *
      * @param validField the field to valid.
      * @param value      the value of the field.
-     * @param verifyAnno  the validation annotation of the field.
      * @param method     the method to action
-     * @param result     the result of invoke the method.
+     * @param verifyAnno the validation annotation of the field.
      */
-    private void info(Field verifyField, Object value, MethodHandle methodHandle) {
-        log.info("###| FIELD       : {}", verifyField);
-        log.info("###| FIELD_VALUE : {}", value);
-        log.info("###| METHOD      : (false) {}", methodHandle);
-    }
-
     private void info(Field verifyField, Object value, Method method, Annotation verifyAnno) {
         log.info("###| FIELD       : {}", verifyField);
         log.info("###| FIELD_VALUE : {}", value);
@@ -1735,7 +1721,7 @@ public class VerifyProcessor {
      * @param message the message of exception.
      * @return a {@link IllegalArgumentException}
      */
-    private IllegalArgumentException illegalArgException(String message, Object... values) {
+    private IllegalArgumentException newIllegalArgException(String message, Object... values) {
         return new IllegalArgumentException(format(message, values));
     }
 
@@ -1745,7 +1731,7 @@ public class VerifyProcessor {
      * @param message the message of exception.
      * @return a {@link VerifyException}
      */
-    private VerifyException verifyException(String message, Object... values) {
+    private VerifyException newVerifyException(String message, Object... values) {
         return new VerifyException(format(message, values));
     }
 
@@ -1770,12 +1756,28 @@ public class VerifyProcessor {
      */
     private void isNull(Object object, String message) {
         if (null == object) {
-            throw illegalArgException(message);
+            throw newIllegalArgException(message);
         }
     }
     private void isTrue(boolean expression, String message) {
         if (expression) {
-            throw illegalArgException(message);
+            throw newIllegalArgException(message);
         }
     }
+
+    public <T> boolean isEmpty(T[] array) {
+        return array == null || array.length == 0;
+    }
+
+    public boolean isEmpty(Iterable<?> iterable) {
+        return null == iterable || isEmpty(iterable.iterator());
+    }
+
+    public boolean isEmpty(Iterator<?> Iterator) {
+        return null == Iterator || !Iterator.hasNext();
+    }
+
+    public boolean notBlank(String value) {
+        return null != value && !value.trim().isEmpty();
+    }
 }