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 levels. 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 GenomicAssemblyLevel implements Serializable, Comparable<GenomicAssemblyLevel> 038{ 039 040 private final String mName; 041 private final int mIndex; 042 043 private static final Set<GenomicAssemblyLevel> sValues = new OrderedSet<>(4); 044 045 public static final GenomicAssemblyLevel COMPLETE_GENOME = new GenomicAssemblyLevel("Complete genome"); 046 public static final GenomicAssemblyLevel CHROMOSOME = new GenomicAssemblyLevel("Chromosome"); 047 public static final GenomicAssemblyLevel SCAFFOLD = new GenomicAssemblyLevel("Scaffold"); 048 public static final GenomicAssemblyLevel CONTIG = new GenomicAssemblyLevel("Contig"); 049 050 //########################################################################### 051 // CONSTRUCTORS 052 //########################################################################### 053 054 //-------------------------------------------------------------------------- 055 private GenomicAssemblyLevel(String inName) 056 { 057 mName = inName; 058 mIndex = sValues.size(); 059 sValues.add(this); 060 } 061 062 //########################################################################### 063 // PUBLIC METHODS 064 //########################################################################### 065 066 //-------------------------------------------------------------------------- 067 @Override 068 public final String toString() 069 { 070 return mName; 071 } 072 073 //-------------------------------------------------------------------------- 074 public static GenomicAssemblyLevel valueOf(String inValue) 075 { 076 GenomicAssemblyLevel outValue = null; 077 078 for (GenomicAssemblyLevel value : sValues) 079 { 080 if (value.toString().equalsIgnoreCase(inValue)) 081 { 082 outValue = value; 083 break; 084 } 085 } 086 087 return outValue; 088 } 089 090 //-------------------------------------------------------------------------- 091 public static GenomicAssemblyLevel[] values() 092 { 093 return sValues.toArray(new GenomicAssemblyLevel[] {}); 094 } 095 096 097 //-------------------------------------------------------------------------- 098 public final String name() 099 { 100 return mName; 101 } 102 103 //-------------------------------------------------------------------------- 104 @Override 105 public final int hashCode() 106 { 107 return mIndex; 108 } 109 110 //-------------------------------------------------------------------------- 111 @Override 112 public final boolean equals(Object inObj) 113 { 114 return (inObj instanceof GenomicAssemblyLevel 115 && mIndex == ((GenomicAssemblyLevel) inObj).mIndex); 116 } 117 118 //-------------------------------------------------------------------------- 119 /** 120 * This method is called after de-serialization, allowing the object 121 * to nominate a replacement object to be used in the output 122 * graph instead of this object. We don't want multiple objects of each type 123 * to exist in a target VM, so instances replace themselves with 124 * local objects. 125 */ 126 private Object readResolve() 127 { 128 GenomicAssemblyLevel outValue = null; 129 130 for (GenomicAssemblyLevel value : sValues) 131 { 132 if (mIndex == value.mIndex) 133 { 134 outValue = value; 135 break; 136 } 137 } 138 139 return outValue; 140 } 141 142 //-------------------------------------------------------------------------- 143 /** 144 * Compares this object with the specified object for order. Returns a 145 * negative integer, zero, or a positive integer as this object is less 146 * than, equal to, or greater than the specified object. 147 * 148 * <p>The implementor must ensure 149 * {@code sgn(x.compareTo(y)) == -sgn(y.compareTo(x))} 150 * for all {@code x} and {@code y}. (This 151 * implies that {@code x.compareTo(y)} must throw an exception iff 152 * {@code y.compareTo(x)} throws an exception.) 153 * 154 * <p>The implementor must also ensure that the relation is transitive: 155 * {@code (x.compareTo(y) > 0 && y.compareTo(z) > 0)} implies 156 * {@code x.compareTo(z) > 0}. 157 * 158 * <p>Finally, the implementor must ensure that {@code x.compareTo(y)==0} 159 * implies that {@code sgn(x.compareTo(z)) == sgn(y.compareTo(z))}, for 160 * all {@code z}. 161 * 162 * <p>It is strongly recommended, but <i>not</i> strictly required that 163 * {@code (x.compareTo(y)==0) == (x.equals(y))}. Generally speaking, any 164 * class that implements the {@code Comparable} interface and violates 165 * this condition should clearly indicate this fact. The recommended 166 * language is "Note: this class has a natural ordering that is 167 * inconsistent with equals." 168 * 169 * <p>In the foregoing description, the notation 170 * {@code sgn(}<i>expression</i>{@code )} designates the mathematical 171 * <i>signum</i> function, which is defined to return one of {@code -1}, 172 * {@code 0}, or {@code 1} according to whether the value of 173 * <i>expression</i> is negative, zero, or positive, respectively. 174 * 175 * @param inObj2 the object to be compared. 176 * @return a negative integer, zero, or a positive integer as this object 177 * is less than, equal to, or greater than the specified object. 178 * @throws ClassCastException if the specified object's type prevents it 179 * from being compared to this object. 180 */ 181 @Override 182 public int compareTo(GenomicAssemblyLevel inObj2) 183 { 184 int result = -1; 185 if (inObj2 != null) 186 { 187 result = CompareUtil.compare(mIndex, inObj2.mIndex); 188 } 189 190 return result; 191 } 192}