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 */
016
017package org.gbif.api.vocabulary;
018
019import com.google.common.base.Strings;
020
021/**
022 * Enumeration to indicate a part of a canonical scientific name.
023 */
024public enum NamePart {
025
026  GENERIC,
027  INFRAGENERIC,
028  SPECIFIC,
029  INFRASPECIFIC;
030
031  /**
032   * Case insensitive lookup of a NamePart by its name that does not throw an exception but returns null
033   * for a not found NamePart.
034   *
035   * @param namePart case insensitive name of name part
036   *
037   * @return the matching NamePart or null
038   */
039  public static NamePart fromString(String namePart) {
040    if (!Strings.isNullOrEmpty(namePart)) {
041      try {
042        return valueOf(namePart.toUpperCase().trim());
043      } catch (IllegalArgumentException e) {
044        // swallow
045      }
046    }
047    return null;
048  }
049
050}