001package com.hfg.bio.seq;
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 * Enumeration of sequence topology types
014 * <div>
015 * @author J. Alex Taylor, hairyfatguy.com
016 * </div>
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 SeqTopology implements Serializable
040{
041
042   //**************************************************************************
043   // PRIVATE FIELDS
044   //**************************************************************************
045
046   private String  mName;
047
048
049   private static Map<String, SeqTopology> sUniqueValueMap = new HashMap<>(4);
050
051   //**************************************************************************
052   // PUBLIC FIELDS
053   //**************************************************************************
054
055   public static SeqTopology LINEAR   = new SeqTopology("linear");
056   public static SeqTopology CIRCULAR = new SeqTopology("circular");
057
058   //**************************************************************************
059   // CONSTRUCTORS
060   //**************************************************************************
061
062   //--------------------------------------------------------------------------
063   private SeqTopology(String inName)
064   {
065      mName = inName;
066
067      if (sUniqueValueMap.containsKey(mName))
068      {
069         throw new RuntimeException("A object already exists with the name '" + mName + "'!");
070      }
071
072      sUniqueValueMap.put(mName, this);
073   }
074
075   //**************************************************************************
076   // PUBLIC METHODS
077   //**************************************************************************
078
079   //--------------------------------------------------------------------------
080   public static Collection<SeqTopology> values()
081   {
082      return sUniqueValueMap.values();
083   }
084
085   //--------------------------------------------------------------------------
086   /**
087    Returns the corresponding SeqTopology by comparing the value to the
088    names in the enumerated set.
089    @param inValue the name of the sequence topology to retrieve
090    @return SeqTopology object corresponding to the specified value
091    */
092   public static SeqTopology valueOf(String inValue)
093   {
094      SeqTopology value = null;
095
096      if (StringUtil.isSet(inValue))
097      {
098         for (SeqTopology obj : sUniqueValueMap.values())
099         {
100            if (obj.name().equalsIgnoreCase(inValue))
101            {
102               value = obj;
103               break;
104            }
105         }
106      }
107
108      return value;
109   }
110
111   //--------------------------------------------------------------------------
112   public String name()
113   {
114      return mName;
115   }
116
117   //--------------------------------------------------------------------------
118   /**
119    The same as name().
120    */
121   @Override
122   public String toString()
123   {
124      return name();
125   }
126
127   //**************************************************************************
128   // PRIVATE METHODS
129   //**************************************************************************
130
131   //--------------------------------------------------------------------------
132   /**
133    * This method is called after de-serialization, allowing the object
134    * to nominate a replacement object to be used in the output
135    * graph instead of this object. We don't want multiple objects of each type
136    * to exist in a target VM, so instances replace themselves with
137    * local objects.
138    */
139   private Object readResolve()
140   {
141      return sUniqueValueMap.get(mName + "");
142   }
143}