程序包 org.xmeta.util

类 UtilData


  • public class UtilData
    extends Object
    数据工具类。
    作者:
    zyx
    • 构造器详细资料

      • UtilData

        public UtilData()
    • 方法详细资料

      • equalsOne

        public static boolean equalsOne​(String str,
                                        String[] matchs)
        如果str和matchs中任何一个匹配返回true,如果str=null或者matchs=null,返回false。
        参数:
        str - 字符串
        matchs - 匹配正则表达式
        返回:
        是否匹配
      • format

        public static String format​(Object value,
                                    String pattern)
        把数据对象转换为字符串类型。
        参数:
        value - 值
        pattern - 格式
        返回:
        结果
      • addToSource

        public static List<Thing> addToSource​(List<Thing> source,
                                              List<Thing> forAdd,
                                              boolean strict)
        添加指定的事物列表到已有的事物列表中,添加时如果存在第一个的描述者相同且名字相同的则不添加。
        参数:
        source - 源事物列表
        forAdd - 要添加的事物列表
        strict - 是否严格判断,如果是严格判断那么校验两个事物必须相等,否则校验事物的描述者和名
        返回:
        结果
      • addToSource

        public static List<Thing> addToSource​(List<Thing> source,
                                              Thing forAdd,
                                              boolean strict)
        添加指定的事物到源事物列表中。
        参数:
        source - 源事物列表
        forAdd - 需要添加的事物
        strict - 是否严格判断,如果是严格判断那么校验两个事物必须相等,否则校验事物的描述者和名
        返回:
        事物列表
      • getByte

        public static byte getByte​(Object v,
                                   byte defaultValue)
      • getBytes

        public static byte[] getBytes​(Object v,
                                      byte[] defaultValue)
      • getChar

        public static char getChar​(Object v,
                                   char defaultValue)
      • getDate

        public static Date getDate​(Object v,
                                   Date defaultValue)
      • getDateDefault

        public static Date getDateDefault​(String defaultValue)
      • getDouble

        public static double getDouble​(Object v,
                                       double defaultValue)
      • getFloat

        public static float getFloat​(Object v,
                                     float defaultValue)
      • getLong

        public static long getLong​(Object v,
                                   long defaultValue)
      • getInt

        public static int getInt​(Object v,
                                 int defaultValue)
      • getShort

        public static short getShort​(Object v,
                                     short defaultValue)
      • getBoolean

        public static boolean getBoolean​(Object v,
                                         boolean defaultValue)
      • getSizeInfo

        public static String getSizeInfo​(double size)
        按照字节、千字节和兆返回大小的值。
        参数:
        size - 大小
        返回:
        字符串
      • hexStringToByteArray

        public static byte[] hexStringToByteArray​(String hex)
        将"00 01 02"形式的字符串转成byte[]
        参数:
        hex - 16进制字符串
        返回:
        字节数组
      • bytesToHexString

        public static String bytesToHexString​(byte[] bytes)
        二进制转字符串。
        参数:
        bytes - 字节数组
        返回:
        16进制字符串
      • transfer

        public static Object transfer​(Object sourceValue,
                                      String targetType,
                                      String pattern,
                                      String patternType,
                                      String patternAction)
                               throws ParseException
        转换数据类型。
        参数:
        sourceValue - 原值
        targetType - 目标值
        pattern - 格式
        patternType - 格式类型
        patternAction - 动作
        返回:
        转换后的结果
        抛出:
        ParseException - 异常
      • getObject

        public static Object getObject​(Thing thing,
                                       String attributeName,
                                       ActionContext actionContext)
        返回通过属性定义的对象,首先使用UtilData获取,如果没有从actionContext中获取。
        参数:
        thing - 事物
        attributeName - 属性名
        actionContext - 变量上下文
        返回:
        对象
      • getThing

        public static Thing getThing​(Thing thing,
                                     String attributeName,
                                     ActionContext actionContext)
        根据事物的属性返回指定的事物。
        参数:
        thing - 事物
        attributeName - 属性名
        actionContext - 变量上下文
        返回:
        事物,如果不存在返回null
      • getThing

        public static Thing getThing​(Thing thing,
                                     String attributeName,
                                     String childThingPath,
                                     ActionContext actionContext)
        先从事物指定的属性上获取事物,如果不存在从子节点的路径上获取。
        参数:
        thing - 事物
        attributeName - 属性名
        childThingPath - 子事物节点
        actionContext - 变量上下文
        返回:
        要返回的额事物,如果不存在返回null
      • getData

        public static Object getData​(Thing thing,
                                     String attributeName,
                                     ActionContext actionContext)
        通过事物的属性获取数据。
        参数:
        thing - 事物
        attributeName - 属性名
        actionContext - 变量上下文
        返回:
        结果
      • isTrue

        public static boolean isTrue​(Object condition)
      • isTrue

        public static boolean isTrue​(Object condition,
                                     boolean defaultValue)
        判断condition是否为true, 当condition==null时返回传入的默认值。
        参数:
        condition -
        defaultValue -
        返回:
      • resetAttributeByType

        public static void resetAttributeByType​(Thing thing,
                                                String name,
                                                String type)