001package com.hfg.bio.taxonomy.ncbi;
002
003import java.io.Serializable;
004import java.util.Collection;
005import java.util.HashMap;
006import java.util.Map;
007
008
009//------------------------------------------------------------------------------
010/**
011 * Enumerated list of NCBI taxon name classes.
012 * <p>
013 * Based on values in the names.dmp file in ftp://ftp.ncbi.nih.gov/pub/taxonomy/taxdump.tar.gz
014 * </p>
015 *
016 * @author J. Alex Taylor, hairyfatguy.com
017 */
018//------------------------------------------------------------------------------
019// com.hfg XML/HTML Coding Library
020//
021// This library is free software; you can redistribute it and/or
022// modify it under the terms of the GNU Lesser General Public
023// License as published by the Free Software Foundation; either
024// version 2.1 of the License, or (at your option) any later version.
025//
026// This library is distributed in the hope that it will be useful,
027// but WITHOUT ANY WARRANTY; without even the implied warranty of
028// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
029// Lesser General Public License for more details.
030//
031// You should have received a copy of the GNU Lesser General Public
032// License along with this library; if not, write to the Free Software
033// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
034//
035// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
036// jataylor@hairyfatguy.com
037//------------------------------------------------------------------------------
038
039public class NCBITaxonNameClass implements Serializable
040{
041   //**************************************************************************
042   // PRIVATE FIELDS
043   //**************************************************************************
044
045   private String mName;
046
047   // Must be declared before the public NCBITaxonNameClass fields are constructed.
048   private static Map<String, NCBITaxonNameClass> sUniqueMap = new HashMap<String, NCBITaxonNameClass>(20);
049
050   //**************************************************************************
051   // PUBLIC FIELDS
052   //**************************************************************************
053
054   public static NCBITaxonNameClass ACRONYM             = new NCBITaxonNameClass("acronym");
055   public static NCBITaxonNameClass ANAMORPH            = new NCBITaxonNameClass("anamorph");
056   public static NCBITaxonNameClass AUTHORITY           = new NCBITaxonNameClass("authority");
057   public static NCBITaxonNameClass BLAST_NAME          = new NCBITaxonNameClass("blast name");
058   public static NCBITaxonNameClass COMMON_NAME         = new NCBITaxonNameClass("common name");
059   public static NCBITaxonNameClass EQUIVALENT_NAME     = new NCBITaxonNameClass("equivalent name");
060   public static NCBITaxonNameClass GENBANK_ACRONYM     = new NCBITaxonNameClass("genbank acronym");
061   public static NCBITaxonNameClass GENBANK_ANAMORPH    = new NCBITaxonNameClass("genbank anamorph");
062   public static NCBITaxonNameClass GENBANK_COMMON_NAME = new NCBITaxonNameClass("genbank common name");
063   public static NCBITaxonNameClass GENBANK_SYNONYM     = new NCBITaxonNameClass("genbank synonym");
064   public static NCBITaxonNameClass INCLUDES            = new NCBITaxonNameClass("includes");
065   public static NCBITaxonNameClass IN_PART             = new NCBITaxonNameClass("in-part");
066   public static NCBITaxonNameClass MISNOMER            = new NCBITaxonNameClass("misnomer");
067   public static NCBITaxonNameClass MISSPELLING         = new NCBITaxonNameClass("misspelling");
068   public static NCBITaxonNameClass SCIENTIFIC_NAME     = new NCBITaxonNameClass("scientific name");
069   public static NCBITaxonNameClass SYNONYM             = new NCBITaxonNameClass("synonym");
070   public static NCBITaxonNameClass TELEOMORPH          = new NCBITaxonNameClass("teleomorph");
071   public static NCBITaxonNameClass TYPE_MATERIAL       = new NCBITaxonNameClass("type material");
072   public static NCBITaxonNameClass UNPUBLISHED_NAME    = new NCBITaxonNameClass("unpublished name");
073
074   //**************************************************************************
075   // CONSTRUCTORS
076   //**************************************************************************
077
078   //--------------------------------------------------------------------------
079   private NCBITaxonNameClass(String inName)
080   {
081      mName = inName;
082
083      if (sUniqueMap.containsKey(mName))
084      {
085         throw new RuntimeException("A object already exists with the name '" + mName + "'!");
086      }
087
088      sUniqueMap.put(mName, this);
089
090   }
091
092   //**************************************************************************
093   // PUBLIC METHODS
094   //**************************************************************************
095
096   //--------------------------------------------------------------------------
097   public static Collection<NCBITaxonNameClass> values()
098   {
099      return sUniqueMap.values();
100   }
101
102   //--------------------------------------------------------------------------
103   public static NCBITaxonNameClass valueOf(String inValue)
104   {
105      return sUniqueMap.get(inValue);
106   }
107
108   //--------------------------------------------------------------------------
109   public String name()
110   {
111      return mName;
112   }
113
114   //--------------------------------------------------------------------------
115   /**
116    The same as name().
117    */
118   @Override
119   public String toString()
120   {
121      return name();
122   }
123
124   //**************************************************************************
125   // PRIVATE METHODS
126   //**************************************************************************
127
128   //--------------------------------------------------------------------------
129   /**
130    * This method is called after de-serialization, allowing the object
131    * to nominate a replacement object to be used in the output
132    * graph instead of this object. We don't want multiple objects of each type
133    * to exist in a target VM, so instances replace themselves with
134    * local objects.
135    */
136   private Object readResolve()
137   {
138      return sUniqueMap.get(mName);
139   }
140}