1
0
Fork 0

remove redundancy/duplicity

This commit is contained in:
Xavier Fontanet 2024-06-20 23:28:33 +02:00
parent 303b1c6df5
commit 3a2175a5f6
1 changed files with 25 additions and 21 deletions

View File

@ -39,40 +39,44 @@ public class MarsMap {
private void incrementLatitude() {
int latitude = currentPosition.getLatitude();
int newLatitude = latitude + 1 > height
? 1
: ++latitude;
int newLatitude = getIncrementedPosition(latitude, height);
setNewLatitude(newLatitude);
}
private void decrementLatitude() {
int latitude = currentPosition.getLatitude();
int newLatitude = latitude - 1 < 1
? height
: --latitude;
setNewLatitude(newLatitude);
}
private void setNewLatitude(int newLatitude) {
currentPosition = currentPosition.ofUpdatedLatitude(newLatitude);
}
private void incrementLongitude() {
int longitude = currentPosition.getLongitude();
int newLongitude = longitude + 1 > width
? 1
: ++longitude;
int newLongitude = getIncrementedPosition(longitude, width);
setNewLongitude(newLongitude);
}
private int getIncrementedPosition(int currentPosition, int threshold) {
return currentPosition + 1 > threshold
? 1
: ++currentPosition;
}
private void decrementLatitude() {
int latitude = currentPosition.getLatitude();
int newLatitude = decrementPosition(latitude, height);
setNewLatitude(newLatitude);
}
private void decrementLongitude() {
int longitude = currentPosition.getLongitude();
int newLongitude = longitude - 1 < 1
? width
: --longitude;
int newLongitude = decrementPosition(longitude, width);
setNewLongitude(newLongitude);
}
private int decrementPosition(int currentPosition, int threshold) {
return currentPosition - 1 < 1
? threshold
: --currentPosition;
}
private void setNewLatitude(int newLatitude) {
currentPosition = currentPosition.ofUpdatedLatitude(newLatitude);
}
private void setNewLongitude(int newLongitude) {
currentPosition = currentPosition.ofUpdatedLongitude(newLongitude);
}