程序包 org.xmeta.util

类 UtilString

java.lang.Object
org.xmeta.util.UtilString

public class UtilString
extends Object
字符串工具类。
作者:
zyx
  • 构造器详细资料

  • 方法详细资料

    • getGroovyStringArray

      public static String[] getGroovyStringArray​(String str)
      解析使用Groovy方式定义的字符串数组,如["cb", "cb"] as String[]。
      参数:
      str - 字符串
      返回:
      数组
    • eq

      public static boolean eq​(Thing thing, String attributeName, String value)
      返回字符串是否相等,如果属性值为null也返回false。
      参数:
      thing - 模型
      attributeName - 属性名
      value - 值
      返回:
      是否相等
    • isNull

      public static boolean isNull​(Thing thing, String attributeName)
      返回指定的模型的属性是否为空,如果是字符串那么null和""都返回true。
      参数:
      thing - 模型
      attributeName - 属性名
      返回:
      是否为null
    • split

      public static String[] split​(String str, char ch)
      分割字符串的方法非String实现,稍微快一些。
      参数:
      str - 字符串
      ch - 分给符
      返回:
      结果
    • haveDescriptor

      public static boolean haveDescriptor​(String descriptors, String descriptor)
      判断描述者列表字符串中是否包含描述者。
      参数:
      descriptors - 描述者列表
      descriptor - 描述者
      返回:
      是否包含
    • insert

      public static String insert​(String source, String forInsert, int index)
      插入一个指定字符串至源字符串中,源字符串中用,号隔开的。
      参数:
      source - 源字符串
      forInsert - 需要插入的字符串
      index - 位置
      返回:
      新的字符串
    • createObjectFromParams

      public static Object createObjectFromParams​(String params, String thingPath, ActionContext actionContext)
    • createObjectFromParams

      public static Object createObjectFromParams​(Map<String,​?> values, String thingPath, ActionContext actionContext)
    • isNotNull

      public static boolean isNotNull​(String str)
    • isNull

      public static boolean isNull​(String str)
    • capFirst

      public static String capFirst​(String str)
    • uncapFirst

      public static String uncapFirst​(String str)
      让字符串的第一个字母小写。
      参数:
      str - 字符串
      返回:
      出理后的字符串
    • debug

      public static void debug​(ActionContext context, Object obj)
    • getStringArray

      public static String[] getStringArray​(String strArray)
    • toIntArray

      public static int[] toIntArray​(String intArray)
    • getParams

      public static Map<String,​String> getParams​(String str)
      解码参数字符串,分隔符默认为&,默认编码utf-8,过滤引号。
      参数:
      str - 参数字符串
      返回:
      参数
    • getParams

      public static Map<String,​String> getParams​(String str, String splitStr)
      解码参数字符串,默认编码utf-8,过滤引号。
      参数:
      str - 参数字符串
      splitStr - 分隔符
      返回:
      参数
    • getParams

      public static Map<String,​String> getParams​(String str, String splitStr, String encoding)
      解码参数字符串,过滤引号。
      参数:
      str - 参数字符串
      splitStr - 分隔符
      encoding - 编码
      返回:
      分析后的参数集
    • getParams

      public static Map<String,​String> getParams​(String str, String splitStr, String encoding, boolean trimQuotate)
      解码参数字符串。
      参数:
      str - 参数字符串
      splitStr - 分隔符
      encoding - 编码
      trimQuotate - 是否过滤参数值包围的引号
      返回:
      参数集
    • getInt

      public static int getInt​(String str)
    • getString

      public static String getString​(Thing thing, String attribute, ActionContext actionContext)
      从模型取指定的属性的字符串值,然后从actionContext中取可能的值。
      参数:
      thing - 模型
      attribute - 属性名
      actionContext - 变量上下文
      返回:
    • getString

      public static String getString​(String value, ActionContext actionContext)

      从制定的字符串值中读取字符串。

      如果字符串值为"号开头,那么返回"号包围的字符串值,如果是以res:开头那么从资源文件中读取,如果以上条件都不符合那么从 actionContext或binding中读取。

      如果是读取资源,那么字符串的格式为:res:<resourceName>:<varName>:<defaultValue>。
      参数:
      value - 字符串值
      actionContext - 动作上下文
      返回:
      字符串
    • toUnicode

      public static String toUnicode​(String theString, boolean escapeSpace)
    • toHex

      public static char toHex​(int nibble)
    • trimFileName

      public static String trimFileName​(String str)
      返回一个正常的文件名,把/\.?等替换成_,并且长度保留最后30,如果大于30增加hashcode。
      参数:
      str -
      返回:
    • getThingManagerFileName

      public static String getThingManagerFileName​(Thing thing)
    • toHexString

      public static String toHexString​(byte[] bytes)
    • hexStringToByteArray

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

      public static String getSizeInfo​(double size)