@@ -144,18 +144,14 @@ public void takePaint() {
144144 /** @return True if there is paint in the square where the painter is standing. */
145145 public boolean isOnPaint () {
146146 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 );
150148 return isOnPaint ;
151149 }
152150
153151 /** @return True if there is a paint bucket in the square where the painter is standing. */
154152 public boolean isOnBucket () {
155153 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 );
159155 return isOnBucket ;
160156 }
161157
@@ -170,9 +166,7 @@ public boolean hasPaint() {
170166 /** @return True if there is no barrier one square ahead in the requested direction. */
171167 public boolean canMove (String direction ) {
172168 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 );
176170 return canMove ;
177171 }
178172
@@ -305,17 +299,17 @@ private HashMap<String, String> getSignalDetails() {
305299 return details ;
306300 }
307301
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-
315302 private void sendOutputMessage (NeighborhoodSignalKey signalKey , HashMap <String , String > details ) {
316303 this .outputAdapter .sendMessage (new NeighborhoodSignalMessage (signalKey , details ));
317304 }
318305
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+
319313 private void sendInitializationMessage () {
320314 HashMap <String , String > initDetails = this .getSignalDetails ();
321315 initDetails .put (DIRECTION , this .direction .getDirectionString ());
0 commit comments