Package: VDMMap

VDMMap

nameinstructionbranchcomplexitylinemethod
VDMMap()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
copy()
M: 43 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
toString()
M: 72 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 20 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * VDM Code Generator Runtime
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.codegen.runtime;
23:
24: import java.util.Iterator;
25: import java.util.LinkedHashMap;
26: import java.util.Map;
27: import java.util.Set;
28:
29: @SuppressWarnings("rawtypes")
30: public class VDMMap extends LinkedHashMap implements ValueType
31: {
32:         private static final long serialVersionUID = -3288711341768577550L;
33:
34:         @SuppressWarnings("unchecked")
35:         public VDMMap copy()
36:         {
37:                 VDMMap mapClone = new VDMMap();
38:
39:                 Iterator iterator = this.entrySet().iterator();
40:
41:•                while (iterator.hasNext())
42:                 {
43:                         Map.Entry entry = (Map.Entry) iterator.next();
44:
45:                         Object key = entry.getKey();
46:                         Object value = entry.getValue();
47:
48:•                        if (key instanceof ValueType)
49:                         {
50:                                 key = ((ValueType) key).copy();
51:                         }
52:
53:•                        if (value instanceof ValueType)
54:                         {
55:                                 value = ((ValueType) value).copy();
56:                         }
57:
58:                         mapClone.put(key, value);
59:                 }
60:
61:                 return mapClone;
62:         }
63:
64:         @Override
65:         public String toString()
66:         {
67:                 Set entries = this.entrySet();
68:                 Iterator iterator = entries.iterator();
69:
70:•                if (!iterator.hasNext())
71:                 {
72:                         return "{|->}";
73:                 }
74:
75:                 StringBuilder sb = new StringBuilder();
76:                 sb.append('{');
77:
78:                 for (;;)
79:                 {
80:                         Object next = iterator.next();
81:
82:•                        if (!(next instanceof Map.Entry))
83:                         {
84:                                 continue;
85:                         }
86:
87:                         Map.Entry entry = (Map.Entry) next;
88:
89:                         Object key = entry.getKey();
90:                         Object value = entry.getValue();
91:
92:•                        sb.append(key == this ? "(this Collection)" : Utils.toString(key));
93:                         sb.append(" |-> ");
94:•                        sb.append(value == this ? "(this Collection)"
95:                                         : Utils.toString(value));
96:
97:•                        if (!iterator.hasNext())
98:                         {
99:                                 return sb.append('}').toString();
100:                         }
101:
102:                         sb.append(", ");
103:                 }
104:         }
105: }