Mercurial > hg > Members > shoshi > TreeCMSv2
annotate src/treecms/tree/util/NodeAttributesImpl.java @ 20:084de6909451
commit
author | shoshi |
---|---|
date | Wed, 01 Jun 2011 15:35:50 +0900 |
parents | 168deb591f21 |
children |
rev | line source |
---|---|
16 | 1 package treecms.tree.util; |
14
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
2 |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
3 import java.nio.ByteBuffer; |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
4 import java.util.Collections; |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
5 import java.util.Map; |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
6 import java.util.Set; |
20 | 7 import java.util.concurrent.ConcurrentHashMap; |
16 | 8 import treecms.api.NodeAttributes; |
9 | |
14
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
10 public class NodeAttributesImpl implements NodeAttributes |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
11 { |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
12 private Map<ByteBuffer,ByteBuffer> m_attrs; |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
13 |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
14 public NodeAttributesImpl() |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
15 { |
20 | 16 m_attrs = new ConcurrentHashMap<ByteBuffer,ByteBuffer>(); |
14
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
17 } |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
18 |
17 | 19 public NodeAttributesImpl(Map<ByteBuffer,ByteBuffer> _map) |
20 { | |
21 this(); | |
22 m_attrs.putAll(_map); | |
23 } | |
24 | |
14
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
25 public NodeAttributesImpl(NodeAttributesImpl _attrs) |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
26 { |
17 | 27 this(); |
14
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
28 m_attrs.putAll(_attrs.m_attrs); |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
29 } |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
30 |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
31 @Override |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
32 public Set<ByteBuffer> getKeySet() |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
33 { |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
34 return m_attrs.keySet(); |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
35 } |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
36 |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
37 @Override |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
38 public void put(ByteBuffer _name, ByteBuffer _value) |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
39 { |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
40 m_attrs.put(_name,_value); |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
41 } |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
42 |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
43 @Override |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
44 public void putAll(NodeAttributes _attrs) |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
45 { |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
46 m_attrs.putAll(_attrs.asMap()); |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
47 } |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
48 |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
49 @Override |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
50 public Map<ByteBuffer,ByteBuffer> asMap() |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
51 { |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
52 return Collections.unmodifiableMap(m_attrs); |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
53 } |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
54 |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
55 @Override |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
56 public ByteBuffer get(ByteBuffer _name) |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
57 { |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
58 return m_attrs.get(_name); |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
59 } |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
60 |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
61 @Override |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
62 public NodeAttributes getAll() |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
63 { |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
64 return this; |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
65 } |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
66 |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
67 @Override |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
68 public void remove(ByteBuffer _name) |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
69 { |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
70 m_attrs.remove(_name); |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
71 } |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
72 |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
73 @Override |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
74 public void removeAll(Set<ByteBuffer> _keySet) |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
75 { |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
76 for(ByteBuffer _key : _keySet){ |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
77 remove(_key); |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
78 } |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
79 } |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
80 |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
81 @Override |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
82 public void clearAttributes() |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
83 { |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
84 m_attrs.clear(); |
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
85 } |
17 | 86 |
87 @Override | |
88 public boolean equals(Object _o) | |
89 { | |
90 if(_o instanceof NodeAttributes || _o == null){ | |
91 return false; | |
92 } | |
93 | |
94 NodeAttributes attr = (NodeAttributes)_o; | |
95 Map<ByteBuffer,ByteBuffer> map = attr.asMap(); | |
96 return m_attrs.equals(map); | |
97 } | |
98 | |
99 @Override | |
100 public int hashCode() | |
101 { | |
102 return m_attrs.hashCode(); | |
103 } | |
14
8bf59f161b23
separete Node methods to NodeContext , NodeAttribute , NodeChildren
misaka
parents:
diff
changeset
|
104 } |