Class LangUtils


  • public class LangUtils
    extends Object
    Created by hocgin on 2020/8/6 email: hocgin@gmail.com
    Author:
    hocgin
    • Constructor Detail

      • LangUtils

        public LangUtils()
    • Method Detail

      • isPresent

        public boolean isPresent​(String name)
      • equals

        public boolean equals​(Long s1,
                              Long s2)
      • toMap

        public <K,​V> Map<K,​V> toMap​(Collection<V> values,
                                                Function<? super V,​K> keyFunction)
        数组 转为 Map
        Type Parameters:
        K - any
        V - any
        Parameters:
        values - values
        keyFunction - keyFunction
        Returns:
        Map
      • toMap

        public <K,​V,​Z> Map<K,​Z> toMap​(Collection<V> values,
                                                        Function<? super V,​K> keyFunction,
                                                        Function<? super V,​Z> valueFunction)
      • getFieldValue

        public Object getFieldValue​(Object fieldObject,
                                    Field field,
                                    Object def)
        获取对象字段的值
        Parameters:
        fieldObject - fieldObject
        field - field
        def - def
        Returns:
        object
      • getObjectValue

        public <T> T getObjectValue​(Object fieldObject,
                                    Field field,
                                    Object def)
      • setFieldValue

        public void setFieldValue​(Object fieldObject,
                                  Field field,
                                  Object value)
        设置对象某字段的值
        Parameters:
        fieldObject - fieldObject
        field - field
        value - value
      • computeIfAbsent

        public static <K,​V> V computeIfAbsent​(Map<K,​V> concurrentHashMap,
                                                    K key,
                                                    Function<? super K,​? extends V> mappingFunction)
      • getAllField

        public static List<Field> getAllField​(Class<?> clazz)
        获取所有字段
        Returns:
        []
      • excludeOverrideSuperField

        public static Map<String,​Field> excludeOverrideSuperField​(Field[] fields,
                                                                        List<Field> superFieldList)
        排序重置父类属性
        Parameters:
        fields -
        superFieldList -
        Returns:
      • isBaseType

        public boolean isBaseType​(Class<?> clazz)
        判断是否基础类型
        Parameters:
        clazz - clazz
        Returns:
        bool
      • toList

        public <V,​R> List<R> toList​(Iterable<V> values,
                                          Function<? super V,​R> keyFunction)
        提取 List 项的值
        Type Parameters:
        V -
        R -
        Parameters:
        values -
        keyFunction -
        Returns:
      • toList

        public <V,​R> List<R> toList​(Iterable<V> values,
                                          boolean filterNull,
                                          Function<? super V,​R> fn)
      • removeIfExits

        public <R,​T> List<R> removeIfExits​(Collection<R> all,
                                                 Collection<T> sub,
                                                 BiFunction<R,​T,​Boolean> biFunction)
        移除 all 中的 sub all - sub
        Type Parameters:
        R -
        T -
        Parameters:
        all -
        sub -
        biFunction -
        Returns:
      • getMixed

        public <R,​T> List<R> getMixed​(Collection<R> l1,
                                            Collection<T> l2,
                                            BiFunction<R,​T,​Boolean> biFunction)
        获取两个 List 的交集
        Type Parameters:
        R -
        T -
        Parameters:
        l1 -
        l2 -
        biFunction -
        Returns:
      • getOrDefault

        public <T> T getOrDefault​(T v,
                                  T def)
        获取如果为 NULL,则返回默认值
        Type Parameters:
        T -
        Parameters:
        v -
        def -
        Returns:
      • callIfNotNull

        public <K,​V> Optional<V> callIfNotNull​(K v,
                                                     Function<K,​V> func)
        如果传入的值不为 NULL,则当作入参执行后续函数
        Type Parameters:
        K -
        V -
        Parameters:
        v -
        func -
        Returns:
      • runIfNotNull

        public <K> void runIfNotNull​(K v,
                                     ConsumerThrow<K> func)
      • setIfNotNull

        public <T> void setIfNotNull​(T v,
                                     Consumer<T> consumer)
        如果传入的值不为 NULL,则当作入参执行后续函数
        Parameters:
        v -
        consumer -
      • groupCallback

        public <R,​P> List<R> groupCallback​(Collection<P> allIds,
                                                 Function<Collection<P>,​Collection<R>> queryFunction,
                                                 int len)
        分组调用 - 将大批量数据,分组后,在整合
        Type Parameters:
        R -
        P -
        Parameters:
        allIds -
        queryFunction -
        len -
        Returns:
      • toGroup

        public <K,​T> Map<K,​List<T>> toGroup​(List<T> list,
                                                        Function<? super T,​? extends K> keyFunction)
      • proxy

        public void proxy​(String host,
                          String port)
        设置代理
        Parameters:
        host -
        port -
      • modifyMD5

        public static Path modifyMD5​(Path path)
      • extract

        public static String extract​(String regex,
                                     String content)
        提取内容
        Parameters:
        regex -
        content -
        Returns:
      • lastElement

        public static <T> T lastElement​(T[] elements)
      • reverse

        public static <K,​V> Map<V,​K> reverse​(Map<K,​V> map)
        Map Key Value 调换
        Type Parameters:
        K -
        V -
        Parameters:
        map -
        Returns:
      • getDuplicateElements

        public static <E> List<E> getDuplicateElements​(List<E> list)
        获取 List 中重复的元素
        Type Parameters:
        E -
        Parameters:
        list -
        Returns: