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