-
Notifications
You must be signed in to change notification settings - Fork 0
/
CodeBlock.java
153 lines (135 loc) · 4.27 KB
/
CodeBlock.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package OrderOfComplexityCalculator;
/**
* Ritesh Sunil Chavan
*/
/**
* This class stores the information of a certain block of code
*/
public class CodeBlock {
/**
* This is an array of block types, it contains the keywords for the name of the block
*/
public static String[] BLOCK_TYPES={"def","for","while","if","else","elif"};
/**
* These variable store the index at which they are stored in the block type array
*/
public static final int DEF=0;
public static final int FOR=1;
public static final int WHILE=2;
public static final int IF=3;
public static final int ELIF=4;
public static final int ELSE=5;
private String name;
private Complexity blockComplexity;
private Complexity highestSubComplexity;
private String loopVariable;
private String type;
/**
*
* @param name name type of the code block
* @param blockComplexity block complexity of the code block
* @param highestSubComplexity nested block complexity of the code block
* @param loopVariable variable name in while loop
* @param type type of the code block
*/
public CodeBlock(String name, Complexity blockComplexity, Complexity highestSubComplexity, String loopVariable, String type) {
this.name = name;
this.blockComplexity = blockComplexity;
this.highestSubComplexity = highestSubComplexity;
this.loopVariable = loopVariable;
this.type = type;
}
/**
*
* @param name name type of the code block
* @param blockComplexity block complexity of the code block
* @param highestSubComplexity nested block complexity of the code block
* @param type type of the code block
*/
public CodeBlock(String name, Complexity blockComplexity, Complexity highestSubComplexity, String type) {
this.name = name;
this.blockComplexity = blockComplexity;
this.highestSubComplexity = highestSubComplexity;
this.type = type;
}
/**
* Getter method for block name
* @return name of block
*/
public String getName() {
return name;
}
/**
* Setter method for name
* @param name name of the block
*/
public void setName(String name) {
this.name = name;
}
/**
* Getter method for block complexity
* @return block complexity of the block
*/
public Complexity getBlockComplexity() {
return blockComplexity;
}
/**
* Setter method for block complexity
* @param blockComplexity block complexity of the block
*/
public void setBlockComplexity(Complexity blockComplexity) {
this.blockComplexity = blockComplexity;
}
/**
* Getter method for the highest complexity of the block
* @return highest complexity of the block
*/
public Complexity getHighestSubComplexity() {
return highestSubComplexity;
}
/**
* Setter method for the highest complexity of the block
* @param highestSubComplexity highest complexity of the block
*/
public void setHighestSubComplexity(Complexity highestSubComplexity) {
this.highestSubComplexity = highestSubComplexity;
}
/**
* Getter method for the while loop variable
* @return loop variable of the while loop
*/
public String getLoopVariable() {
return loopVariable;
}
/**
* Setter method for the while loop variable
* @param loopVariable loop variable of the while loop
*/
public void setLoopVariable(String loopVariable) {
this.loopVariable = loopVariable;
}
/**
* Getter method for the type of the block
* @return type of block
*/
public String getType() {
return type;
}
/**
* Setter method for the type of the block
* @param type type of block
*/
public void setType(String type) {
this.type = type;
}
/**
* toString method for the code block
* @return Neatly formatted block and highest complexity
*/
public String toString() {
String a = " BLOCK "+name+":";
String b = "block complexity = "+blockComplexity.toString();
String c = "highest sub-complexity = "+highestSubComplexity.toString();
return String.format("%-19s%-34s%s",a,b,c);
}
}