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..778772c 100644 --- a/src/Map.java +++ b/src/Map.java @@ -1,15 +1,21 @@ -import java.util.*; - public class Map { - private MapLongitude mapLongitude; - private Longitude longitude; private MapLatitude mapLatitude; private Latitude latitude; + private MapLongitude mapLongitude; + private Longitude longitude; + private Presenter presenter; public Map() { - this.mapLongitude = new MapLongitude(); - this.longitude = new Longitude(mapLongitude); this.mapLatitude = new MapLatitude(); - this.latitude = new Latitude(mapLatitude); + this.latitude = new Latitude(); + this.mapLongitude = new MapLongitude(); + this.longitude = new Longitude(); + this.presenter = new Presenter(longitude, latitude, mapLongitude, mapLatitude); + } + public double getMapLatitude() { + return mapLatitude.getValue(); + } + public double getLatitude() { + return latitude.getValue(); } public double getMapLongitude() { return mapLongitude.getValue(); @@ -18,13 +24,15 @@ return longitude.getValue(); } public void updateGPS(double lat2, double long2) { - this.longitude.updateGPS(lat2, long2); - this.latitude.updateGPS(lat2, long2); + this.presenter.updateGPS(lat2, long2); } - public double getMapLatitude() { - return mapLatitude.getValue(); - } - public double getLatitude() { - return latitude.getValue(); - } + // setAutoUpdate ���\�b�h�̒lj� + public void setAutoUpdate(boolean isAutoUpdate) { + this.presenter.setAutoUpdate(isAutoUpdate); + } + + // updateManually ���\�b�h�̒lj� + 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..4e0a1db --- /dev/null +++ b/src/Presenter.java @@ -0,0 +1,48 @@ +public class Presenter { + private Longitude longitude; + private Latitude latitude; + private MapLongitude mapLongitude; + private MapLatitude mapLatitude; + private boolean isAutoUpdate; // isAutoUpdate �t�B�[���h�̒lj� +// public Presenter(Longitude longitude, Latitude latitude, MapLongitude mapLongitude, MapLatitude mapLatitude) { +// this.longitude = longitude; +// this.latitude = latitude; +// this.mapLongitude = mapLongitude; +// this.mapLatitude = mapLatitude; +// } +// public void updateGPS(double lat2, double long2) { +// double longitude = this.longitude.updateGPS(lat2, long2); +// double latitude = this.latitude.updateGPS(lat2, long2); +// this.mapLongitude.updateLongitude(longitude); +// this.mapLatitude.updateLatitude(latitude); +// } + // �R���X�g���N�^ + public Presenter(Longitude longitude, Latitude latitude, MapLongitude mapLongitude, MapLatitude mapLatitude) { + this.longitude = longitude; + this.latitude = latitude; + this.mapLongitude = mapLongitude; + this.mapLatitude = mapLatitude; + this.isAutoUpdate = true; // �����l�� true �ɐݒ� + } + + // updateGPS ���\�b�h�̕ύX + 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); + } + } + + // setAutoUpdate ���\�b�h�̒lj� + public void setAutoUpdate(boolean isAutoUpdate) { + this.isAutoUpdate = isAutoUpdate; + } + + // updateManually ���\�b�h�̒lj� + public void updateManually() { + this.mapLongitude.updateLongitude(this.longitude.getValue()); + this.mapLatitude.updateLatitude(this.latitude.getValue()); + } +} \ No newline at end of file diff --git a/src/TestManualUpdate.java b/src/TestManualUpdate.java new file mode 100644 index 0000000..dfb4613 --- /dev/null +++ b/src/TestManualUpdate.java @@ -0,0 +1,69 @@ +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����� + } +} \ No newline at end of file