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.
151 lines
4.0 KiB
151 lines
4.0 KiB
package com.fanruan.api.util; |
|
|
|
import com.fr.base.FRContext; |
|
import com.fr.base.Utils; |
|
import com.fr.general.ComparatorUtils; |
|
import com.fr.general.GeneralUtils; |
|
import com.fr.stable.StableUtils; |
|
import org.jetbrains.annotations.NotNull; |
|
import org.jetbrains.annotations.Nullable; |
|
|
|
import java.io.IOException; |
|
import java.util.Locale; |
|
|
|
/** |
|
* @author richie |
|
* @version 10.0 |
|
* Created by richie on 2019-08-09 |
|
*/ |
|
public class GeneralKit { |
|
/** |
|
* 返回系统的首选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); |
|
} |
|
|
|
/** |
|
* 判断两个对象是否相等 |
|
* |
|
* @param var1 源对象 |
|
* @param var2 待比较对象 |
|
* @return 如果两个对象相等,则返回true,否则返回false |
|
*/ |
|
public static boolean equals(Object var1, Object var2) { |
|
return ComparatorUtils.equals(var1, var2); |
|
} |
|
|
|
/** |
|
* 将一个数组中的元素按照给定的连接符连接成一个字符串 |
|
* |
|
* @param array 数组 |
|
* @param se 连接符 |
|
* @return 连接后的字符串 |
|
*/ |
|
public static String join(Object[] array, String se) { |
|
return StableUtils.join(array, se); |
|
} |
|
|
|
/** |
|
* 返回国际化区属 |
|
* |
|
* @return 国际化后区域属性 |
|
*/ |
|
@Deprecated |
|
public static Locale getLocale() { |
|
return FRContext.getLocale(); |
|
} |
|
|
|
/** |
|
* 将路径节点数组用路径分隔符"/"连接起来 |
|
* |
|
* @param nodes 路径节点数组 |
|
* @return 连接后的路径 |
|
*/ |
|
public static String pathJoin(String... nodes) { |
|
return StableUtils.pathJoin(nodes); |
|
} |
|
|
|
/** |
|
* 获取系统可用用于报表设计的字体 |
|
* |
|
* @return 可用字体数组 |
|
*/ |
|
public static String[] getAvailableFontFamilyNames() { |
|
return Utils.getAvailableFontFamilyNames4Report(); |
|
} |
|
|
|
/** |
|
* 从rgb颜色中根据透明度过滤 |
|
* |
|
* @param rgb rgb颜色值 |
|
* @param percent 透明度百分比 |
|
* @return 新的颜色 |
|
*/ |
|
public static int filterRGB(int rgb, int percent) { |
|
int gray = (int) ((0.30 * ((rgb >> 16) & 0xff) + 0.59 * ((rgb >> 8) & 0xff) + 0.11 * (rgb & 0xff)) / 3); |
|
gray = (255 - ((255 - gray) * (100 - percent) / 100)); |
|
|
|
if (gray < 0) { |
|
gray = 0; |
|
} |
|
if (gray > 255) { |
|
gray = 255; |
|
} |
|
return (rgb & 0xff000000) | (gray << 16) | (gray << 8) | (gray); |
|
} |
|
|
|
}
|
|
|