001package com.hfg.bio.seq.genomic.assembly;
002
003import java.io.Serializable;
004import java.util.Set;
005
006import com.hfg.util.collection.OrderedSet;
007
008//------------------------------------------------------------------------------
009/**
010 * Enumeration of genomic paired assembly comparison types.
011 * <div>
012 * @author J. Alex Taylor, hairyfatguy.com
013 * </div>
014 */
015//------------------------------------------------------------------------------
016// com.hfg XML/HTML Coding Library
017//
018// This library is free software; you can redistribute it and/or
019// modify it under the terms of the GNU Lesser General Public
020// License as published by the Free Software Foundation; either
021// version 2.1 of the License, or (at your option) any later version.
022//
023// This library is distributed in the hope that it will be useful,
024// but WITHOUT ANY WARRANTY; without even the implied warranty of
025// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
026// Lesser General Public License for more details.
027//
028// You should have received a copy of the GNU Lesser General Public
029// License along with this library; if not, write to the Free Software
030// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
031//
032// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
033// jataylor@hairyfatguy.com
034//------------------------------------------------------------------------------
035
036public final class GenomicPairedAssemblyComparison implements Serializable
037{
038
039   private final String mName;
040   private final int    mIndex;
041
042   private static final Set<GenomicPairedAssemblyComparison> sValues = new OrderedSet<>(3);
043
044   public static final GenomicPairedAssemblyComparison IDENTICAL = new GenomicPairedAssemblyComparison("identical");
045   public static final GenomicPairedAssemblyComparison DIFFERENT = new GenomicPairedAssemblyComparison("different");
046   public static final GenomicPairedAssemblyComparison NA        = new GenomicPairedAssemblyComparison("na");
047
048   //###########################################################################
049   // CONSTRUCTORS
050   //###########################################################################
051
052   //--------------------------------------------------------------------------
053   private GenomicPairedAssemblyComparison(String inName)
054   {
055      mName = inName;
056      mIndex = sValues.size();
057      sValues.add(this);
058   }
059
060   //###########################################################################
061   // PUBLIC METHODS
062   //###########################################################################
063
064   //--------------------------------------------------------------------------
065   @Override
066   public final String toString()
067   {
068      return mName;
069   }
070
071   //--------------------------------------------------------------------------
072   public static GenomicPairedAssemblyComparison valueOf(String inValue)
073   {
074      GenomicPairedAssemblyComparison outValue = null;
075
076      for (GenomicPairedAssemblyComparison value : sValues)
077      {
078         if (value.toString().equalsIgnoreCase(inValue))
079         {
080            outValue = value;
081            break;
082         }
083      }
084
085      return outValue;
086   }
087
088   //--------------------------------------------------------------------------
089   public static GenomicPairedAssemblyComparison[] values()
090   {
091      return sValues.toArray(new GenomicPairedAssemblyComparison[] {});
092   }
093
094
095   //--------------------------------------------------------------------------
096   public final String name()
097   {
098      return mName;
099   }
100
101   //--------------------------------------------------------------------------
102   @Override
103   public final int hashCode()
104   {
105      return mIndex;
106   }
107
108   //--------------------------------------------------------------------------
109   @Override
110   public final boolean equals(Object inObj)
111   {
112      return (inObj instanceof GenomicPairedAssemblyComparison
113              && mIndex == ((GenomicPairedAssemblyComparison) inObj).mIndex);
114   }
115
116   //--------------------------------------------------------------------------
117   /**
118    * This method is called after de-serialization, allowing the object
119    * to nominate a replacement object to be used in the output
120    * graph instead of this object. We don't want multiple objects of each type
121    * to exist in a target VM, so instances replace themselves with
122    * local objects.
123    */
124   private Object readResolve()
125   {
126      GenomicPairedAssemblyComparison outValue = null;
127
128      for (GenomicPairedAssemblyComparison value : sValues)
129      {
130         if (mIndex == value.mIndex)
131         {
132            outValue = value;
133            break;
134         }
135      }
136
137      return outValue;
138   }
139}