001/*
002 * Copyright 2014 Global Biodiversity Information Facility (GBIF)
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 org.gbif.api.model.registry.eml.geospatial;
017
018import com.google.common.base.Objects;
019
020
021public class GeospatialCoverage implements Geometry {
022
023  private String description;
024
025  private BoundingBox boundingBox;
026
027  public GeospatialCoverage() {
028  }
029
030  public GeospatialCoverage(String description, BoundingBox boundingBox) {
031    this.description = description;
032    this.boundingBox = boundingBox;
033  }
034
035  public BoundingBox getBoundingBox() {
036    return boundingBox;
037  }
038
039  public void setBoundingBox(BoundingBox boundingBox) {
040    // ensure globalCoverage is set
041    boundingBox.setGlobalCoverage(boundingBox.getMinLatitude(),
042                                  boundingBox.getMaxLatitude(),
043                                  boundingBox.getMinLongitude(),
044                                  boundingBox.getMaxLongitude());
045    this.boundingBox = boundingBox;
046  }
047
048  public String getDescription() {
049    return description;
050  }
051
052  public void setDescription(String description) {
053    this.description = description;
054  }
055
056  @Override
057  public String toWellKnownText() {
058    return boundingBox == null ? null : boundingBox.toWellKnownText();
059  }
060
061  @Override
062  public boolean equals(Object obj) {
063    if (this == obj) {
064      return true;
065    }
066    if (!(obj instanceof org.gbif.api.model.registry.eml.geospatial.GeospatialCoverage)) {
067      return false;
068    }
069
070    org.gbif.api.model.registry.eml.geospatial.GeospatialCoverage
071      that = (org.gbif.api.model.registry.eml.geospatial.GeospatialCoverage) obj;
072    return Objects.equal(this.description, that.description) && Objects.equal(this.boundingBox, that.boundingBox);
073  }
074
075  @Override
076  public int hashCode() {
077    return Objects.hashCode(description, boundingBox);
078  }
079
080  @Override
081  public String toString() {
082    return Objects.toStringHelper(this).add("description", description).add("boundingBox", boundingBox).toString();
083  }
084
085}