1111 * Given a command as a body and a condition to check, this command will
1212 * repeatedly check the condition, and execute the command if it is met.
1313 *
14- * The requirements of the body command are removed, and transferred over
15- * to this command at construction. This allows CommandGroups and cancelling
16- * to work properly.
14+ * The requirements of the body command are removed, and transferred over to
15+ * this command at construction. This allows CommandGroups and canceling to work
16+ * properly.
1717 *
18- * If this command is interrupted (cancelled or booted by another command),
19- * then the body command will be cancelled. If the body command is cancelled,
20- * then it will start again on the next iteration.
18+ * If this command is interrupted (cancelled or booted by another command), then
19+ * the body command will be cancelled. If the body command is cancelled, then it
20+ * will start again on the next iteration.
2121 *
2222 * Because HyperLib is currently in pre-release, these semantics may change
2323 * based on what we consider "reasonable defaults".
@@ -29,18 +29,20 @@ public class WhileCommand extends Command {
2929
3030 private final BooleanSupplier m_condition ;
3131 private final Command m_body ;
32-
32+
3333 private boolean m_hasFinished ;
34-
34+
3535 /**
3636 * Construct a new WhileCommand from a condition and a body.
3737 *
3838 * After construction, the body command's requirements are moved to this
39- * command. That means you should not re-use the body command after
40- * passing it to this method. Instead, create a new one.
39+ * command. That means you should not re-use the body command after passing
40+ * it to this method. Instead, create a new one.
4141 *
42- * @param condition The condition to check
43- * @param body The command to run as the body
42+ * @param condition
43+ * The condition to check
44+ * @param body
45+ * The command to run as the body
4446 */
4547 public WhileCommand (BooleanSupplier condition , Command body ) {
4648 if (body == null ) {
@@ -49,23 +51,26 @@ public WhileCommand(BooleanSupplier condition, Command body) {
4951 if (condition == null ) {
5052 throw new NullPointerException ("condition == null" );
5153 }
52-
54+
5355 m_condition = condition ;
5456 m_body = body ;
5557 transferRequirements ();
5658 }
57-
59+
5860 /**
59- * Construct a new WhileCommand from a condition and a body, with the
60- * given name.
61+ * Construct a new WhileCommand from a condition and a body, with the given
62+ * name.
6163 *
6264 * After construction, the body command's requirements are moved to this
63- * command. That means you should not re-use the body command after
64- * passing it to this method. Instead, create a new one.
65+ * command. That means you should not re-use the body command after passing
66+ * it to this method. Instead, create a new one.
6567 *
66- * @param name The name of the command
67- * @param condition The condition to check
68- * @param body The command to run as the body
68+ * @param name
69+ * The name of the command
70+ * @param condition
71+ * The condition to check
72+ * @param body
73+ * The command to run as the body
6974 */
7075 public WhileCommand (String name , BooleanSupplier condition , Command body ) {
7176 super (name );
@@ -75,68 +80,68 @@ public WhileCommand(String name, BooleanSupplier condition, Command body) {
7580 if (condition == null ) {
7681 throw new NullPointerException ("condition == null" );
7782 }
78-
83+
7984 m_condition = condition ;
8085 m_body = body ;
8186 transferRequirements ();
8287 }
83-
88+
8489 @ SuppressWarnings ("unchecked" )
8590 private void transferRequirements () {
8691 for (Object req : Collections .list (m_body .getRequirements ())) {
8792 requires ((Subsystem ) req );
8893 }
89-
94+
9095 m_body .clearRequirements ();
9196 }
92-
97+
9398 private void checkCondition () {
9499 m_hasFinished = !m_condition .getAsBoolean ();
95100 }
96-
101+
97102 /**
98103 * Reset the state as if this command has not yet been run.
99104 *
100105 * We don't call checkCondition() here, because the condition is already
101106 * checked in execute(), and it makes sense semantically to check the
102- * condition once per iteration. This might matter if the condition
103- * passed in has side effects.
107+ * condition once per iteration. This might matter if the condition passed
108+ * in has side effects.
104109 */
105110 @ Override
106111 protected void initialize () {
107112 m_hasFinished = false ;
108113 }
109-
114+
110115 /**
111- * If the loop has already ended, do nothing. Otherwise, check if the
112- * body command is running. If it is not, check the condition and start
113- * it if necessary.
116+ * If the loop has already ended, do nothing. Otherwise, check if the body
117+ * command is running. If it is not, check the condition and start it if
118+ * necessary.
114119 */
115120 @ Override
116121 protected void execute () {
117122 if (m_hasFinished ) {
118123 return ;
119124 }
120-
125+
121126 if (!m_body .isRunning ()) {
122127 checkCondition ();
123128 if (!m_hasFinished ) {
124129 m_body .start ();
125130 }
126131 }
127132 }
128-
133+
129134 /**
130135 * Cancel the body command.
131136 */
132137 @ Override
133138 protected void interrupted () {
134139 m_body .cancel ();
135140 }
136-
141+
137142 /**
138- * Check if the loop has finished. This is only true if the body command
139- * has ended and the condition returned false on most recent check.
143+ * Check if the loop has finished. This is only true if the body command has
144+ * ended and the condition returned false on most recent check.
140145 */
141146 @ Override
142147 protected boolean isFinished () {
0 commit comments