diff --git a/.project b/.project index a3e06b8..1098dee 100644 --- a/.project +++ b/.project @@ -1,6 +1,6 @@ - MapPush2 + MapPush diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..5e56e04 --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1 @@ +/bin diff --git a/src/Latitude.java b/src/Latitude.java index d9f9f3b..f1716a0 100644 --- a/src/Latitude.java +++ b/src/Latitude.java @@ -1,16 +1,12 @@ import java.util.*; public class Latitude { - private MapLatitude mapLatitude; private double value; - public Latitude(MapLatitude mapLatitude) { - this.mapLatitude = mapLatitude; - } public double getValue() { return this.value; } - public void updateGPS(double lat2, double long2) { + public double updateGPS(double lat2, double long2) { this.value = lat2; - this.mapLatitude.updateLatitude(this.value); + return this.value; } } \ No newline at end of file diff --git a/src/Longitude.java b/src/Longitude.java index b533c8a..032283a 100644 --- a/src/Longitude.java +++ b/src/Longitude.java @@ -1,16 +1,12 @@ import java.util.*; public class Longitude { - private MapLongitude mapLongitude; private double value; - public Longitude(MapLongitude mapLongitude) { - this.mapLongitude = mapLongitude; - } public double getValue() { return this.value; } - public void updateGPS(double lat2, double long2) { + public double updateGPS(double lat2, double long2) { this.value = long2; - this.mapLongitude.updateLongitude(this.value); + return this.value; } } \ No newline at end of file diff --git a/src/Map.java b/src/Map.java index abfd465..a2a1995 100644 --- a/src/Map.java +++ b/src/Map.java @@ -1,30 +1,37 @@ import java.util.*; public class Map { - private MapLongitude mapLongitude; private Longitude longitude; - private MapLatitude mapLatitude; private Latitude latitude; + private MapLatitude mapLatitude; + private MapLongitude mapLongitude; + private Presenter presenter; public Map() { - this.mapLongitude = new MapLongitude(); - this.longitude = new Longitude(mapLongitude); + this.longitude = new Longitude(); + this.latitude = new Latitude(); this.mapLatitude = new MapLatitude(); - this.latitude = new Latitude(mapLatitude); - } - public double getMapLongitude() { - return mapLongitude.getValue(); + this.mapLongitude = new MapLongitude(); + this.presenter = new Presenter(longitude, mapLongitude, latitude, mapLatitude); } public double getLongitude() { return longitude.getValue(); } - public void updateGPS(double lat2, double long2) { - this.longitude.updateGPS(lat2, long2); - this.latitude.updateGPS(lat2, long2); + public double getLatitude() { + return latitude.getValue(); } public double getMapLatitude() { return mapLatitude.getValue(); } - public double getLatitude() { - return latitude.getValue(); + public double getMapLongitude() { + return mapLongitude.getValue(); + } + public void updateGPS(double lat2, double long2) { + this.presenter.updateGPS(lat2, long2); + } + public void setAutoUpdate(boolean isAutoUpdate) { + this.presenter.setAutoUpdate(isAutoUpdate); + } + public void updateManually() { + this.presenter.updateManually(); } } \ No newline at end of file diff --git a/src/Presenter.java b/src/Presenter.java new file mode 100644 index 0000000..8669dde --- /dev/null +++ b/src/Presenter.java @@ -0,0 +1,32 @@ +import java.util.*; + +public class Presenter { + private Longitude longitude; + private MapLongitude mapLongitude; + private Latitude latitude; + private MapLatitude mapLatitude; + private boolean isAutoUpdate = true; + public Presenter(Longitude longitude, MapLongitude mapLongitude, Latitude latitude, MapLatitude mapLatitude) { + this.longitude = longitude; + this.mapLongitude = mapLongitude; + this.latitude = latitude; + this.mapLatitude = mapLatitude; + } + public void updateGPS(double lat2, double long2) { + double longitude = this.longitude.updateGPS(lat2, long2); + double latitude = this.latitude.updateGPS(lat2, long2); + if (isAutoUpdate) { + this.mapLongitude.updateLongitude(longitude); + this.mapLatitude.updateLatitude(latitude); + } + } + public void updateManually() { + double longitude = this.longitude.getValue(); + double latitude = this.latitude.getValue(); + this.mapLongitude.updateLongitude(longitude); + this.mapLatitude.updateLatitude(latitude); + } + public void setAutoUpdate(boolean isAutoUpdate) { + this.isAutoUpdate = isAutoUpdate; + } +} \ No newline at end of file diff --git a/src/TestManualUpdate.java b/src/TestManualUpdate.java new file mode 100644 index 0000000..6661e17 --- /dev/null +++ b/src/TestManualUpdate.java @@ -0,0 +1,72 @@ + + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class TestManualUpdate { + + @Test + public void test() { + // �k��35.0�x�C���o135.0�x�C�����X�V���[�h�ɐݒ肷�� + Map map = new Map(); + map.updateGPS(35.0, 135.0); + map.setAutoUpdate(true); + double lati = map.getLatitude(); + double longi = map.getLongitude(); + double mapLati = map.getMapLatitude(); + double mapLongi = map.getMapLongitude(); + assertEquals(lati, 35.0, 0.0001); + assertEquals(longi, 135.0, 0.0001); + assertEquals(mapLati, 35.0, 0.0001); + assertEquals(mapLongi, 135.0, 0.0001); + + // �k��35.1�x�C���o135.1�x�Ɉړ����� + map.updateGPS(35.1, 135.1); + lati = map.getLatitude(); + longi = map.getLongitude(); + mapLati = map.getMapLatitude(); + mapLongi = map.getMapLongitude(); + assertEquals(lati, 35.1, 0.0001); + assertEquals(longi, 135.1, 0.0001); + assertEquals(mapLati, 35.1, 0.0001); + assertEquals(mapLongi, 135.1, 0.0001); + + // �蓮�X�V���s�� + map.updateManually(); + lati = map.getLatitude(); + longi = map.getLongitude(); + mapLati = map.getMapLatitude(); + mapLongi = map.getMapLongitude(); + assertEquals(lati, 35.1, 0.0001); + assertEquals(longi, 135.1, 0.0001); + assertEquals(mapLati, 35.1, 0.0001); + assertEquals(mapLongi, 135.1, 0.0001); + + // �蓮�X�V���[�h�ɐݒ肷�� + map.setAutoUpdate(false); + + // �k��35.0�x�C���o135.0�x�ɖ߂� + map.updateGPS(35.0, 135.0); + lati = map.getLatitude(); + longi = map.getLongitude(); + mapLati = map.getMapLatitude(); + mapLongi = map.getMapLongitude(); + assertEquals(lati, 35.0, 0.0001); + assertEquals(longi, 135.0, 0.0001); + assertEquals(mapLati, 35.1, 0.0001); // �蓮�X�V�̂��ߒl�͕ω����Ȃ� + assertEquals(mapLongi, 135.1, 0.0001); // �蓮�X�V�̂��ߒl�͕ω����Ȃ� + + // �蓮�X�V���s�� + map.updateManually(); + lati = map.getLatitude(); + longi = map.getLongitude(); + mapLati = map.getMapLatitude(); + mapLongi = map.getMapLongitude(); + assertEquals(lati, 35.0, 0.0001); + assertEquals(longi, 135.0, 0.0001); + assertEquals(mapLati, 35.0, 0.0001); // �蓮�X�V�ɂ���Ēl���X�V����� + assertEquals(mapLongi, 135.0, 0.0001); // �蓮�X�V�ɂ���Ēl���X�V����� + } + +}