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.temporal;
017
018import org.gbif.api.util.formatter.TemporalCoverageFormatterVisitor;
019
020import java.io.Serializable;
021import java.util.Collection;
022
023import com.google.common.base.Objects;
024import com.google.common.collect.Lists;
025
026
027/**
028 * A verbatim (e.g. free text) period of time.
029 */
030public class VerbatimTimePeriod extends TemporalCoverage implements Serializable {
031
032  private static final long serialVersionUID = 2161509394401716416L;
033
034  private String period;
035
036  private VerbatimTimePeriodType type;
037
038  public VerbatimTimePeriod() {
039  }
040
041  public String getPeriod() {
042    return period;
043  }
044
045  public void setPeriod(String period) {
046    this.period = period;
047  }
048
049  public VerbatimTimePeriodType getType() {
050    return type;
051  }
052
053  public void setType(VerbatimTimePeriodType type) {
054    this.type = type;
055  }
056
057  @Override
058  public Collection<String> toKeywords() {
059    return Lists.newArrayList(period);
060  }
061
062  @Override
063  public boolean equals(Object obj) {
064    if (this == obj) {
065      return true;
066    }
067    if (!(obj instanceof org.gbif.api.model.registry.eml.temporal.VerbatimTimePeriod)) {
068      return false;
069    }
070
071    org.gbif.api.model.registry.eml.temporal.VerbatimTimePeriod
072      that = (org.gbif.api.model.registry.eml.temporal.VerbatimTimePeriod) obj;
073    return Objects.equal(this.period, that.period) && Objects.equal(this.type, that.type);
074  }
075
076  @Override
077  public int hashCode() {
078    return Objects.hashCode(super.hashCode(), period, type);
079  }
080
081  @Override
082  public String toString() {
083    return Objects.toStringHelper(this)
084      .add("super", super.toString())
085      .add("period", period)
086      .add("type", type)
087      .toString();
088  }
089
090  @Override
091  public String acceptFormatter(TemporalCoverageFormatterVisitor formatter) {
092    return formatter.format(this);
093  }
094}