001package arez.dom; 002 003import java.util.Objects; 004import javaemul.internal.annotations.DoNotAutobox; 005import javax.annotation.Nullable; 006 007/** 008 * An immutable variant of {@link akasha.GeolocationCoordinates}. 009 */ 010public final class Position 011{ 012 private final double _accuracy; 013 @Nullable 014 private final Double _altitude; 015 @Nullable 016 private final Double _heading; 017 private final double _latitude; 018 private final double _longitude; 019 @Nullable 020 private final Double _speed; 021 022 /** 023 * Create the position object. 024 * 025 * @param accuracy the accuracy. 026 * @param altitude the altitude. 027 * @param heading the heading. 028 * @param latitude the latitude. 029 * @param longitude the longitude. 030 * @param speed the speed. 031 */ 032 public Position( final double accuracy, 033 @DoNotAutobox @Nullable final Double altitude, 034 @DoNotAutobox @Nullable final Double heading, 035 final double latitude, 036 final double longitude, 037 @DoNotAutobox @Nullable final Double speed ) 038 { 039 _accuracy = accuracy; 040 _altitude = altitude; 041 _heading = heading; 042 _latitude = latitude; 043 _longitude = longitude; 044 _speed = speed; 045 } 046 047 /** 048 * Return the accuracy of the latitude and longitude properties, expressed in meters. 049 * 050 * @return the accuracy. 051 */ 052 public double getAccuracy() 053 { 054 return _accuracy; 055 } 056 057 /** 058 * Return the position's altitude in meters, relative to sea level. This value can be null if the implementation cannot provide the data. 059 * 060 * @return the altitude. 061 */ 062 @Nullable 063 public Double getAltitude() 064 { 065 return _altitude; 066 } 067 068 /** 069 * Return the direction in which the device is traveling. 070 * This value, specified in degrees, indicates how far off from heading true north the device is. 0 degrees 071 * represents true north, and the direction is determined clockwise (which means that east is 90 degrees and 072 * west is 270 degrees). If speed is 0, heading is NaN. If the device is unable to provide heading information, 073 * this value is null. 074 * 075 * @return the heading. 076 */ 077 @Nullable 078 public Double getHeading() 079 { 080 return _heading; 081 } 082 083 /** 084 * Return the position's latitude in decimal degrees. 085 * 086 * @return the latitude. 087 */ 088 public double getLatitude() 089 { 090 return _latitude; 091 } 092 093 /** 094 * Return the position's longitude in decimal degrees. 095 * 096 * @return the longitude. 097 */ 098 public double getLongitude() 099 { 100 return _longitude; 101 } 102 103 /** 104 * Return the velocity of the device in meters per second. 105 * 106 * @return the speed. 107 */ 108 @Nullable 109 public Double getSpeed() 110 { 111 return _speed; 112 } 113 114 @Override 115 public boolean equals( final Object o ) 116 { 117 if ( o instanceof Position ) 118 { 119 final Position other = (Position) o; 120 return other._latitude == _latitude && other._longitude == _longitude; 121 } 122 else 123 { 124 return false; 125 } 126 } 127 128 @Override 129 public int hashCode() 130 { 131 return Objects.hash( _latitude, _longitude ); 132 } 133}