001 package com.croftsoft.core.util.state; 002 003 /********************************************************************* 004 * 005 * Static methods to support concrete implementations of the State 006 * interface. 007 * 008 * <P> 009 * 010 * Reference:<BR> 011 * Mark Roulo, 012 * <A HREF="http://www.javaworld.com/javaworld/jw-01-1999/jw-01-object.html"> 013 * "How to avoid traps and correctly override methods 014 * from java.lang.Object"</A>, January 1999, JavaWorld. 015 * 016 * <P> 017 * 018 * @author 019 * <a href="https://www.croftsoft.com/">David Wallace Croft</a> 020 * @version 021 * 1999-02-06 022 *********************************************************************/ 023 024 public class StateLib 025 ////////////////////////////////////////////////////////////////////// 026 ////////////////////////////////////////////////////////////////////// 027 { 028 029 private StateLib ( ) { } 030 031 /********************************************************************* 032 * Returns true if the classes and State keys are equal. 033 * 034 * State implementation usage: 035 * <PRE> 036 * public boolean equals ( Object other ) 037 * { 038 * return StateLib.equals ( this, other ); 039 * } 040 * </PRE> 041 *********************************************************************/ 042 public static boolean equals ( State state, Object other ) 043 ////////////////////////////////////////////////////////////////////// 044 { 045 if ( state == null ) 046 { 047 throw new IllegalArgumentException ( "null state" ); 048 } 049 050 if ( ( other == null ) 051 || !other.getClass ( ).equals ( state.getClass ( ) ) ) 052 { 053 return false; 054 } 055 056 return state.getKey ( ).equals ( ( ( State ) other ).getKey ( ) ); 057 } 058 059 /********************************************************************* 060 * Returns the hash code of the State key. 061 * 062 * <PRE> 063 * return state.getKey ( ).hashCode ( ); 064 * </PRE> 065 * 066 * State implementation usage: 067 * <PRE> 068 * public int hashCode ( ) 069 * { 070 * return StateLib.hashCode ( this ); 071 * } 072 * </PRE> 073 *********************************************************************/ 074 public static int hashCode ( State state ) 075 ////////////////////////////////////////////////////////////////////// 076 { 077 return state.getKey ( ).hashCode ( ); 078 } 079 080 ////////////////////////////////////////////////////////////////////// 081 ////////////////////////////////////////////////////////////////////// 082 }