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.temporal;
017
018import org.gbif.api.util.formatter.TemporalCoverageFormatterVisitor;
019
020import java.io.Serializable;
021import java.util.Collection;
022import java.util.Objects;
023import java.util.StringJoiner;
024import java.util.stream.Collectors;
025import java.util.stream.Stream;
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 Stream.of(period).collect(Collectors.toList());
060  }
061
062  @Override
063  public boolean equals(Object o) {
064    if (this == o) {
065      return true;
066    }
067    if (o == null || getClass() != o.getClass()) {
068      return false;
069    }
070    VerbatimTimePeriod that = (VerbatimTimePeriod) o;
071    return Objects.equals(period, that.period) &&
072      type == that.type;
073  }
074
075  @Override
076  public int hashCode() {
077    return Objects.hash(period, type);
078  }
079
080  @Override
081  public String toString() {
082    return new StringJoiner(", ", VerbatimTimePeriod.class.getSimpleName() + "[", "]")
083      .add("period='" + period + "'")
084      .add("type=" + type)
085      .toString();
086  }
087
088  @Override
089  public String acceptFormatter(TemporalCoverageFormatterVisitor formatter) {
090    return formatter.format(this);
091  }
092}