KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > importscrubber > FilePair


1 package net.sourceforge.importscrubber;
2
3 import java.io.File JavaDoc;
4 import java.io.FilenameFilter JavaDoc;
5 import java.util.*;
6
7 /**
8  * This class encapsulates the source & class files
9  */

10 public class FilePair
11 {
12
13     /**
14      * A filter which only accepts inner classes.
15      */

16     private class InnerClassFilter implements FilenameFilter JavaDoc
17     {
18         public boolean accept(File JavaDoc dir, String JavaDoc name)
19         {
20             // make sure we only get inner classes
21
if (name.indexOf("$") == -1) {
22                 return false;
23             }
24             // make sure we get this class's inner classes
25
String JavaDoc className = _classFile.getName();
26             className = className.substring(0, className.indexOf("."));
27             return name.startsWith(className);
28         }
29     }
30     private File JavaDoc _sourceFile;
31     private File JavaDoc _classFile;
32
33     /**
34      *
35      * @param sourceFile
36      * @param classFile
37      */

38     public FilePair(File JavaDoc sourceFile, File JavaDoc classFile)
39     {
40         _sourceFile = sourceFile;
41         _classFile = classFile;
42     }
43
44     public File JavaDoc getSourceFile()
45     {
46         return _sourceFile;
47     }
48
49     public ListIterator getClassFiles()
50     {
51         List files = new ArrayList();
52         files.add(_classFile);
53         if (_classFile.getParent() != null) {
54             File JavaDoc dir = new File JavaDoc(_classFile.getParent());
55             files.addAll(Arrays.asList(dir.listFiles(new InnerClassFilter())));
56         }
57         return files.listIterator();
58     }
59
60     public int hashCode()
61     {
62         return _sourceFile.hashCode();
63     }
64
65     public boolean equals(Object JavaDoc o)
66     {
67         return o instanceof FilePair
68                && ((FilePair)o).getSourceFile().compareTo(_sourceFile) == 0;
69     }
70
71     public String JavaDoc toString()
72     {
73         return _sourceFile.getAbsolutePath();
74     }
75 }
76
Popular Tags