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;
017import java.util.StringJoiner;
018
019/**
020 * Simple container class for double based values with an accuracy (e.g. depth in meters).
021 */
022public class DoubleAccuracy {
023
024  private final Double value;
025  private final Double accuracy;
026
027  public DoubleAccuracy(Double value, Double accuracy) {
028    this.value = value;
029    // never negative
030    this.accuracy = accuracy == null ? null : Math.abs(accuracy);
031  }
032
033  public Double getValue() {
034    return value;
035  }
036
037  public Double getAccuracy() {
038    return accuracy;
039  }
040
041  @Override
042  public String toString() {
043    return new StringJoiner(", ", DoubleAccuracy.class.getSimpleName() + "[", "]")
044        .add("value=" + value)
045        .add("accuracy=" + accuracy)
046        .toString();
047  }
048
049  @Override
050  public boolean equals(Object o) {
051    if (this == o) {
052      return true;
053    }
054    if (!(o instanceof DoubleAccuracy)) {
055      return false;
056    }
057    DoubleAccuracy that = (DoubleAccuracy) o;
058    return Objects.equals(value, that.value) && Objects.equals(accuracy, that.accuracy);
059  }
060
061  @Override
062  public int hashCode() {
063    return Objects.hash(value, accuracy);
064  }
065}