| 1 | package com.roxoft.lib; | |
| 2 | ||
| 3 | import java.util.ArrayList; | |
| 4 | import java.util.List; | |
| 5 | ||
| 6 | /** | |
| 7 | * Mutable entity on a {@link IntegerCoord2D} co-ordinate system which retains a movement history. | |
| 8 | */ | |
| 9 | public final class Movable2DEntity { | |
| 10 | /** The history of {@link IntegerCoord2D} visited by this {@link Movable2DEntity}. */ | |
| 11 | private final List<IntegerCoord2D> locationHistory; | |
| 12 | /** This {@link Movable2DEntity}s current {@link IntegerCoord2D} location. */ | |
| 13 | private IntegerCoord2D location; | |
| 14 | ||
| 15 | private Movable2DEntity(final IntegerCoord2D currentLocation) { | |
| 16 | location = currentLocation; | |
| 17 | locationHistory = new ArrayList<>(); | |
| 18 | locationHistory.add(currentLocation); | |
| 19 | } | |
| 20 | ||
| 21 | /** | |
| 22 | * @param startLocation indicates a start location for this {@link Movable2DEntity} | |
| 23 | * @return a new {@link Movable2DEntity} at the specified {@link IntegerCoord2D} location | |
| 24 | */ | |
| 25 | public static Movable2DEntity at(final IntegerCoord2D startLocation) { | |
| 26 |
1
1. at : replaced return value with null for com/roxoft/lib/Movable2DEntity::at → KILLED |
return new Movable2DEntity(startLocation); |
| 27 | } | |
| 28 | ||
| 29 | /** | |
| 30 | * Move this {@link Movable2DEntity}s {@link IntegerCoord2D} location Up/North one space. | |
| 31 | */ | |
| 32 | public void moveUp() { | |
| 33 |
2
1. moveUp : removed call to com/roxoft/lib/Movable2DEntity::move → KILLED 2. moveUp : Replaced integer subtraction with addition → KILLED |
move(IntegerCoord2D.of(location.getX(), location.getY() - 1)); |
| 34 | } | |
| 35 | ||
| 36 | /** | |
| 37 | * Move this {@link Movable2DEntity}s {@link IntegerCoord2D} location Down/South one space. | |
| 38 | */ | |
| 39 | public void moveDown() { | |
| 40 |
2
1. moveDown : removed call to com/roxoft/lib/Movable2DEntity::move → KILLED 2. moveDown : Replaced integer addition with subtraction → KILLED |
move(IntegerCoord2D.of(location.getX(), location.getY() + 1)); |
| 41 | } | |
| 42 | ||
| 43 | /** | |
| 44 | * Move this {@link Movable2DEntity}s {@link IntegerCoord2D} location Left/West one space. | |
| 45 | */ | |
| 46 | public void moveLeft() { | |
| 47 |
2
1. moveLeft : removed call to com/roxoft/lib/Movable2DEntity::move → KILLED 2. moveLeft : Replaced integer subtraction with addition → KILLED |
move(IntegerCoord2D.of(location.getX() - 1, location.getY())); |
| 48 | } | |
| 49 | ||
| 50 | /** | |
| 51 | * Move this {@link Movable2DEntity}s {@link IntegerCoord2D} location Right/East one space. | |
| 52 | */ | |
| 53 | public void moveRight() { | |
| 54 |
2
1. moveRight : Replaced integer addition with subtraction → KILLED 2. moveRight : removed call to com/roxoft/lib/Movable2DEntity::move → KILLED |
move(IntegerCoord2D.of(location.getX() + 1, location.getY())); |
| 55 | } | |
| 56 | ||
| 57 | /** | |
| 58 | * @param newLocation a {@link IntegerCoord2D} to move this {@link Movable2DEntity} to. | |
| 59 | */ | |
| 60 | private void move(final IntegerCoord2D newLocation) { | |
| 61 | locationHistory.add(newLocation); | |
| 62 | location = newLocation; | |
| 63 | } | |
| 64 | ||
| 65 | /** | |
| 66 | * @return this {@link Movable2DEntity}s {@link IntegerCoord2D} location. | |
| 67 | */ | |
| 68 | public IntegerCoord2D location() { | |
| 69 |
1
1. location : replaced return value with null for com/roxoft/lib/Movable2DEntity::location → KILLED |
return location; |
| 70 | } | |
| 71 | ||
| 72 | /** | |
| 73 | * @return this {@link Movable2DEntity}s history of {@link IntegerCoord2D} location. | |
| 74 | */ | |
| 75 | public List<IntegerCoord2D> locationHistory() { | |
| 76 |
1
1. locationHistory : replaced return value with Collections.emptyList for com/roxoft/lib/Movable2DEntity::locationHistory → KILLED |
return locationHistory; |
| 77 | } | |
| 78 | } | |
Mutations | ||
| 26 |
1.1 |
|
| 33 |
1.1 2.2 |
|
| 40 |
1.1 2.2 |
|
| 47 |
1.1 2.2 |
|
| 54 |
1.1 2.2 |
|
| 69 |
1.1 |
|
| 76 |
1.1 |