当前位置 : 主页 > 编程语言 > c++ >

StringUnit

来源:互联网 收集:自由互联 发布时间:2021-06-30
StringUnit package com.skspruce.ism.detect.webapi.util;import java.util.ArrayList;import java.util.List;import java.util.Set;import java.util.regex.Matcher;import java.util.regex.Pattern;/** * fix string * * @author ouzhb */public class Str
StringUnit
package com.skspruce.ism.detect.webapi.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * fix string
 *
 * @author ouzhb
 */
public class StringUtil {

    /**
     * null
     * @param obj
     * @return
     */
    public static boolean isNull(String obj) {
        if (obj == null) {
            return true;
        } else if (obj.toString().trim().equals("")) {
            return true;
        } else if (obj.toString().trim().toLowerCase().equals("null")) {
            return true;
        }

        return false;
    }

    /**
     * number
     *
     * @param str
     * @return
     */
    public static boolean isNumber(String str) {
        Pattern pattern = Pattern.compile("[+-]?[0-9]+[0-9]*(\\.[0-9]+)?");
        Matcher match = pattern.matcher(str);

        return match.matches();
    }

    /**
     *long to bytes[]
     * @param l
     * @return byte[]
     */
    public static byte[] longToBytes(long l) {
        byte[] b = new byte[8];
        b[0] = (byte) (l >>> 56);
        b[1] = (byte) (l >>> 48);
        b[2] = (byte) (l >>> 40);
        b[3] = (byte) (l >>> 32);
        b[4] = (byte) (l >>> 24);
        b[5] = (byte) (l >>> 16);
        b[6] = (byte) (l >>> 8);
        b[7] = (byte) (l);
        return b;
    }

    public static String setString(Set
 
   sets) {
        List
  
    list = new ArrayList<>(); list.addAll(sets); StringBuffer sb = new StringBuffer(); for(int i=0;i
  
 
网友评论