001/**
002 * Copyright 2016 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.alerts.datatypes;
017
018import javax.xml.bind.annotation.XmlAccessType;
019import javax.xml.bind.annotation.XmlAccessorType;
020import javax.xml.bind.annotation.XmlElement;
021import javax.xml.bind.annotation.XmlRootElement;
022
023import org.apache.log4j.Logger;
024
025/**
026 * class for representing location
027 * 
028 */
029@XmlRootElement(name=Definitions.ELEMENT_LOCATION)
030@XmlAccessorType(XmlAccessType.NONE)
031public class Location {
032  private static final Logger LOGGER = Logger.getLogger(Location.class);
033  @XmlElement(name=Definitions.ELEMENT_HEADING)
034  private Double _heading = null;
035  @XmlElement(name=Definitions.ELEMENT_LATITUDE)
036  private Double _latitude = null;
037  @XmlElement(name=Definitions.ELEMENT_LONGITUDE)
038  private Double _longitude = null;
039  
040  /**
041   * @return the latitude
042   * @see #setLatitude(Double)
043   */
044  public Double getLatitude() {
045    return _latitude;
046  }
047  
048  /**
049   * @param latitude the latitude to set
050   * @see #getLatitude()
051   */
052  public void setLatitude(Double latitude) {
053    _latitude = latitude;
054  }
055  
056  /**
057   * @return the longitude
058   * @see #setLongitude(Double)
059   */
060  public Double getLongitude() {
061    return _longitude;
062  }
063  
064  /**
065   * @param longitude the longitude to set
066   * @see #getLongitude()
067   */
068  public void setLongitude(Double longitude) {
069    _longitude = longitude;
070  }
071
072  /**
073   * @return the heading
074   * @see #setHeading(Double)
075   */
076  public Double getHeading() {
077    return _heading;
078  }
079
080  /**
081   * @param heading the heading to set
082   * @see #getHeading()
083   */
084  public void setHeading(Double heading) {
085    _heading = heading;
086  }
087  
088  /**
089   * 
090   * @return true if valid
091   */
092  protected boolean isValid() {
093    if(_heading != null && (_heading < 0 || _heading > 360)) {
094      LOGGER.debug("Invalid heading.");
095      return false;
096    }else if(_longitude < -180 || _longitude > 180){
097      LOGGER.debug("Invalid longitude.");
098      return false;
099    }else if(_latitude < -90 || _latitude > 90){
100      LOGGER.debug("Invalid latitude.");
101      return false;
102    }else{
103      return true;
104    }
105  }
106
107  /**
108   * 
109   * @param location
110   * @return false if location is null or invalid
111   */
112  public static boolean isValid(Location location) {
113    return (location != null && location.isValid());
114  }
115}