1 package org.apache.helix.store.zk;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Collections;
23 import java.util.HashSet;
24 import java.util.List;
25 import java.util.Set;
26
27 import org.apache.zookeeper.data.Stat;
28
29 public class ZNode
30 {
31
32
33 public static final Stat ZERO_STAT = new Stat();
34
35 final String _zkPath;
36 private Stat _stat;
37 Object _data;
38 Set<String> _childSet;
39
40 public ZNode(String zkPath, Object data, Stat stat)
41 {
42 _zkPath = zkPath;
43 _childSet = Collections.<String>emptySet();
44 _data = data;
45 _stat = stat;
46 }
47
48 public void removeChild(String child)
49 {
50 if (_childSet != Collections.<String>emptySet())
51 {
52 _childSet.remove(child);
53 }
54 }
55
56 public void addChild(String child)
57 {
58 if (_childSet == Collections.<String>emptySet())
59 {
60 _childSet = new HashSet<String>();
61 }
62
63 _childSet.add(child);
64 }
65
66 public void addChildren(List<String> children)
67 {
68 if (children != null && !children.isEmpty())
69 {
70 if (_childSet == Collections.<String>emptySet())
71 {
72 _childSet = new HashSet<String>();
73 }
74
75 _childSet.addAll(children);
76 }
77 }
78
79 public boolean hasChild(String child)
80 {
81 return _childSet.contains(child);
82 }
83
84 public Set<String> getChildSet()
85 {
86 return _childSet;
87 }
88
89 public void setData(Object data)
90 {
91
92 _data= data;
93 }
94
95 public Object getData()
96 {
97 return _data;
98 }
99
100 public void setStat(Stat stat)
101 {
102 _stat = stat;
103 }
104
105 public Stat getStat()
106 {
107 return _stat;
108 }
109
110 public void setChildSet(List<String> childNames)
111 {
112 if (childNames != null && !childNames.isEmpty())
113 {
114 if (_childSet == Collections.<String>emptySet())
115 {
116 _childSet = new HashSet<String>();
117 }
118
119 _childSet.clear();
120 _childSet.addAll(childNames);
121 }
122 }
123
124 @Override
125 public String toString()
126 {
127 return _zkPath + ", " + _data + ", " + _childSet + ", " + _stat;
128 }
129 }