001         package com.croftsoft.core.util.filemap;
002    
003         import java.io.*;
004         import java.util.*;
005    
006         /*********************************************************************
007         * This Map.Entry is required for the AbstractMap implementation of
008         * FileMap.
009         *
010         * @see
011         *   FileMapEntryIterator
012         * @see
013         *   FileMapEntrySet
014         * @see
015         *   java.util.Map.Entry
016         *
017         * @version
018         *   1999-04-03
019         * @author
020         *   <a href="https://www.croftsoft.com/">David Wallace Croft</a>
021         *********************************************************************/
022    
023         public class  FileMapEntry implements Map.Entry
024         //////////////////////////////////////////////////////////////////////
025         //////////////////////////////////////////////////////////////////////
026         {
027    
028         private File    rootDirectory;
029         private String  filename;
030    
031         //////////////////////////////////////////////////////////////////////
032         //////////////////////////////////////////////////////////////////////
033    
034         public  FileMapEntry ( File  rootDirectory, String  filename )
035         //////////////////////////////////////////////////////////////////////
036         {
037           this.rootDirectory = rootDirectory;
038           this.filename      = filename;
039         }
040    
041         //////////////////////////////////////////////////////////////////////
042         //////////////////////////////////////////////////////////////////////
043    
044         public boolean  equals ( Object  o )
045         //////////////////////////////////////////////////////////////////////
046         {
047           if ( o == null ) return false;
048    
049           if ( !o.getClass ( ).equals ( this.getClass ( ) ) ) return false;
050    
051           FileMapEntry  other = ( FileMapEntry ) o;
052    
053           if ( !filename.equals ( other.filename ) ) return false;
054    
055           if ( !rootDirectory.equals ( other.rootDirectory ) ) return false;
056    
057           if ( hashCode ( ) != other.hashCode ( ) ) return false;
058    
059           return true;
060         }
061    
062         public Object  getKey ( )
063         //////////////////////////////////////////////////////////////////////
064         {
065           return filename;
066         }
067    
068         public Object  getValue ( )
069         //////////////////////////////////////////////////////////////////////
070         {
071           try
072           {
073             return new FileInputStream (
074               new File ( rootDirectory, filename ) );
075           }
076           catch ( FileNotFoundException  ex )
077           {
078             return null;
079           }
080         }
081    
082         public int  hashCode ( )
083         //////////////////////////////////////////////////////////////////////
084         {
085           return filename.hashCode ( );
086         }
087    
088         public Object  setValue ( Object  value )
089         //////////////////////////////////////////////////////////////////////
090         {
091           throw new UnsupportedOperationException ( );
092         }
093    
094         //////////////////////////////////////////////////////////////////////
095         //////////////////////////////////////////////////////////////////////
096         }