peternameyakj
2024-08-29 7c1a152e3a978b14114f0d28275cbcc295357d51
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
package util;
 
import java.io.Serializable;
 
public class IgnoreCaseString implements Comparable<IgnoreCaseString>, Serializable {
    /**
     * Member Description
     */
    private static final long serialVersionUID = -247637491060007575L;
 
    public static final IgnoreCaseString EMPTY = IgnoreCaseString.valueOf("");
 
    /**
     * origStr string对象
     */
    private final String origStr;
 
    /**
     * lowerCaseStr string对象
     */
    private final String lowerCaseStr;
 
    // 需要抛出异常, Assert.assertEquals("d", IgnoreCaseString.valueOf(null).toString());
    public static IgnoreCaseString valueOf(String str) {
        if (str == null) {
            return null;
        }
        return new IgnoreCaseString(str);
    }
 
    /**
     * 
     * @param value
     *            String参数
     */
    private IgnoreCaseString(String value) {
        if (value == null) {
            throw new NullPointerException("value不能为空");
        }
 
        origStr = value;
        lowerCaseStr = value.toLowerCase();
    }
 
    public char charAt(int i) {
        return origStr.charAt(i);
    }
 
    public int compareTo(IgnoreCaseString o) {
        if (o == null) {
            return 1;
        }
 
        if (this == o) {
            return 0;
        }
 
        return lowerCaseStr.compareTo(o.lowerCaseStr);
    }
 
    public boolean contains(IgnoreCaseString other) {
        if (other == null) {
            return false;
        }
 
        return lowerCaseStr.contains(other.lowerCaseStr);
    }
 
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
 
        if (obj instanceof IgnoreCaseString) {
            IgnoreCaseString other = (IgnoreCaseString) obj;
            return lowerCaseStr.equals(other.lowerCaseStr);
        }
 
        return false;
    }
 
    /**
     * @return byte数组 origStr转换成byte数组
     */
    public byte[] getBytes() {
        return origStr.getBytes();
    }
 
    @Override
    public int hashCode() {
        final int PRIME = 31;
        int result = 1;
        result = PRIME * result + ((lowerCaseStr == null) ? 0 : lowerCaseStr.hashCode());
        return result;
    }
 
    public int length() {
        return origStr.length();
    }
 
    // TODO ztt
    // null的情况是否应该存在
    public String[] split(String regex) {
        if (origStr == null) {
            return null;
        }
 
        return origStr.split(regex);
    }
 
    public char[] toCharArray() {
        return origStr.toCharArray();
    }
 
    public String toLowerCase() {
        return origStr.toLowerCase();
    }
 
    @Override
    public String toString() {
        return origStr;
    }
 
    public String toUpperCase() {
        return origStr.toUpperCase();
    }
 
    public String trim() {
        return origStr.trim();
    }
 
}