forked from fanruan/finekit
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
3.4 KiB
116 lines
3.4 KiB
package com.fanruan.api.util; |
|
|
|
import com.fr.general.ComparatorUtils; |
|
import com.fr.general.GeneralUtils; |
|
import com.fr.stable.StableUtils; |
|
import com.fr.base.TemplateUtils; |
|
import com.fr.third.guava.base.Objects; |
|
import org.jetbrains.annotations.NotNull; |
|
import org.jetbrains.annotations.Nullable; |
|
|
|
import java.io.IOException; |
|
import java.util.Map; |
|
|
|
/** |
|
* @author richie |
|
* @version 10.0 |
|
* Created by richie on 2019-08-09 |
|
*/ |
|
public class GeneralKit { |
|
/** |
|
* 根据参数来计算文档字符串 |
|
* @param query 文档来源 |
|
* @param map 参数map |
|
* @return 计算后结果 |
|
*/ |
|
public static String renderParameter4Tpl(String query, Map map) throws Exception { |
|
return TemplateUtils.renderParameter4Tpl(query, map); |
|
} |
|
/** |
|
* 返回多个属性合并计算的哈希值 |
|
* @param args 对象列表 |
|
* @return 哈希值 |
|
*/ |
|
public static int hashCode(Object... args) { |
|
return Objects.hashCode(args); |
|
} |
|
/** |
|
* 判断两个对象是否相等 |
|
* @param source 对象1 |
|
* @param des 对象2 |
|
* @return 如果两个对象相等,则返回true,否则返回false |
|
*/ |
|
public static boolean equals(Object source, Object des) { |
|
if (source == null && des == null) { |
|
return true; |
|
} else if (source == null) { |
|
return false; |
|
} else { |
|
return source!=null && source.equals(des); |
|
} |
|
} |
|
/** |
|
* 判断指定的类是否是另一个类的子类 |
|
* @param childClass 指定的类 |
|
* @param parentClass 另一个类 |
|
* @return 如果指定类是另一个类的子类则返回true,否则返回false |
|
*/ |
|
public static boolean classInstanceOf(Class childClass, Class parentClass) { |
|
return StableUtils.classInstanceOf(childClass, parentClass); |
|
} |
|
|
|
/** |
|
* 返回系统的首选MAC地址 |
|
* |
|
* @return 表示系统MAC地址的字符串 |
|
*/ |
|
public static @NotNull String getMacAddress() throws IOException { |
|
return GeneralUtils.getMacAddress(); |
|
} |
|
|
|
/** |
|
* 任意对象转换为文本值 |
|
* @param obj 待转换的对象 |
|
* @return 文本值 |
|
*/ |
|
public static @NotNull String objectToString(Object obj) { |
|
return GeneralUtils.objectToString(obj); |
|
} |
|
|
|
/** |
|
* 任意对象转换为数值,如果无法转换为数值,就返回0 |
|
* @param obj 待转换的对象 |
|
* @return 数值 |
|
*/ |
|
public static @NotNull Number objectToNumber(Object obj) { |
|
return GeneralUtils.objectToNumber(obj); |
|
} |
|
|
|
/** |
|
* 任意对象转换为数值,如果无法转换为数值,根据returnNull参数决定,返回0或者返回null |
|
* @param obj 待转换的对象 |
|
* @param returnNull 无法转换时,是否返回null |
|
* @return 数值对象或者null |
|
*/ |
|
public static @Nullable Number objectToNumber(Object obj, boolean returnNull) { |
|
return GeneralUtils.objectToNumber(obj, returnNull); |
|
} |
|
|
|
/** |
|
* 读取jar的版本号 |
|
* @return 返回jar版本号 |
|
*/ |
|
public static @Nullable String readBuildNO() { |
|
return GeneralUtils.readBuildNO(); |
|
} |
|
|
|
/** |
|
* 返回两个对象比较的大小 |
|
* @param obj1 |
|
* @param obj2 |
|
* @return 若相等返回0,obj1小于obj2返回负数,否则返回正数 |
|
*/ |
|
public static int compare(Object obj1, Object obj2) { |
|
return ComparatorUtils.compare(obj1, obj2); |
|
} |
|
}
|
|
|