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..780c143 100644 --- a/src/Map.java +++ b/src/Map.java @@ -1,30 +1,55 @@ import java.util.*; public class Map { - private MapLongitude mapLongitude; - private Longitude longitude; - private MapLatitude mapLatitude; - private Latitude latitude; - public Map() { - this.mapLongitude = new MapLongitude(); - this.longitude = new Longitude(mapLongitude); - this.mapLatitude = new MapLatitude(); - this.latitude = new Latitude(mapLatitude); - } - public double getMapLongitude() { - return mapLongitude.getValue(); - } - 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 getMapLatitude() { - return mapLatitude.getValue(); - } - public double getLatitude() { - return latitude.getValue(); - } -} \ No newline at end of file + private MapLatitude mapLatitude; + private Latitude latitude; + private MapLongitude mapLongitude; + private Longitude longitude; + private Presenter presenter; + private boolean autoUpdate; // �����X�V�̏�Ԃ��Ǘ�����ϐ� + + public Map() { + this.mapLatitude = new MapLatitude(); + this.latitude = new Latitude(); + this.mapLongitude = new MapLongitude(); + this.longitude = new Longitude(); + this.presenter = new Presenter(longitude, latitude, mapLongitude, mapLatitude); + this.autoUpdate = true; // �f�t�H���g�͎����X�VON + } + + // �����X�V�̏�Ԃ�ݒ肷�� + public void setAutoUpdate(boolean autoUpdate) { + this.autoUpdate = autoUpdate; + } + + // ���݂�GPS�ʒu�Ŏ蓮�X�V���s�� + public void updateManually() { + this.presenter.updateMapLocation(latitude.getValue(), longitude.getValue()); + } + + // �ȉ��̃��\�b�h�͕ύX�Ȃ� + public double getMapLatitude() { + return mapLatitude.getValue(); + } + + public double getLatitude() { + return latitude.getValue(); + } + + public double getMapLongitude() { + return mapLongitude.getValue(); + } + + public double getLongitude() { + return longitude.getValue(); + } + + // GPS�ʒu���X�V���ꂽ���̏��� + public void updateGPS(double lat2, double long2) { + this.latitude.updateGPS(lat2, long2); + this.longitude.updateGPS(lat2, long2); + if (autoUpdate) { // �����X�V��ON�̎��̂ݒn�}�ʒu���X�V + this.presenter.updateMapLocation(lat2, long2); + } + } +} diff --git a/src/Presenter.java b/src/Presenter.java new file mode 100644 index 0000000..a1c3e83 --- /dev/null +++ b/src/Presenter.java @@ -0,0 +1,23 @@ +public class Presenter { + private Longitude longitude; + private Latitude latitude; + private MapLongitude mapLongitude; + private MapLatitude mapLatitude; + + public Presenter(Longitude longitude, Latitude latitude, MapLongitude mapLongitude, MapLatitude mapLatitude) { + this.longitude = longitude; + this.latitude = latitude; + this.mapLongitude = mapLongitude; + this.mapLatitude = mapLatitude; + } + + // �n�}�ʒu���X�V����i�V�K���\�b�h�j + public void updateMapLocation(double lat, double lon) { + this.mapLatitude.updateLatitude(lat); + this.mapLongitude.updateLongitude(lon); + } + + // �ȉ��̃��\�b�h�͍폜 + // public void updateGPS(double lat2, double long2) { + // } +} diff --git a/src/TestManualUpdate.java b/src/TestManualUpdate.java new file mode 100644 index 0000000..c7c9d14 --- /dev/null +++ b/src/TestManualUpdate.java @@ -0,0 +1,70 @@ +import static org.junit.Assert.*; + +import org.junit.Test; + +public class TestManualUpdate { + + @Test + public void test() { + + 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); + + + 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); + + + 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); + + + map.setAutoUpdate(false); + + + 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); + assertEquals(mapLongi, 135.1, 0.0001); + + + 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); + assertEquals(mapLongi, 135.0, 0.0001); + } + +} \ No newline at end of file