001package com.hfg.graphics; 002 003import java.io.Serializable; 004import java.util.Set; 005 006import com.hfg.util.collection.OrderedSet; 007 008//------------------------------------------------------------------------------ 009/** 010 * Enumeration of border 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 BorderType implements Serializable 037{ 038 039 private String mName; 040 private int mIndex; 041 042 private static Set<BorderType> sValues = new OrderedSet<>(4); 043 044 public static final BorderType TOP = new BorderType("top"); 045 public static final BorderType LEFT = new BorderType("left"); 046 public static final BorderType RIGHT = new BorderType("right"); 047 public static final BorderType BOTTOM = new BorderType("bottom"); 048 049 //########################################################################### 050 // CONSTRUCTORS 051 //########################################################################### 052 053 //-------------------------------------------------------------------------- 054 private BorderType(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 BorderType valueOf(String inValue) 074 { 075 BorderType outValue = null; 076 077 for (BorderType 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 BorderType[] values() 091 { 092 return sValues.toArray(new BorderType[] {}); 093 } 094 095 096 //-------------------------------------------------------------------------- 097 @Override 098 public final int hashCode() 099 { 100 return mIndex; 101 } 102 103 //-------------------------------------------------------------------------- 104 @Override 105 public final boolean equals(Object inObj) 106 { 107 BorderType o2 = (BorderType) inObj; 108 return (mIndex == o2.mIndex); 109 } 110 111 //-------------------------------------------------------------------------- 112 /** 113 * This method is called after de-serialization, allowing the object 114 * to nominate a replacement object to be used in the output 115 * graph instead of this object. We don't want multiple objects of each type 116 * to exist in a target VM, so instances replace themselves with 117 * local objects. 118 */ 119 private Object readResolve() 120 { 121 BorderType outValue = null; 122 123 for (BorderType value : sValues) 124 { 125 if (mIndex == value.mIndex) 126 { 127 outValue = value; 128 break; 129 } 130 } 131 132 return outValue; 133 } 134}