<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 33,  comments - 17,  trackbacks - 0
     1/**
     2  * 判斷是不是合法手機
     3  * handset 手機號碼
     4  */

     5 public static boolean isHandset(String handset) {
     6  try {
     7   if(!handset.substring(0,1).equals("1")) {
     8    return false;
     9   }

    10   if (handset==null || handset.length()!=11{
    11    return false;
    12   }

    13   String check = "^[0123456789]+$";
    14   Pattern regex = Pattern.compile(check);
    15   Matcher matcher = regex.matcher(handset);
    16   boolean isMatched = matcher.matches();
    17   if(isMatched) {
    18    return true;
    19   }
     else {
    20    return false;
    21   }

    22  }
     catch (RuntimeException e) {
    23   return false;
    24  }
     
    25 }

    26}
    27
    28
     1 /**
     2     * 將指定byte數組以16進制的形式打印到控制臺
     3     * @param hint
     4     *            String
     5     * @param b
     6     *            byte[]
     7     * @return void
     8     */

     9    public static void printHexString(String hint, byte[] b)
    10    {
    11        System.out.print(hint);
    12        for (int i = 0; i < b.length; i++)
    13        {
    14            String hex = Integer.toHexString(b[i] & 0xFF);
    15            if (hex.length() == 1)
    16            {
    17                hex = '0' + hex;
    18            }

    19            System.out.print(hex.toUpperCase() + " ");
    20        }

    21        System.out.println("");
    22    }

    23

     1/**
     2     * 全角字符轉半角字符
     3     * 
     4     * @param QJStr
     5     * @return String
     6     */

     7    public static final String QJToBJChange(String QJStr)
     8    {
     9        char[] chr = QJStr.toCharArray();
    10        String str = "";
    11        for (int i = 0; i < chr.length; i++)
    12        {
    13            chr[i] = (char) ((int) chr[i] - 65248);
    14            str += chr[i];
    15        }

    16        return str;
    17    }

     1  /**
     2     * 去掉字符串中重復的子字符串
     3     * 
     4     * @param str
     5     * @return String
     6     */

     7    private static String removeSameString(String str)
     8    {
     9        Set<String> mLinkedSet = new LinkedHashSet<String>();
    10        String[] strArray = str.split(" ");
    11        StringBuffer sb = new StringBuffer();
    12
    13        for (int i = 0; i < strArray.length; i++)
    14        {
    15            if (!mLinkedSet.contains(strArray[i]))
    16            {
    17                mLinkedSet.add(strArray[i]);
    18                sb.append(strArray[i] + " ");
    19            }

    20        }

    21        System.out.println(mLinkedSet);
    22        return sb.toString().substring(0, sb.toString().length() - 1);
    23    }

     1/**
     2     * 設置JSpinner的編輯屬性
     3     * @param spinner 目標JSpinner
     4     * @param isAllowInvalid 是否允許輸入非法值
     5     * @param isEditable 是否允許編輯
     6     */

     7    public static void setAllowsInvalid(JSpinner spinner, boolean isAllowInvalid, boolean isEditable)
     8    {
     9        JSpinner.NumberEditor editor = new JSpinner.NumberEditor(spinner, "#");
    10        spinner.setEditor(editor);
    11        JFormattedTextField tf = ((JSpinner.NumberEditor)spinner.getEditor()).getTextField();
    12        tf.setEditable(isEditable);
    13        DefaultFormatterFactory factory = (DefaultFormatterFactory)tf.getFormatterFactory();
    14        NumberFormatter formatter = (NumberFormatter)factory.getDefaultFormatter();
    15        formatter.setAllowsInvalid(isAllowInvalid);
    16    }

    17

     1 /**   
     2     * 根據指定方法的參數去構造一個新的對象的拷貝并將他返回
     3     * @param obj 原始對象
     4     * @return 新對象
     5     * @throws NoSuchMethodException    
     6     * @throws InvocationTargetException    
     7     * @throws IllegalAccessException    
     8     * @throws InstantiationException    
     9     * @throws SecurityException    
    10     * @throws IllegalArgumentException    
    11     */

    12    @SuppressWarnings("unchecked")
    13    public static Object copy(Object obj) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException,
    14                    InvocationTargetException, NoSuchMethodException
    15    {
    16        //獲得對象的類型    
    17        Class classType = obj.getClass();
    18
    19        //通過默認構造方法去創建一個新的對象,getConstructor的視其參數決定調用哪個構造方法    
    20        Object objectCopy = classType.getConstructor(new Class[]{}).newInstance(new Object[]{});
    21
    22        //獲得對象的所有屬性    
    23        Field[] fields = classType.getDeclaredFields();
    24
    25        for(int i = 0; i < fields.length; i++)
    26        {
    27            //獲取數組中對應的屬性    
    28            Field field = fields[i];
    29
    30            String fieldName = field.getName();
    31            String stringLetter = fieldName.substring(01).toUpperCase();
    32
    33            //獲得相應屬性的getXXX和setXXX方法名稱    
    34            String getName = "get" + stringLetter + fieldName.substring(1);
    35            String setName = "set" + stringLetter + fieldName.substring(1);
    36
    37            //獲取相應的方法    
    38            Method getMethod = classType.getMethod(getName, new Class[]{});
    39            Method setMethod = classType.getMethod(setName, new Class[]{field.getType()});
    40
    41            //調用源對象的getXXX()方法    
    42            Object value = getMethod.invoke(obj, new Object[]{});
    43
    44            //調用拷貝對象的setXXX()方法    
    45            setMethod.invoke(objectCopy, new Object[]{value});
    46        }

    47
    48        return objectCopy;
    49    }

    50
    51

     1//過濾特殊字符
     2public static String encoding(String src){
     3        if (src==null)
     4            return "";
     5        StringBuilder result=new StringBuilder();
     6        if (src!=null){
     7            src=src.trim();
     8            for (int pos=0;pos<src.length();pos++){
     9                switch(src.charAt(pos)){
    10                    case '\"':result.append("&quot;");break;
    11                    case '<':result.append("&lt;");break;
    12                    case '>':result.append("&gt;");break;
    13                    case '\'':result.append("&apos;");break;
    14                    case '&':result.append("&amp;");break;
    15                    case '%':result.append("&pc;");break;
    16                    case '_':result.append("&ul;");break;
    17                    case '#':result.append("&shap;");break;
    18                    case '?':result.append("&ques;");break;
    19                    default:result.append(src.charAt(pos));break;
    20                }

    21            }

    22        }

    23        return result.toString();
    24    }

    25    
    26//反過濾特殊字符
    27    public static String decoding(String src){
    28        if (src==null)
    29            return "";
    30        String result=src;
    31        result=result.replace("&quot;""\"").replace("&apos;""\'");
    32        result=result.replace("&lt;""<").replace("&gt;"">");
    33        result=result.replace("&amp;""&");
    34        result=result.replace("&pc;""%").replace("&ul""_");
    35        result=result.replace("&shap;""#").replace("&ques""?");
    36        return result;
    37    }

    38

     1 /**
     2  * 寫入日志
     3  * filePath 日志文件的路徑
     4  * code 要寫入日志文件的內容
     5  */

     6 public static boolean print(String filePath,String code) {
     7  try {
     8   File tofile=new File(filePath);
     9   FileWriter fw=new FileWriter(tofile,true);
    10   BufferedWriter bw=new BufferedWriter(fw);
    11   PrintWriter pw=new PrintWriter(bw);
    12   
    13   System.out.println(getDate()+":"+code);
    14   pw.println(getDate()+":"+code);
    15   pw.close();
    16   bw.close();
    17   fw.close();
    18   return true;
    19  }
     catch (IOException e) {
    20   return false;
    21  }

    22 }

    23

     1// 字符串匹配的算法. 
     2public String getMaxMatch(String a,String b) {   
     3        StringBuffer tmp = new StringBuffer();   
     4        String maxString = "";   
     5        int max = 0;   
     6        int len = 0;   
     7        char[] aArray = a.toCharArray();   
     8        char[] bArray = b.toCharArray();   
     9        int posA = 0;   
    10        int posB = 0;   
    11        while(posA<aArray.length-max) {   
    12            posB = 0;   
    13            while(posB<(bArray.length-max)) {                                   
    14                 if(aArray[posA]==bArray[posB]) {   
    15                      len = 1;   
    16                      tmp = new StringBuffer();   
    17                      tmp.append(aArray[posA]);                                           
    18                      while((posA+len<aArray.length)&&(posB+len<bArray.length)&&(aArray[posA+len]==bArray[posB+len])) {   
    19                           tmp.append(aArray[posA+len]);   
    20                           len++;   
    21                      }
       
    22                      if(len>max) {   
    23                            max = len;   
    24                            maxString = tmp.toString();   
    25                      }
       
    26                 }
       
    27                      posB++;   
    28            }
       
    29                      posA++;   
    30         }
               
    31            return maxString;                       
    32    }

    33
    34

    posted on 2008-07-23 17:20 scea2009 閱讀(253) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    <2008年7月>
    293012345
    6789101112
    13141516171819
    20212223242526
    272829303112
    3456789

    常用鏈接

    留言簿(1)

    隨筆分類

    隨筆檔案

    PL/SQL存儲過程與函數

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲经典在线中文字幕| 亚洲日韩乱码中文无码蜜桃臀| 一个人免费视频在线观看www| 亚洲国产精品lv| 午夜毛片不卡免费观看视频| 精品免费久久久久国产一区| 亚洲日本va午夜中文字幕一区| 在线免费观看污网站| 黄色视频在线免费观看| 亚洲一区二区三区国产精品无码 | 久久午夜无码免费| 亚洲精品一区二区三区四区乱码| 国产在线19禁免费观看国产| 波多野结衣免费一区视频 | 一级毛片大全免费播放下载| 91在线精品亚洲一区二区| 四虎永久在线免费观看| 最近中文字幕电影大全免费版 | 最新亚洲人成无码网站| 亚洲欧洲国产日韩精品| 亚洲AⅤ视频一区二区三区| 1000部拍拍拍18勿入免费凤凰福利 | 国产免费怕怕免费视频观看| 毛片免费在线观看| 精品女同一区二区三区免费播放| 亚洲视频在线观看免费| 亚洲精品国产福利一二区| 免费无码精品黄AV电影| 久9热免费精品视频在线观看| 美女黄频a美女大全免费皮| 亚洲AV无码乱码在线观看代蜜桃| 亚洲精品无码鲁网中文电影| 美女黄网站人色视频免费国产| 免费人妻无码不卡中文字幕系| 免费国产va视频永久在线观看| 亚洲国产成人精品久久| 亚洲国产精品第一区二区| 国产亚洲精品无码专区| 全黄a免费一级毛片人人爱| 在线中文高清资源免费观看| 99爱在线精品免费观看|