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