001package com.hfg.bio.taxonomy.uniprot;
002
003import com.hfg.bio.taxonomy.SeqRepositoryDivision;
004import com.hfg.util.StringUtil;
005
006import java.util.HashMap;
007import java.util.Map;
008import java.util.Collection;
009import java.io.Serializable;
010
011
012//------------------------------------------------------------------------------
013/**
014 * Enumerated list of EMBL taxonomic divisions.
015 * <div>
016 * Based on ftp://ftp.ebi.ac.uk/pub/databases/embl/doc/usrman.txt
017 * </div>
018 * @author J. Alex Taylor, hairyfatguy.com
019 */
020//------------------------------------------------------------------------------
021// com.hfg XML/HTML Coding Library
022//
023// This library is free software; you can redistribute it and/or
024// modify it under the terms of the GNU Lesser General Public
025// License as published by the Free Software Foundation; either
026// version 2.1 of the License, or (at your option) any later version.
027//
028// This library is distributed in the hope that it will be useful,
029// but WITHOUT ANY WARRANTY; without even the implied warranty of
030// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
031// Lesser General Public License for more details.
032//
033// You should have received a copy of the GNU Lesser General Public
034// License along with this library; if not, write to the Free Software
035// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
036//
037// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
038// jataylor@hairyfatguy.com
039//------------------------------------------------------------------------------
040
041public class EMBL_TaxonDivision implements SeqRepositoryDivision, Serializable
042{
043
044   //**************************************************************************
045   // PRIVATE FIELDS
046   //**************************************************************************
047
048   private String  mName;
049   private String  mCode;
050
051
052   private static Map<String, EMBL_TaxonDivision> sUniqueCodeMap = new HashMap<>(20);
053
054   //**************************************************************************
055   // PUBLIC FIELDS
056   //**************************************************************************
057
058   /** Bacteriophage PHG */
059   public static EMBL_TaxonDivision BACTERIOPHAGE = new EMBL_TaxonDivision("Bacteriophage", "PHG");
060
061   /** Environmental Sample ENV */
062   public static EMBL_TaxonDivision ENVIRONMENTAL_SAMPLE = new EMBL_TaxonDivision("Environmental Sample", "ENV");
063
064   /** Fungal FUN */
065   public static EMBL_TaxonDivision FUNGAL        = new EMBL_TaxonDivision("Fungal", "FUN");
066
067   /** Human HUM */
068   public static EMBL_TaxonDivision HUMAN         = new EMBL_TaxonDivision("Human", "HUM");
069
070   /** Invertebrate INV */
071   public static EMBL_TaxonDivision INVERTEBRATE  = new EMBL_TaxonDivision("Invertebrate", "INV");
072
073   /** Other Mammal MAM */
074   public static EMBL_TaxonDivision OTHER_MAMMAL  = new EMBL_TaxonDivision("Other Mammal", "MAM");
075
076   /** Other Vertebrate VRT */
077   public static EMBL_TaxonDivision OTHER_VERTEBRATE = new EMBL_TaxonDivision("Other Vertebrate", "VRT");
078
079   /** Mus musculus MUS */
080   public static EMBL_TaxonDivision MUS_MUSCULUS  = new EMBL_TaxonDivision("Mus musculus", "Mus");
081
082   /** Plant PLN */
083   public static EMBL_TaxonDivision PLANT         = new EMBL_TaxonDivision("Plant", "PLN");
084
085   /** Prokaryote PRO */
086   public static EMBL_TaxonDivision PROKARYOTE    = new EMBL_TaxonDivision("Prokaryote", "PRO");
087
088   /** Other Rodent ROD */
089   public static EMBL_TaxonDivision OTHER_RODENT  = new EMBL_TaxonDivision("Other Rodent", "ROD");
090
091   /** Synthetic SYN */
092   public static EMBL_TaxonDivision SYNTHETIC     = new EMBL_TaxonDivision("Synthetic", "SYN");
093
094   /** Transgenic TGN */
095   public static EMBL_TaxonDivision TRANSGENIC    = new EMBL_TaxonDivision("Transgenic", "TGN");
096
097   /** Unclassified UNC */
098   public static EMBL_TaxonDivision UNCLASSIFIED  = new EMBL_TaxonDivision("Unclassified", "UNC");
099
100   /** Viral VRL */
101   public static EMBL_TaxonDivision VIRAL         = new EMBL_TaxonDivision("Viral", "VRL");
102
103
104
105   //**************************************************************************
106   // CONSTRUCTORS
107   //**************************************************************************
108
109   //--------------------------------------------------------------------------
110   private EMBL_TaxonDivision(String inName, String inCode)
111   {
112      mName = inName;
113      mCode = inCode;
114
115      if (sUniqueCodeMap.containsKey(mCode))
116      {
117         throw new RuntimeException("A object already exists with the code '" + mCode + "'!");
118      }
119
120      sUniqueCodeMap.put(mCode, this);
121   }
122
123   //**************************************************************************
124   // PUBLIC METHODS
125   //**************************************************************************
126
127   //--------------------------------------------------------------------------
128   public static Collection<EMBL_TaxonDivision> values()
129   {
130      return sUniqueCodeMap.values();
131   }
132
133   //--------------------------------------------------------------------------
134   /**
135    Returns the corresponding EMBL_TaxonDivision by comparing the value to the
136    name and code values of the enumerated set.
137    @param inValue the name or code of the EMBL division to retrieve
138    @return EMBL_TaxonDivision object corresponding to the specified value
139    */
140   public static EMBL_TaxonDivision valueOf(String inValue)
141   {
142      EMBL_TaxonDivision value = null;
143
144      if (StringUtil.isSet(inValue))
145      {
146         for (EMBL_TaxonDivision division : sUniqueCodeMap.values())
147         {
148            if (division.name().equalsIgnoreCase(inValue)
149                || division.getCode().equalsIgnoreCase(inValue))
150            {
151               value = division;
152               break;
153            }
154         }
155      }
156
157      return value;
158   }
159
160   //--------------------------------------------------------------------------
161   public String name()
162   {
163      return mName;
164   }
165
166   //--------------------------------------------------------------------------
167   /**
168    The same as name().
169    */
170   @Override
171   public String toString()
172   {
173      return name();
174   }
175
176   //--------------------------------------------------------------------------
177   /**
178    Returns the 3-letter EMBL division code.
179    @return the 3-letter EMBL division code
180    */
181   public String getCode()
182   {
183      return mCode;
184   }
185
186   //**************************************************************************
187   // PRIVATE METHODS
188   //**************************************************************************
189
190   //--------------------------------------------------------------------------
191   /**
192    * This method is called after de-serialization, allowing the object
193    * to nominate a replacement object to be used in the output
194    * graph instead of this object. We don't want multiple objects of each type
195    * to exist in a target VM, so instances replace themselves with
196    * local objects.
197    */
198   private Object readResolve()
199   {
200      return sUniqueCodeMap.get(mCode + "");
201   }
202}