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.vocabulary;
017
018import org.apache.commons.lang3.StringUtils;
019
020/**
021 * Enumeration to indicate a part of a canonical scientific name.
022 *
023 * Deprecated.
024 * Please use the name parser enum instead.
025 * https://github.com/gbif/name-parser/blob/master/name-parser-api/src/main/java/org/gbif/nameparser/api/NamePart.java
026 */
027
028@Deprecated
029public enum NamePart {
030
031  GENERIC,
032  INFRAGENERIC,
033  SPECIFIC,
034  INFRASPECIFIC;
035
036  /**
037   * Case insensitive lookup of a NamePart by its name that does not throw an exception but returns null
038   * for a not found NamePart.
039   *
040   * @param namePart case insensitive name of name part
041   *
042   * @return the matching NamePart or null
043   */
044  public static NamePart fromString(String namePart) {
045    if (StringUtils.isNotEmpty(namePart)) {
046      try {
047        return valueOf(namePart.toUpperCase().trim());
048      } catch (IllegalArgumentException e) {
049        // swallow
050      }
051    }
052    return null;
053  }
054
055}