001package com.hfg.bio.seq.genomic.assembly; 002 003import java.io.Serializable; 004import java.util.Set; 005 006import com.hfg.util.CompareUtil; 007import com.hfg.util.collection.OrderedSet; 008 009//------------------------------------------------------------------------------ 010/** 011 * Enumeration of genomic assembly version status values. 012 * <div> 013 * @author J. Alex Taylor, hairyfatguy.com 014 * </div> 015 */ 016//------------------------------------------------------------------------------ 017// com.hfg XML/HTML Coding Library 018// 019// This library is free software; you can redistribute it and/or 020// modify it under the terms of the GNU Lesser General Public 021// License as published by the Free Software Foundation; either 022// version 2.1 of the License, or (at your option) any later version. 023// 024// This library is distributed in the hope that it will be useful, 025// but WITHOUT ANY WARRANTY; without even the implied warranty of 026// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 027// Lesser General Public License for more details. 028// 029// You should have received a copy of the GNU Lesser General Public 030// License along with this library; if not, write to the Free Software 031// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 032// 033// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 034// jataylor@hairyfatguy.com 035//------------------------------------------------------------------------------ 036 037public final class GenomicAssemblyVersionStatus implements Serializable, Comparable<GenomicAssemblyVersionStatus> 038{ 039 040 private final String mName; 041 private final int mIndex; 042 043 private static final Set<GenomicAssemblyVersionStatus> sValues = new OrderedSet<>(3); 044 045 public static final GenomicAssemblyVersionStatus LATEST = new GenomicAssemblyVersionStatus("latest"); 046 public static final GenomicAssemblyVersionStatus REPLACED = new GenomicAssemblyVersionStatus("replaced"); 047 public static final GenomicAssemblyVersionStatus SUPPRESSED = new GenomicAssemblyVersionStatus("suppressed"); 048 049 //########################################################################### 050 // CONSTRUCTORS 051 //########################################################################### 052 053 //-------------------------------------------------------------------------- 054 private GenomicAssemblyVersionStatus(String inName) 055 { 056 mName = inName; 057 mIndex = sValues.size(); 058 sValues.add(this); 059 } 060 061 //########################################################################### 062 // PUBLIC METHODS 063 //########################################################################### 064 065 //-------------------------------------------------------------------------- 066 @Override 067 public final String toString() 068 { 069 return mName; 070 } 071 072 //-------------------------------------------------------------------------- 073 public static GenomicAssemblyVersionStatus valueOf(String inValue) 074 { 075 GenomicAssemblyVersionStatus outValue = null; 076 077 for (GenomicAssemblyVersionStatus value : sValues) 078 { 079 if (value.toString().equalsIgnoreCase(inValue)) 080 { 081 outValue = value; 082 break; 083 } 084 } 085 086 return outValue; 087 } 088 089 //-------------------------------------------------------------------------- 090 public static GenomicAssemblyVersionStatus[] values() 091 { 092 return sValues.toArray(new GenomicAssemblyVersionStatus[] {}); 093 } 094 095 096 //-------------------------------------------------------------------------- 097 public final String name() 098 { 099 return mName; 100 } 101 102 //-------------------------------------------------------------------------- 103 @Override 104 public final int hashCode() 105 { 106 return mIndex; 107 } 108 109 //-------------------------------------------------------------------------- 110 @Override 111 public final boolean equals(Object inObj) 112 { 113 return (inObj instanceof GenomicAssemblyVersionStatus 114 && mIndex == ((GenomicAssemblyVersionStatus) inObj).mIndex); 115 } 116 117 //-------------------------------------------------------------------------- 118 /** 119 * This method is called after de-serialization, allowing the object 120 * to nominate a replacement object to be used in the output 121 * graph instead of this object. We don't want multiple objects of each type 122 * to exist in a target VM, so instances replace themselves with 123 * local objects. 124 */ 125 private Object readResolve() 126 { 127 GenomicAssemblyVersionStatus outValue = null; 128 129 for (GenomicAssemblyVersionStatus value : sValues) 130 { 131 if (mIndex == value.mIndex) 132 { 133 outValue = value; 134 break; 135 } 136 } 137 138 return outValue; 139 } 140 141 //-------------------------------------------------------------------------- 142 /** 143 * Compares this object with the specified object for order. Returns a 144 * negative integer, zero, or a positive integer as this object is less 145 * than, equal to, or greater than the specified object. 146 * 147 * <p>The implementor must ensure 148 * {@code sgn(x.compareTo(y)) == -sgn(y.compareTo(x))} 149 * for all {@code x} and {@code y}. (This 150 * implies that {@code x.compareTo(y)} must throw an exception iff 151 * {@code y.compareTo(x)} throws an exception.) 152 * 153 * <p>The implementor must also ensure that the relation is transitive: 154 * {@code (x.compareTo(y) > 0 && y.compareTo(z) > 0)} implies 155 * {@code x.compareTo(z) > 0}. 156 * 157 * <p>Finally, the implementor must ensure that {@code x.compareTo(y)==0} 158 * implies that {@code sgn(x.compareTo(z)) == sgn(y.compareTo(z))}, for 159 * all {@code z}. 160 * 161 * <p>It is strongly recommended, but <i>not</i> strictly required that 162 * {@code (x.compareTo(y)==0) == (x.equals(y))}. Generally speaking, any 163 * class that implements the {@code Comparable} interface and violates 164 * this condition should clearly indicate this fact. The recommended 165 * language is "Note: this class has a natural ordering that is 166 * inconsistent with equals." 167 * 168 * <p>In the foregoing description, the notation 169 * {@code sgn(}<i>expression</i>{@code )} designates the mathematical 170 * <i>signum</i> function, which is defined to return one of {@code -1}, 171 * {@code 0}, or {@code 1} according to whether the value of 172 * <i>expression</i> is negative, zero, or positive, respectively. 173 * 174 * @param inObj2 the object to be compared. 175 * @return a negative integer, zero, or a positive integer as this object 176 * is less than, equal to, or greater than the specified object. 177 * @throws ClassCastException if the specified object's type prevents it 178 * from being compared to this object. 179 */ 180 @Override 181 public int compareTo(GenomicAssemblyVersionStatus inObj2) 182 { 183 int result = -1; 184 if (inObj2 != null) 185 { 186 result = CompareUtil.compare(mIndex, inObj2.mIndex); 187 } 188 189 return result; 190 } 191}