001/** 002 * Copyright 2018 Tampere University of Technology, Pori Department 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package service.tut.pori.apilta.shock.datatypes; 017 018import java.util.Date; 019 020import javax.xml.bind.annotation.XmlAccessType; 021import javax.xml.bind.annotation.XmlAccessorType; 022import javax.xml.bind.annotation.XmlElement; 023import javax.xml.bind.annotation.XmlRootElement; 024import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 025 026import core.tut.pori.utils.ISODateAdapter; 027 028/** 029 * 030 * 031 */ 032@XmlRootElement(name=Definitions.ELEMENT_LOCATION_DATA) 033@XmlAccessorType(XmlAccessType.NONE) 034public class LocationData { 035 @XmlElement(name = service.tut.pori.apilta.sensors.datatypes.Definitions.ELEMENT_MEASUREMENT_ID) 036 private String _measurementId = null; 037 @XmlElement(name=Definitions.ELEMENT_LATITUDE) 038 private Double _latitude = null; 039 @XmlElement(name=Definitions.ELEMENT_LONGITUDE) 040 private Double _longitude = null; 041 @XmlElement(name=Definitions.ELEMENT_HEADING) 042 private Double _heading = null; 043 @XmlElement(name=Definitions.ELEMENT_SPEED) 044 private Double _speed = null; 045 @XmlJavaTypeAdapter(ISODateAdapter.class) 046 @XmlElement(name=Definitions.ELEMENT_TIMESTAMP) 047 private Date _timestamp = null; 048 049 /*** 050 * for sub-classing, use the static 051 * 052 * @return true if valid 053 * @see #isValid(LocationData) 054 */ 055 protected boolean isValid() { 056 if(_latitude == null || _longitude == null) { 057 return false; 058 }else if(_latitude < -90 || _latitude > 90){ 059 return false; 060 }else if(_longitude < -180 || _longitude > 180){ 061 return false; 062 }else if(_speed != null && _speed < 0){ 063 return false; 064 }else if(_heading != null && (_heading < 0 || _heading > 360)) { 065 return false; 066 }else{ 067 return true; 068 } 069 } 070 071 /** 072 * 073 * @param data 074 * @return true if valid and not null 075 */ 076 public static boolean isValid(LocationData data) { 077 return (data != null && data.isValid()); 078 } 079 080 /** 081 * @return the measurementId 082 */ 083 public String getMeasurementId() { 084 return _measurementId; 085 } 086 087 /** 088 * @param measurementId the measurementId to set 089 */ 090 public void setMeasurementId(String measurementId) { 091 _measurementId = measurementId; 092 } 093 094 /** 095 * @return the latitude 096 */ 097 public Double getLatitude() { 098 return _latitude; 099 } 100 /** 101 * @param latitude the latitude to set 102 */ 103 public void setLatitude(Double latitude) { 104 _latitude = latitude; 105 } 106 107 /** 108 * @return the longitude 109 */ 110 public Double getLongitude() { 111 return _longitude; 112 } 113 114 /** 115 * @param longitude the longitude to set 116 */ 117 public void setLongitude(Double longitude) { 118 _longitude = longitude; 119 } 120 121 /** 122 * @return the heading 123 */ 124 public Double getHeading() { 125 return _heading; 126 } 127 128 /** 129 * @param heading the heading to set 130 */ 131 public void setHeading(Double heading) { 132 _heading = heading; 133 } 134 135 /** 136 * @return the speed 137 */ 138 public Double getSpeed() { 139 return _speed; 140 } 141 142 /** 143 * @param speed the speed to set 144 */ 145 public void setSpeed(Double speed) { 146 _speed = speed; 147 } 148 149 /** 150 * @return the timestamp 151 */ 152 public Date getTimestamp() { 153 return _timestamp; 154 } 155 156 /** 157 * @param timestamp the timestamp to set 158 */ 159 public void setTimestamp(Date timestamp) { 160 _timestamp = timestamp; 161 } 162}