remove redundancy/duplicity
This commit is contained in:
parent
303b1c6df5
commit
3a2175a5f6
|
@ -39,40 +39,44 @@ public class MarsMap {
|
||||||
|
|
||||||
private void incrementLatitude() {
|
private void incrementLatitude() {
|
||||||
int latitude = currentPosition.getLatitude();
|
int latitude = currentPosition.getLatitude();
|
||||||
int newLatitude = latitude + 1 > height
|
int newLatitude = getIncrementedPosition(latitude, height);
|
||||||
? 1
|
|
||||||
: ++latitude;
|
|
||||||
setNewLatitude(newLatitude);
|
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() {
|
private void incrementLongitude() {
|
||||||
int longitude = currentPosition.getLongitude();
|
int longitude = currentPosition.getLongitude();
|
||||||
int newLongitude = longitude + 1 > width
|
int newLongitude = getIncrementedPosition(longitude, width);
|
||||||
? 1
|
|
||||||
: ++longitude;
|
|
||||||
setNewLongitude(newLongitude);
|
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() {
|
private void decrementLongitude() {
|
||||||
int longitude = currentPosition.getLongitude();
|
int longitude = currentPosition.getLongitude();
|
||||||
int newLongitude = longitude - 1 < 1
|
int newLongitude = decrementPosition(longitude, width);
|
||||||
? width
|
|
||||||
: --longitude;
|
|
||||||
setNewLongitude(newLongitude);
|
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) {
|
private void setNewLongitude(int newLongitude) {
|
||||||
currentPosition = currentPosition.ofUpdatedLongitude(newLongitude);
|
currentPosition = currentPosition.ofUpdatedLongitude(newLongitude);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue