1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.io.vamsas; |
22 |
|
|
23 |
|
import java.util.IdentityHashMap; |
24 |
|
import java.util.Iterator; |
25 |
|
import java.util.Map; |
26 |
|
|
27 |
|
import jalview.log.JLoggerLog4j; |
28 |
|
|
|
|
| 0% |
Uncovered Elements: 77 (77) |
Complexity: 21 |
Complexity Density: 0.51 |
|
29 |
|
public class DatastoreRegistry implements AutoCloseable |
30 |
|
{ |
31 |
|
protected static JLoggerLog4j log = JLoggerLog4j |
32 |
|
.getLogger(DatastoreRegistry.class); |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
IdentityHashMap dsObjReg; |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
IdentityHashMap dsItemReg; |
45 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
46 |
0 |
public DatastoreRegistry()... |
47 |
|
{ |
48 |
0 |
dsObjReg = new IdentityHashMap(); |
49 |
0 |
dsItemReg = new IdentityHashMap(); |
50 |
|
} |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
@param |
55 |
|
@return |
56 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
57 |
0 |
public boolean isInvolvedInDsitem(Object obj)... |
58 |
|
{ |
59 |
0 |
return (obj instanceof DatastoreItem) ? dsItemReg.containsKey(obj) |
60 |
|
: dsObjReg.containsKey(obj); |
61 |
|
} |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
@param |
66 |
|
@return |
67 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
68 |
0 |
public DatastoreItem getDatastoreItemFor(Object obj)... |
69 |
|
{ |
70 |
0 |
if (obj instanceof DatastoreItem) |
71 |
|
{ |
72 |
0 |
log.debug("Returning DatastoreItem self reference."); |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
0 |
return (DatastoreItem) obj; |
78 |
|
} |
79 |
0 |
return (DatastoreItem) dsObjReg.get(obj); |
80 |
|
} |
81 |
|
|
|
|
| 0% |
Uncovered Elements: 30 (30) |
Complexity: 8 |
Complexity Density: 0.5 |
|
82 |
0 |
synchronized void registerDsObj(DatastoreItem dsitem)... |
83 |
|
{ |
84 |
0 |
Object[] dsregitem = (Object[]) dsItemReg.get(dsitem); |
85 |
0 |
if (dsregitem == null) |
86 |
|
{ |
87 |
|
|
88 |
0 |
dsregitem = new Object[] { dsitem.jvobj, dsitem.vobj }; |
89 |
0 |
dsItemReg.put(dsitem, dsregitem); |
90 |
0 |
dsObjReg.put(dsitem.jvobj, dsitem); |
91 |
0 |
dsObjReg.put(dsitem.vobj, dsitem); |
92 |
|
} |
93 |
|
else |
94 |
|
{ |
95 |
|
|
96 |
|
|
97 |
0 |
if (dsitem.jvobj != dsregitem[0]) |
98 |
|
{ |
99 |
|
|
100 |
0 |
if (dsregitem[0] != null) |
101 |
|
{ |
102 |
0 |
dsObjReg.remove(dsregitem[0]); |
103 |
|
} |
104 |
0 |
if ((dsregitem[0] = dsitem.jvobj) != null) |
105 |
|
{ |
106 |
0 |
dsObjReg.put(dsregitem[0], dsitem); |
107 |
|
} |
108 |
|
} |
109 |
|
|
110 |
0 |
if (dsitem.vobj != dsregitem[1]) |
111 |
|
{ |
112 |
|
|
113 |
0 |
if (dsregitem[1] != null) |
114 |
|
{ |
115 |
0 |
dsObjReg.remove(dsregitem[1]); |
116 |
|
} |
117 |
0 |
if ((dsregitem[1] = dsitem.vobj) != null) |
118 |
|
{ |
119 |
0 |
dsObjReg.put(dsregitem[1], dsitem); |
120 |
|
} |
121 |
|
} |
122 |
|
} |
123 |
|
} |
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
@param |
129 |
|
@return |
130 |
|
|
131 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
132 |
0 |
public synchronized Object[] removeDsObj(DatastoreItem dsitem)... |
133 |
|
{ |
134 |
0 |
Object[] dsregitem = null; |
135 |
|
|
136 |
|
{ |
137 |
|
|
138 |
|
{ |
139 |
0 |
dsregitem = (Object[]) dsItemReg.remove(dsitem); |
140 |
0 |
if (dsregitem != null) |
141 |
|
{ |
142 |
|
|
143 |
0 |
if (dsregitem[0] != null) |
144 |
|
{ |
145 |
0 |
dsObjReg.remove(dsregitem[0]); |
146 |
|
} |
147 |
0 |
if (dsregitem[1] != null) |
148 |
|
{ |
149 |
0 |
dsObjReg.remove(dsregitem[1]); |
150 |
|
} |
151 |
|
} |
152 |
|
} |
153 |
|
} |
154 |
0 |
return dsregitem; |
155 |
|
} |
156 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 4 |
Complexity Density: 0.4 |
|
157 |
0 |
@Override... |
158 |
|
public void close() |
159 |
|
{ |
160 |
0 |
if (dsObjReg != null) |
161 |
|
{ |
162 |
0 |
Iterator items = dsObjReg.entrySet().iterator(); |
163 |
|
|
164 |
0 |
while (items.hasNext()) |
165 |
|
{ |
166 |
0 |
Object[] vals = (Object[]) ((Map.Entry) items.next()).getValue(); |
167 |
0 |
vals[0] = null; |
168 |
0 |
vals[1] = null; |
169 |
|
} |
170 |
0 |
items = null; |
171 |
0 |
dsObjReg.clear(); |
172 |
|
} |
173 |
0 |
if (dsItemReg != null) |
174 |
|
{ |
175 |
0 |
dsItemReg.clear(); |
176 |
|
} |
177 |
|
|
178 |
|
} |
179 |
|
} |