diff --git a/src/Latitude.java b/src/Latitude.java index d9f9f3b..73d6a0e 100644 --- a/src/Latitude.java +++ b/src/Latitude.java @@ -1,5 +1,3 @@ -import java.util.*; - public class Latitude { private MapLatitude mapLatitude; private double value; @@ -9,8 +7,10 @@ public double getValue() { return this.value; } - public void updateGPS(double lat2, double long2) { - this.value = lat2; - this.mapLatitude.updateLatitude(this.value); - } + public void updateGPS(double lat2, double long2, boolean autoUpdate) { + this.value = lat2; + if (autoUpdate) { + this.mapLatitude.updateLatitude(this.value); + } + } } \ No newline at end of file diff --git a/src/Longitude.java b/src/Longitude.java index b533c8a..7819d1d 100644 --- a/src/Longitude.java +++ b/src/Longitude.java @@ -1,5 +1,3 @@ -import java.util.*; - public class Longitude { private MapLongitude mapLongitude; private double value; @@ -9,8 +7,10 @@ public double getValue() { return this.value; } - public void updateGPS(double lat2, double long2) { - this.value = long2; - this.mapLongitude.updateLongitude(this.value); - } + public void updateGPS(double lat2, double long2, boolean autoUpdate) { + this.value = long2; + if (autoUpdate) { + this.mapLongitude.updateLongitude(this.value); + } + } } \ No newline at end of file diff --git a/src/Map.java b/src/Map.java index abfd465..a4c661a 100644 --- a/src/Map.java +++ b/src/Map.java @@ -1,15 +1,16 @@ -import java.util.*; - public class Map { private MapLongitude mapLongitude; private Longitude longitude; private MapLatitude mapLatitude; private Latitude latitude; + private boolean autoUpdate; + public Map() { this.mapLongitude = new MapLongitude(); this.longitude = new Longitude(mapLongitude); this.mapLatitude = new MapLatitude(); this.latitude = new Latitude(mapLatitude); + this.autoUpdate = true; // �f�t�H���g�͎����X�V���[�h } public double getMapLongitude() { return mapLongitude.getValue(); @@ -17,14 +18,24 @@ 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(); } + + public void setAutoUpdate(boolean autoUpdate) { + this.autoUpdate = autoUpdate; + } + + public void updateGPS(double lat2, double long2) { + this.longitude.updateGPS(lat2, long2, this.autoUpdate); + this.latitude.updateGPS(lat2, long2, this.autoUpdate); + } + + 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..2faf8b1 --- /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() { + // �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