001         package com.croftsoft.core.util.id;
002    
003         import com.croftsoft.core.lang.NullArgumentException;
004    
005         /*********************************************************************
006         * An Id implementation backed by a String.
007         *
008         * @version
009         *   $Id: StringId.java,v 1.3 2008/09/20 05:11:34 croft Exp $
010         * @since
011         *   2000-01-16
012         * @author
013         *   <a href="https://www.croftsoft.com/">David Wallace Croft</a>
014         *********************************************************************/
015    
016         public class  StringId
017           implements Id
018         //////////////////////////////////////////////////////////////////////
019         //////////////////////////////////////////////////////////////////////
020         {
021    
022         private static final long  serialVersionUID = 0L;
023    
024         //
025    
026         private final String  s;
027    
028         //////////////////////////////////////////////////////////////////////
029         // constructor method
030         //////////////////////////////////////////////////////////////////////
031    
032         /*********************************************************************
033         * Main constructor.
034         *
035         * @throws NullArgumentException
036         *
037         *   If argument is null.
038         *********************************************************************/
039         public  StringId ( String  s )
040         //////////////////////////////////////////////////////////////////////
041         {
042           NullArgumentException.check ( this.s = s );
043         }
044    
045         //////////////////////////////////////////////////////////////////////
046         // accessor method
047         //////////////////////////////////////////////////////////////////////
048    
049         public String  getS ( ) { return s; }
050    
051         //////////////////////////////////////////////////////////////////////
052         // Id interface methods
053         //////////////////////////////////////////////////////////////////////
054    
055         @Override
056         public boolean  equals ( Object  other )
057         //////////////////////////////////////////////////////////////////////
058         {
059           if ( other == null ) return false;
060    
061           if ( !getClass ( ).equals ( other.getClass ( ) ) ) return false;
062    
063           return s.equals ( ( ( StringId ) other ).s );
064         }
065    
066         @Override
067         public int  hashCode ( )
068         //////////////////////////////////////////////////////////////////////
069         {
070           return s.hashCode ( );
071         }
072    
073         @Override
074         public Object  clone ( )
075         //////////////////////////////////////////////////////////////////////
076         {
077           try
078           {
079             return super.clone ( );
080           }
081           catch ( CloneNotSupportedException  ex )
082           {
083             // This will never happen.
084    
085             throw new RuntimeException ( );
086           }
087         }
088    
089         //////////////////////////////////////////////////////////////////////
090         // Other methods
091         //////////////////////////////////////////////////////////////////////
092    
093         /*********************************************************************
094         * return s;
095         *********************************************************************/
096         @Override
097         public String  toString ( )
098         //////////////////////////////////////////////////////////////////////
099         {
100           return s;
101         }
102    
103         //////////////////////////////////////////////////////////////////////
104         //////////////////////////////////////////////////////////////////////
105         }