001/* 002 * Copyright 2020 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 java.util.Objects; 019import java.util.StringJoiner; 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 o) { 063 if (this == o) { 064 return true; 065 } 066 if (o == null || getClass() != o.getClass()) { 067 return false; 068 } 069 GeospatialCoverage that = (GeospatialCoverage) o; 070 return Objects.equals(description, that.description) && 071 Objects.equals(boundingBox, that.boundingBox); 072 } 073 074 @Override 075 public int hashCode() { 076 return Objects.hash(description, boundingBox); 077 } 078 079 @Override 080 public String toString() { 081 return new StringJoiner(", ", GeospatialCoverage.class.getSimpleName() + "[", "]") 082 .add("description='" + description + "'") 083 .add("boundingBox=" + boundingBox) 084 .toString(); 085 } 086}