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
018/**
019 * A simple enumeration of all kingdoms found in the GBIF Backbone Taxonomy and also Catalogue of Life.
020 */
021public enum Kingdom {
022
023  INCERTAE_SEDIS,
024  ANIMALIA,
025  ARCHAEA,
026  BACTERIA,
027  CHROMISTA,
028  FUNGI,
029  PLANTAE,
030  PROTOZOA,
031  VIRUSES;
032
033  /**
034   * Looks up a kingdom by its nub usage key.
035   *
036   * @param usageKey the nub usage key to lookup, must be < 9 to get a result.
037   *
038   * @return the matching kingdom or null
039   */
040  public static Kingdom byNubUsageKey(int usageKey) {
041    try {
042      return Kingdom.values()[usageKey];
043    } catch (IndexOutOfBoundsException e) {
044      throw new IllegalArgumentException("There is no kingdom with usage key " + usageKey);
045    }
046  }
047
048  /**
049   * @return a unique single capital char representing the kingdom.
050   */
051  public String scientificName() {
052    String lower = name().replaceAll("_", " ").toLowerCase();
053    return this==INCERTAE_SEDIS ? lower : Character.toUpperCase(lower.charAt(0)) + lower.substring(1);
054  }
055
056  public int nubUsageKey() {
057    return ordinal();
058  }
059
060  /**
061   * @deprecated please use nubUsageKey() instead
062   */
063  @Deprecated
064  public Integer nubUsageID() {
065    return nubUsageKey();
066  }
067
068  /**
069   * @deprecated please use byNubUsageId(int) instead
070   */
071  @Deprecated
072  public static Kingdom byNubUsageId(int usageKey) {
073    return byNubUsageKey(usageKey);
074  }
075}