puzhibing
2023-11-25 53e7558400dcacecdce70e39ebfe1727740f9296
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package com.dsh.course.util;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
 
 
public class StrUtils {
    /**
     * 把逗号分隔的字符串转换字符串数组
     * Convert comma-separated string to string array.
     *
     * @param str
     * @return
     */
    public static String[] splitStr2StrArr(String str, String split) {
        if (str != null && !str.equals("")) {
            return str.split(split);
        }
        return null;
    }
 
 
    /**
     * 把逗号分隔字符串转换List的Long
     *
     * @param str
     * @return
     */
    public static List<Long> splitStr2LongArr(String str) {
        String[] strings = splitStr2StrArr(str, ",");
        if (strings == null) return null;
 
        List<Long> result = new ArrayList<>();
        for (String string : strings) {
            result.add(Long.parseLong(string));
        }
 
        return result;
    }
 
    /**
     * 把逗号分隔字符串转换List的Long
     *
     * @param str
     * @return
     */
    public static List<Long> splitStr2LongArr(String str, String split) {
        String[] strings = splitStr2StrArr(str, split);
        if (strings == null) return null;
 
        List<Long> result = new ArrayList<>();
        for (String string : strings) {
            result.add(Long.parseLong(string));
        }
 
        return result;
    }
 
    public static String getRandomString(int length) {
        String str = "0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(10);
            sb.append(str.charAt(number));
        }
        return sb.toString();
 
    }
 
    public static String getComplexRandomString(int length) {
        String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(62);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }
 
    public static String getClassCodeString(int length) {
        String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(36);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }
 
    public static String convertPropertiesToHtml(String properties) {
        //1:容量:6:32GB_4:样式:12:塑料壳
        StringBuilder sBuilder = new StringBuilder();
        String[] propArr = properties.split("_");
        for (String props : propArr) {
            String[] valueArr = props.split(":");
            sBuilder.append(valueArr[1]).append(":").append(valueArr[3]).append("<br>");
        }
        return sBuilder.toString();
    }
 
    public static List<Integer> dealStrToList(String str) {
        List<Integer> list = new ArrayList<>();
        if (null == str || str == "" || str.isEmpty()) {
            return list;
        }
        String[] strArray = str.split(";");
        for (String numStr : strArray) {
            switch (numStr) {
                case "周一":
                    list.add(1);
                    break;
                case "周二":
                    list.add(2);
                    break;
                case "周三":
                    list.add(3);
                    break;
                case "周四":
                    list.add(4);
                    break;
                case "周五":
                    list.add(5);
                    break;
                case "周六":
                    list.add(6);
                    break;
                case "周日":
                    list.add(7);
                    break;
 
            }
 
        }
        return list;
    }
 
}