Package: Permutor

Permutor

nameinstructionbranchcomplexitylinemethod
Permutor(int[])
M: 2 C: 35
95%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 0 C: 11
100%
M: 0 C: 1
100%
hasNext()
M: 0 C: 7
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
next()
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%
permute()
M: 0 C: 54
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 10
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: *
3: *        Copyright (C) 2008, 2009 Fujitsu Services Ltd.
4: *
5: *        Author: Nick Battle
6: *
7: *        This file is part of VDMJ.
8: *
9: *        VDMJ is free software: you can redistribute it and/or modify
10: *        it under the terms of the GNU General Public License as published by
11: *        the Free Software Foundation, either version 3 of the License, or
12: *        (at your option) any later version.
13: *
14: *        VDMJ is distributed in the hope that it will be useful,
15: *        but WITHOUT ANY WARRANTY; without even the implied warranty of
16: *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: *        GNU General Public License for more details.
18: *
19: *        You should have received a copy of the GNU General Public License
20: *        along with VDMJ. If not, see <http://www.gnu.org/licenses/>.
21: *
22: ******************************************************************************/
23:
24: package org.overture.codegen.runtime.traces;
25:
26: public class Permutor
27: {
28:         private final int[] limit;
29:         private final int count;
30:         private final int[] current;
31:
32:         private boolean done = false;
33:
34:         public Permutor(int[] limits)
35:         {
36:                 this.limit = limits;
37:                 this.count = limits.length;
38:                 this.current = new int[count];
39:                 this.done = true;
40:
41:•                for (int i = 0; i < count; i++)
42:                 {
43:•                        if (limits[i] > 0)
44:                         {
45:                                 this.done = false;
46:                                 break;
47:                         }
48:                 }
49:         }
50:
51:         private int[] permute()
52:         {
53:                 int[] old = new int[count];
54:                 System.arraycopy(current, 0, old, 0, count);
55:
56:•                for (int i = 0; i < count; i++)
57:                 {
58:•                        if (++current[i] < limit[i])
59:                         {
60:                                 done = false;
61:                                 break;
62:                         }
63:
64:                         current[i] = 0;
65:
66:•                        if (i == count - 1)
67:                         {
68:                                 done = true;
69:                         }
70:                 }
71:
72:                 return old;
73:         }
74:
75:         public int[] next()
76:         {
77:                 return permute();
78:         }
79:
80:         public boolean hasNext()
81:         {
82:•                return !done;
83:         }
84: }