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.vocabulary;
017
018import com.google.common.base.Strings;
019
020/**
021 * Enumeration to classify name usages by how they originated.
022 */
023public enum Origin {
024
025  /**
026   * Record came straight from source record.
027   */
028  SOURCE,
029
030  /**
031   * Implicit usage from a denormalised classification.
032   */
033  DENORMED_CLASSIFICATION,
034
035  /**
036   * Implicit usage from a verbatim parent name usage.
037   */
038  VERBATIM_PARENT,
039
040  /**
041   * Implicit usage from a verbatim accepted name usage.
042  */
043  VERBATIM_ACCEPTED,
044
045    /**
046   * Implicit usage from a verbatim basionym/original name.
047   */
048  VERBATIM_BASIONYM,
049
050  /**
051   * Duplicated usage from a single pro parte record.
052   */
053  PROPARTE,
054
055  /**
056   * Generated, missing autonym.
057   */
058  AUTONYM,
059
060  /**
061   * Generated, missing genus or species for "orphaned" lower name.
062   */
063  IMPLICIT_NAME,
064
065  /**
066   * Artificial accepted usage for a synonym if its missing to preserve the taxonomic hierarchy.
067   */
068  MISSING_ACCEPTED,
069
070  /**
071   * Placeholder usage for a missing or implicit basionym.
072   */
073  BASIONYM_PLACEHOLDER,
074
075  /**
076   * Implicit synonym based on the illegitimate ex author.
077   * See ICN article 46: http://www.iapt-taxon.org/nomen/main.php?page=art46
078   */
079  EX_AUTHOR_SYNONYM,
080
081  /**
082   * Any other origin not covered by the above.
083   */
084  OTHER;
085
086  /**
087   * Case insensitive lookup of an Origin by its name that does not throw an exception but returns null
088   * for not found origins.
089   *
090   * @param origin case insensitive name of the origin
091   *
092   * @return the matching Origin or null
093   */
094  public static Origin fromString(String origin) {
095    if (!Strings.isNullOrEmpty(origin)) {
096      try {
097        return valueOf(origin.toUpperCase().trim());
098      } catch (IllegalArgumentException e) {
099        // swallow
100      }
101    }
102    return null;
103  }
104
105}