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.curatorial;
017
018import java.util.Objects;
019import java.util.StringJoiner;
020
021/**
022 * Composite class, combining fields from CuratorialUnitCount and CuratorialUnitRange for simpler parsing of
023 * curatorial units, since both count and range types share the same root element.
024 */
025public class CuratorialUnitComposite extends CuratorialUnit {
026
027  private static final long serialVersionUID = 3259062014051953305L;
028
029  // fields from CuratorialUnitCount
030  private int count;
031  private int deviation;
032  // fields from CuratorialUnitRange
033  private int lower;
034  private int upper;
035
036  public CuratorialUnitComposite() {
037  }
038
039  public CuratorialUnitComposite(int count, int deviation, int lower, int upper, String typeVerbatim) {
040    super(null, typeVerbatim);
041    this.count = count;
042    this.deviation = deviation;
043    this.lower = lower;
044    this.upper = upper;
045  }
046
047  public int getCount() {
048    return count;
049  }
050
051  public void setCount(int count) {
052    this.count = count;
053  }
054
055  public int getDeviation() {
056    return deviation;
057  }
058
059  public void setDeviation(int deviation) {
060    this.deviation = deviation;
061  }
062
063  public int getLower() {
064    return lower;
065  }
066
067  public void setLower(int lower) {
068    this.lower = lower;
069  }
070
071  public int getUpper() {
072    return upper;
073  }
074
075  public void setUpper(int upper) {
076    this.upper = upper;
077  }
078
079  public void addDeviation(String deviation) {
080    try {
081      this.deviation = Integer.valueOf(deviation);
082    } catch (NumberFormatException ignored) {
083      // nonesense provided
084    }
085  }
086
087  @Override
088  public boolean equals(Object o) {
089    if (this == o) {
090      return true;
091    }
092    if (o == null || getClass() != o.getClass()) {
093      return false;
094    }
095    if (!super.equals(o)) {
096      return false;
097    }
098    CuratorialUnitComposite that = (CuratorialUnitComposite) o;
099    return count == that.count &&
100      deviation == that.deviation &&
101      lower == that.lower &&
102      upper == that.upper;
103  }
104
105  @Override
106  public int hashCode() {
107    return Objects.hash(super.hashCode(), count, deviation, lower, upper);
108  }
109
110  @Override
111  public String toString() {
112    return new StringJoiner(", ", CuratorialUnitComposite.class.getSimpleName() + "[", "]")
113      .add("count=" + count)
114      .add("deviation=" + deviation)
115      .add("lower=" + lower)
116      .add("upper=" + upper)
117      .toString();
118  }
119}