001/*
002 * Licensed under the Apache License, Version 2.0 (the "License");
003 * you may not use this file except in compliance with the License.
004 * You may obtain a copy of the License at
005 *
006 *     http://www.apache.org/licenses/LICENSE-2.0
007 *
008 * Unless required by applicable law or agreed to in writing, software
009 * distributed under the License is distributed on an "AS IS" BASIS,
010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011 * See the License for the specific language governing permissions and
012 * limitations under the License.
013 */
014package org.gbif.common.parsers.geospatial;
015
016import java.util.Objects;
017
018/**
019 * A bounding box for lat long.
020 */
021public class LatLngBoundingBox {
022
023  public static final LatLngBoundingBox GLOBAL_BOUNDING_BOX = new LatLngBoundingBox(-180, -90, 180, 90);
024
025  double minLong;
026  double minLat;
027  double maxLong;
028  double maxLat;
029
030  /**
031   * Force the box to be well formed
032   */
033  public LatLngBoundingBox(double minLong, double minLat, double maxLong, double maxLat) {
034    this.minLong = minLong;
035    this.minLat = minLat;
036    this.maxLong = maxLong;
037    this.maxLat = maxLat;
038  }
039
040  @Override
041  public boolean equals(Object t) {
042    if (this == t) {
043      return true;
044    }
045    if (!(t instanceof LatLngBoundingBox)) {
046      return false;
047    }
048    LatLngBoundingBox target = (LatLngBoundingBox) t;
049    return minLat == target.getMinLat() && minLong == target.getMinLong() && maxLat == target.getMaxLat()
050           && maxLong == target.getMaxLong();
051  }
052
053  @Override
054  public int hashCode() {
055    return Objects.hash(minLong, minLat, maxLong, maxLat);
056  }
057
058  @Override
059  public String toString() {
060    return "minLong[" + minLong + "] minLat[" + minLat + "] maxLong[" + maxLong + "] maxLat[" + maxLat + "] ";
061  }
062
063  /**
064   * @return the maxLat
065   */
066  public double getMaxLat() {
067    return maxLat;
068  }
069
070  /**
071   * @param maxLat the maxLat to set
072   */
073  public void setMaxLat(double maxLat) {
074    this.maxLat = maxLat;
075  }
076
077  /**
078   * @return the maxLong
079   */
080  public double getMaxLong() {
081    return maxLong;
082  }
083
084  /**
085   * @param maxLong the maxLong to set
086   */
087  public void setMaxLong(double maxLong) {
088    this.maxLong = maxLong;
089  }
090
091  /**
092   * @return the minLat
093   */
094  public double getMinLat() {
095    return minLat;
096  }
097
098  /**
099   * @param minLat the minLat to set
100   */
101  public void setMinLat(double minLat) {
102    this.minLat = minLat;
103  }
104
105  /**
106   * @return the minLong
107   */
108  public double getMinLong() {
109    return minLong;
110  }
111
112  /**
113   * @param minLong the minLong to set
114   */
115  public void setMinLong(double minLong) {
116    this.minLong = minLong;
117  }
118}