001package com.hfg.bio.seq.format; 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 data class. 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// jataylor@hairyfatguy.com 038//------------------------------------------------------------------------------ 039 040public class EMBL_DataClass implements 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_DataClass> sUniqueCodeMap = new HashMap<>(20); 052 053 //************************************************************************** 054 // PUBLIC FIELDS 055 //************************************************************************** 056 057 /** Constructed CON */ 058 public static EMBL_DataClass CONSTRUCTED = new EMBL_DataClass("Constructed", "CON"); 059 060 /** Patent PAT */ 061 public static EMBL_DataClass PATENT = new EMBL_DataClass("Patent", "PAT"); 062 063 /** Expressed Sequence Tag EST */ 064 public static EMBL_DataClass EST = new EMBL_DataClass("Expressed Sequence Tag", "EST"); 065 066 /** Genome Survey Sequence GSS */ 067 public static EMBL_DataClass GSS = new EMBL_DataClass("Genome Survey Sequence", "GSS"); 068 069 /** High Throughput cDNA sequencing HTC */ 070 public static EMBL_DataClass HTC = new EMBL_DataClass("High Throughput cDNA sequencing", "HTC"); 071 072 /** High Throughput Genome sequencing HTC */ 073 public static EMBL_DataClass HTG = new EMBL_DataClass("High Throughput Genome sequencing", "HTG"); 074 075 /** Mass Genome Annotation MGA */ 076 public static EMBL_DataClass MGA = new EMBL_DataClass("Mass Genome Annotation", "MGA"); 077 078 /** Whole Genome Shotgun WGS */ 079 public static EMBL_DataClass WGS = new EMBL_DataClass("Whole Genome Shotgun", "WGS"); 080 081 /** Transcriptome Shotgun Assembly TSA*/ 082 public static EMBL_DataClass TSA = new EMBL_DataClass("Transcriptome Shotgun Assembly", "TSA"); 083 084 /** Sequence Tagged Site */ 085 public static EMBL_DataClass STS = new EMBL_DataClass("Sequence Tagged Site", "STS"); 086 087 /** Standard STD */ 088 public static EMBL_DataClass STANDARD = new EMBL_DataClass("Standard", "STD"); 089 090 091 //************************************************************************** 092 // CONSTRUCTORS 093 //************************************************************************** 094 095 //-------------------------------------------------------------------------- 096 private EMBL_DataClass(String inName, String inCode) 097 { 098 mName = inName; 099 mCode = inCode; 100 101 if (sUniqueCodeMap.containsKey(mCode)) 102 { 103 throw new RuntimeException("A object already exists with the code '" + mCode + "'!"); 104 } 105 106 sUniqueCodeMap.put(mCode, this); 107 } 108 109 //************************************************************************** 110 // PUBLIC METHODS 111 //************************************************************************** 112 113 //-------------------------------------------------------------------------- 114 public static Collection<EMBL_DataClass> values() 115 { 116 return sUniqueCodeMap.values(); 117 } 118 119 //-------------------------------------------------------------------------- 120 /** 121 Returns the corresponding EMBL_DataClass by comparing the value to the 122 name and code values of the enumerated set. 123 @param inValue the name or code of the EMBL data class to retrieve 124 @return EMBL_DataClass object corresponding to the specified value 125 */ 126 public static EMBL_DataClass valueOf(String inValue) 127 { 128 EMBL_DataClass value = null; 129 130 if (StringUtil.isSet(inValue)) 131 { 132 for (EMBL_DataClass dataClass : sUniqueCodeMap.values()) 133 { 134 if (dataClass.name().equalsIgnoreCase(inValue) 135 || dataClass.getCode().equalsIgnoreCase(inValue)) 136 { 137 value = dataClass; 138 break; 139 } 140 } 141 } 142 143 return value; 144 } 145 146 //-------------------------------------------------------------------------- 147 public String name() 148 { 149 return mName; 150 } 151 152 //-------------------------------------------------------------------------- 153 /** 154 The same as name(). 155 */ 156 @Override 157 public String toString() 158 { 159 return name(); 160 } 161 162 //-------------------------------------------------------------------------- 163 /** 164 Returns the 3-letter EMBL data class code. 165 @return the 3-letter EMBL data class code 166 */ 167 public String getCode() 168 { 169 return mCode; 170 } 171 172 //************************************************************************** 173 // PRIVATE METHODS 174 //************************************************************************** 175 176 //-------------------------------------------------------------------------- 177 /** 178 * This method is called after de-serialization, allowing the object 179 * to nominate a replacement object to be used in the output 180 * graph instead of this object. We don't want multiple objects of each type 181 * to exist in a target VM, so instances replace themselves with 182 * local objects. 183 */ 184 private Object readResolve() 185 { 186 return sUniqueCodeMap.get(mCode + ""); 187 } 188}