hefeixia
2021-02-18 5b8c95c760840f09910730943b21391e47187315
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
package chat.module.friendcircle;
 
import java.util.HashSet;
import java.util.Set;
 
import frame.util.ContentBuilder;
 
public class LabeList {
 
    public static String Spliter = "#";
    private Set<String> items;
    private String value;
    
    
    public LabeList() {
        items = new HashSet<String>();
        value = null;
    }
    
    public void addone(String label) {
        if (label == null) {
            return;
        }
        
        items.add(label);
        value = null;
    }
 
    public synchronized String getValue() {
        if (value == null) {
            value = createValue();
        }
        
        return value;
    }
 
    private String createValue() {
        if (items.isEmpty()) {
            return "";
        }
        
        ContentBuilder builder = new ContentBuilder(Spliter);
        
        for (String label: items) {
            builder.append(label);
        }
        
        return Spliter + builder.toString();
    }
 
    public void load(String value) {
        if (value == null) {
            return;
        }
        
        value = value.trim();
        
        String[] segments = value.split("#");
        
        for (String segment: segments) {
            segment = segment.trim();
            
            if ("".equals(segment)) {
                continue;
            }
            
            items.add(segment);
        }
    }
}