forked from FASP-QAT/fasp-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBadCode.java
More file actions
72 lines (64 loc) · 1.89 KB
/
BadCode.java
File metadata and controls
72 lines (64 loc) · 1.89 KB
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
package cc.altius.FASP;
public class BadCode {
private int a, b, c, d, e, f, g, h; // Too many fields
// Method with too many parameters
public void doSomething(int param1, int param2, int param3, int param4, int param5) {
// Nested control flow beyond threshold
if (param1 > 0) {
if (param2 > 0) {
if (param3 > 0) {
if (param4 > 0) {
if (param5 > 0) {
System.out.println("Too deep!");
}
}
}
}
}
}
// Complex method with high cyclomatic complexity
public int calculateSomething(int x) {
int result = 0;
// Multiple return statements
if (x < 0) return -1;
if (x == 0) return 0;
if (x > 100) return 100;
if (x % 2 == 0) return x * 2;
if (x % 3 == 0) return x * 3;
// Complex logic with many branches
for (int i = 0; i < x; i++) {
if (i % 2 == 0) {
result += i;
} else if (i % 3 == 0) {
result += i * 2;
} else if (i % 5 == 0) {
result += i * 3;
} else {
result += 1;
}
}
return result;
}
// Duplicate code block 1
public void duplicateMethod1() {
int sum = 0;
for (int i = 0; i < 100; i++) {
sum += i;
System.out.println("Processing: " + i);
if (i % 2 == 0) {
sum += 5;
}
}
}
// Duplicate code block 2
public void duplicateMethod2() {
int sum = 0;
for (int i = 0; i < 100; i++) {
sum += i;
System.out.println("Processing: " + i);
if (i % 2 == 0) {
sum += 5;
}
}
}
}