comparison src/treecms/tree/util/NodeChildrenImpl.java @ 22:fa784faafc78

commit
author shoshi
date Tue, 07 Jun 2011 16:42:49 +0900
parents f3150b37f9be
children 77a894c0b919
comparison
equal deleted inserted replaced
21:f3150b37f9be 22:fa784faafc78
4 import java.util.HashMap; 4 import java.util.HashMap;
5 import java.util.List; 5 import java.util.List;
6 import java.util.Map; 6 import java.util.Map;
7 import java.util.Set; 7 import java.util.Set;
8 import java.util.concurrent.ConcurrentHashMap; 8 import java.util.concurrent.ConcurrentHashMap;
9 import java.util.concurrent.ConcurrentMap;
9 import java.util.concurrent.CopyOnWriteArrayList; 10 import java.util.concurrent.CopyOnWriteArrayList;
11
12 import treecms.api.NodeAttributes;
10 import treecms.api.NodeChildren; 13 import treecms.api.NodeChildren;
11 import treecms.api.NodeContext; 14 import treecms.api.NodeContext;
12 import treecms.api.NodeID; 15 import treecms.api.NodeID;
13 16
14 public class NodeChildrenImpl<T extends NodeContext & NodeChildren<T>> implements NodeChildren<T> 17 public class NodeChildrenImpl<T extends NodeContext & NodeAttributes & NodeChildren<T>> implements NodeChildren<T>
15 { 18 {
16 private final Map<String,T> m_map; 19 private final ConcurrentMap<String,T> m_map;
17 private final List<T> m_list; 20 private final List<T> m_list;
18 private final List<T> m_readOnlyList; 21 private final List<T> m_readOnlyList;
19 22
20 public NodeChildrenImpl() 23 public NodeChildrenImpl()
21 { 24 {
52 { 55 {
53 return m_readOnlyList; 56 return m_readOnlyList;
54 } 57 }
55 58
56 @Override 59 @Override
60 public T create(NodeAttributes _attr)
61 {
62 throw new UnsupportedOperationException();
63 }
64
57 public synchronized T replace(T _node) 65 public synchronized T replace(T _node)
58 { 66 {
59 String fid = _node.getID().getFamilyID(); 67 String fid = _node.getID().getFamilyID();
60 68
61 T old = m_map.get(fid); 69 T old = m_map.get(fid);
77 throw new IllegalStateException("FamilyID is found on the map but not found on the list"); 85 throw new IllegalStateException("FamilyID is found on the map but not found on the list");
78 } 86 }
79 return null; 87 return null;
80 } 88 }
81 89
82 @Override
83 public synchronized boolean add(T _n) 90 public synchronized boolean add(T _n)
84 { 91 {
85 if(!m_map.containsKey(_n.getID().getFamilyID())){ 92 if(!m_map.containsKey(_n.getID().getFamilyID())){
86 m_map.put(_n.getID().getFamilyID(),_n); 93 m_map.put(_n.getID().getFamilyID(),_n);
87 return m_list.add(_n); 94 return m_list.add(_n);
88 } 95 }
89 return false; 96 return false;
90 } 97 }
91 98
92 @Override
93 public synchronized boolean addAll(NodeChildren<T> _list) 99 public synchronized boolean addAll(NodeChildren<T> _list)
94 { 100 {
95 if(_list == this){ 101 if(_list == this){
96 return false; 102 return false;
97 } 103 }