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