Package: VDMSeq

VDMSeq

nameinstructionbranchcomplexitylinemethod
VDMSeq()
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: 27 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
toStr(Iterator)
M: 18 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
toString()
M: 81 C: 0
0%
M: 14 C: 0
0%
M: 8 C: 0
0%
M: 25 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.ArrayList;
25: import java.util.Iterator;
26:
27: @SuppressWarnings("rawtypes")
28: public class VDMSeq extends ArrayList implements ValueType
29: {
30:         private static final long serialVersionUID = 5083307947808060044L;
31:
32:         @SuppressWarnings("unchecked")
33:         public VDMSeq copy()
34:         {
35:                 VDMSeq seqClone = new VDMSeq();
36:
37:•                for (Object element : this)
38:                 {
39:•                        if (element instanceof ValueType)
40:                         {
41:                                 element = ((ValueType) element).copy();
42:                         }
43:
44:                         seqClone.add(element);
45:                 }
46:
47:                 return seqClone;
48:         }
49:
50:         @Override
51:         public String toString()
52:         {
53:                 Iterator iterator = this.iterator();
54:
55:•                if (!iterator.hasNext())
56:                 {
57:                         return "[]";
58:                 }
59:
60:                 boolean seqOfChar = true;
61:
62:•                while (iterator.hasNext())
63:                 {
64:                         Object element = iterator.next();
65:•                        if (!(element instanceof Character))
66:                         {
67:                                 seqOfChar = false;
68:                                 break;
69:                         }
70:                 }
71:
72:•                if (seqOfChar)
73:                 {
74:                         return toStr(this.iterator());
75:
76:                 } else
77:                 {
78:                         iterator = this.iterator();
79:
80:                         StringBuilder sb = new StringBuilder();
81:
82:                         sb.append('[');
83:
84:                         Object element = iterator.next();
85:•                        sb.append(element == this ? "(this Collection)"
86:                                         : Utils.toString(element));
87:
88:•                        while (iterator.hasNext())
89:                         {
90:                                 element = iterator.next();
91:                                 sb.append(", ");
92:•                                sb.append(element == this ? "(this Collection)"
93:                                                 : Utils.toString(element));
94:                         }
95:
96:                         sb.append(']');
97:
98:                         return sb.toString();
99:                 }
100:         }
101:
102:         public static String toStr(Iterator iterator) {
103:                 StringBuilder sb = new StringBuilder();
104:
105:•                while (iterator.hasNext())
106:                 {
107:                         Object element = iterator.next();
108:
109:                         // Do not use Utils.toString(..) to avoid single quotes
110:                         // around the chars
111:                         sb.append(element);
112:                 }
113:
114:                 return sb.toString();
115:         }
116: }