@@ -144,18 +144,14 @@ public void takePaint() {
144
144
/** @return True if there is paint in the square where the painter is standing. */
145
145
public boolean isOnPaint () {
146
146
boolean isOnPaint = this .grid .getSquare (this .xLocation , this .yLocation ).hasColor ();
147
- this .outputAdapter .sendMessage (
148
- new NeighborhoodSignalMessage (
149
- NeighborhoodSignalKey .IS_ON_PAINT , this .getSignalDetailsForBooleanMethod (isOnPaint )));
147
+ this .sendBooleanMessage (NeighborhoodSignalKey .IS_ON_PAINT , isOnPaint );
150
148
return isOnPaint ;
151
149
}
152
150
153
151
/** @return True if there is a paint bucket in the square where the painter is standing. */
154
152
public boolean isOnBucket () {
155
153
boolean isOnBucket = this .grid .getSquare (this .xLocation , this .yLocation ).containsPaint ();
156
- this .outputAdapter .sendMessage (
157
- new NeighborhoodSignalMessage (
158
- NeighborhoodSignalKey .IS_ON_BUCKET , this .getSignalDetailsForBooleanMethod (isOnBucket )));
154
+ this .sendBooleanMessage (NeighborhoodSignalKey .IS_ON_BUCKET , isOnBucket );
159
155
return isOnBucket ;
160
156
}
161
157
@@ -170,9 +166,7 @@ public boolean hasPaint() {
170
166
/** @return True if there is no barrier one square ahead in the requested direction. */
171
167
public boolean canMove (String direction ) {
172
168
boolean canMove = this .isValidMovement (Direction .fromString (direction ));
173
- this .outputAdapter .sendMessage (
174
- new NeighborhoodSignalMessage (
175
- NeighborhoodSignalKey .CAN_MOVE , this .getSignalDetailsForBooleanMethod (canMove )));
169
+ this .sendBooleanMessage (NeighborhoodSignalKey .CAN_MOVE , canMove );
176
170
return canMove ;
177
171
}
178
172
@@ -305,17 +299,17 @@ private HashMap<String, String> getSignalDetails() {
305
299
return details ;
306
300
}
307
301
308
- private HashMap <String , String > getSignalDetailsForBooleanMethod (boolean result ) {
309
- HashMap <String , String > details = this .getSignalDetails ();
310
- String resultString = result ? "true" : "false" ;
311
- details .put (BOOLEAN_RESULT , resultString );
312
- return details ;
313
- }
314
-
315
302
private void sendOutputMessage (NeighborhoodSignalKey signalKey , HashMap <String , String > details ) {
316
303
this .outputAdapter .sendMessage (new NeighborhoodSignalMessage (signalKey , details ));
317
304
}
318
305
306
+ private void sendBooleanMessage (NeighborhoodSignalKey signalKey , boolean result ) {
307
+ HashMap <String , String > details = this .getSignalDetails ();
308
+ String resultString = String .valueOf (result );
309
+ details .put (BOOLEAN_RESULT , resultString );
310
+ this .sendOutputMessage (signalKey , details );
311
+ }
312
+
319
313
private void sendInitializationMessage () {
320
314
HashMap <String , String > initDetails = this .getSignalDetails ();
321
315
initDetails .put (DIRECTION , this .direction .getDirectionString ());
0 commit comments