Completed
Push — master ( 0672dd...74c8db )
by John
33s
created

CommandGroupAuto(Position,Goal)   F

Complexity

Conditions 21

Size

Total Lines 81

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 81
rs 0
cc 21

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like org.usfirst.frc.team3695.robot.auto.CommandGroupAuto.CommandGroupAuto(Position,Goal) often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
package org.usfirst.frc.team3695.robot.auto;
2
3
import edu.wpi.first.wpilibj.DriverStation;
4
import org.usfirst.frc.team3695.robot.Constants;
5
import org.usfirst.frc.team3695.robot.Robot;
6
import org.usfirst.frc.team3695.robot.commands.*; // when the commands are ready, load each individually to decrease runtime
7
import org.usfirst.frc.team3695.robot.enumeration.Goal;
8
import org.usfirst.frc.team3695.robot.enumeration.Position;
9
10
import edu.wpi.first.wpilibj.command.CommandGroup;
11
12
/** the sequence of commands for autonomous */
13
public class CommandGroupAuto extends CommandGroup {
14
15
	//Stores the states of the switches and scale
16
	String gameData;
17
18
	public CommandGroupAuto(Position position, Goal goal) {
19
		//Get the state of the switches and scale for each round
20
		gameData = DriverStation.getInstance().getGameSpecificMessage();
21
22
		// make sure everything is in the right state/position up here
23
		Robot.SUB_CLAMP.closeArms();
24
		// EX: making sure flap is closed before auto starts
25
		switch (position) {
26
			case LEFT:
27
				switch (goal){
28
					case RUN_FOR_IT:
29
						addSequential(new CyborgCommandDriveUntilError(Position.FORWARD));
30
						break;
31
					case SWITCH:
32
						if (gameData.charAt(0) == 'L'){ //When the switch is on the left
33
							addParallel(new CyborgCommandDriveDistance(Constants.Autonomous.DIST_TO_SWITCH_FROM_SIDE));
34
							addSequential(new CyborgCommandGoToMid());
35
							addSequential(new CyborgCommandRotateDegrees(Constants.Autonomous.ROT_90_CLOCKWISE));
36
						} else { //When the switch is on the right
37
38
						}
39
						break;
40
					case ENEMY_SWITCH:
41
						break;
42
					case SCALE:
0 ignored issues
show
Bug introduced by
Your code has two case statements with the same code. Consider merging these statements to make the code more readable and easier to maintain.

case statements can be bundled like this:

switch (s) {
    case "A":
    case "B":
        doSomething();
    break;
}
Loading history...
43
						break;
44
					case BEST_OPTION:
0 ignored issues
show
Bug introduced by
Your code has two case statements with the same code. Consider merging these statements to make the code more readable and easier to maintain.

case statements can be bundled like this:

switch (s) {
    case "A":
    case "B":
        doSomething();
    break;
}
Loading history...
45
						break;
46
				}
47
				break;
48
49
			case CENTER:
50
				switch (goal){
51
					case RUN_FOR_IT:
52
						addSequential(new CyborgCommandDriveUntilError(Position.FORWARD));
53
						break;
54
					case SWITCH:
55
						//Raise the mast to midpoint and pass the portal to avoid collisions
56
						addParallel(new CyborgCommandGoToMid());
57
						addSequential(new CyborgCommandDriveDistance(Constants.Autonomous.DIST_PASS_PORTAL));
58
						if (gameData.charAt(0) == 'L'){ //When the switch is on the left
59
							addSequential(new CyborgCommandRotateDegrees(Constants.Autonomous.ROT_90_COUNTERCLOCKWISE));
60
							addSequential(new CyborgCommandDriveDistance(Constants.Autonomous.DIST_CENTER_LINE_SWITCH_ALIGN));
61
							addSequential(new CyborgCommandRotateDegrees(Constants.Autonomous.ROT_90_CLOCKWISE));
62
							addSequential(new CyborgCommandDriveDistance(Constants.Autonomous.DIST_WALL_TO_BLOCKS
63
																				+ Constants.Autonomous.DIST_BLOCKS_TO_SWITCH
64
																				- Constants.Autonomous.DIST_PASS_PORTAL));
65
66
						} else { //When the switch is on the right
67
							addSequential(new CyborgCommandRotateDegrees(Constants.Autonomous.ROT_90_CLOCKWISE));
68
							addSequential(new CyborgCommandDriveDistance(Constants.Autonomous.DIST_CENTER_LINE_SWITCH_ALIGN));
69
							addSequential(new CyborgCommandRotateDegrees(Constants.Autonomous.ROT_90_COUNTERCLOCKWISE));
70
							addSequential(new CyborgCommandDriveDistance(Constants.Autonomous.DIST_WALL_TO_BLOCKS
71
																				+ Constants.Autonomous.DIST_BLOCKS_TO_SWITCH
72
																				- Constants.Autonomous.DIST_PASS_PORTAL));
73
						}
74
						break;
75
					case ENEMY_SWITCH:
76
						break;
77
					case SCALE:
0 ignored issues
show
Bug introduced by
Your code has two case statements with the same code. Consider merging these statements to make the code more readable and easier to maintain.

case statements can be bundled like this:

switch (s) {
    case "A":
    case "B":
        doSomething();
    break;
}
Loading history...
78
						break;
79
					case BEST_OPTION:
0 ignored issues
show
Bug introduced by
Your code has two case statements with the same code. Consider merging these statements to make the code more readable and easier to maintain.

case statements can be bundled like this:

switch (s) {
    case "A":
    case "B":
        doSomething();
    break;
}
Loading history...
80
						break;
81
			}
82
				break;
83
				
84
			case RIGHT:
85
				switch (goal) {
86
					case RUN_FOR_IT:
87
						addSequential(new CyborgCommandDriveUntilError(Position.FORWARD));
88
						break;
89
					case SWITCH:
90
						break;
91
					case ENEMY_SWITCH:
0 ignored issues
show
Bug introduced by
Your code has two case statements with the same code. Consider merging these statements to make the code more readable and easier to maintain.

case statements can be bundled like this:

switch (s) {
    case "A":
    case "B":
        doSomething();
    break;
}
Loading history...
92
						break;
93
					case SCALE:
0 ignored issues
show
Bug introduced by
Your code has two case statements with the same code. Consider merging these statements to make the code more readable and easier to maintain.

case statements can be bundled like this:

switch (s) {
    case "A":
    case "B":
        doSomething();
    break;
}
Loading history...
94
						break;
95
					case BEST_OPTION:
0 ignored issues
show
Bug introduced by
Your code has two case statements with the same code. Consider merging these statements to make the code more readable and easier to maintain.

case statements can be bundled like this:

switch (s) {
    case "A":
    case "B":
        doSomething();
    break;
}
Loading history...
96
						break;
97
				}
98
			break;
99
		}	
100
	}
101
}
102