Skip to content

Package: PackageReader$1

PackageReader$1

nameinstructionbranchcomplexitylinemethod
accept(File, String)
M: 21 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
{...}
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /**
2: *
3: */
4: package reader;
5:
6: import java.io.File;
7: import java.io.FilenameFilter;
8: import java.util.HashMap;
9: import java.util.Map;
10:
11: /**
12: * @author Phil
13: *
14: */
15: public final class PackageReader {
16:         /**
17:          * private constructor.
18:          */
19:         private PackageReader() {
20:         }
21:
22:         /**
23:          * Finds files in a directory with a specified file ending.
24:          *
25:          * @param pathToFiles
26:          * The directory where the files are to be found.
27:          * @param ending
28:          * The file ending the files need to have.
29:          * @return A list of the files found.
30:          */
31:         public static Map<String, File> readFiles(final String pathToFiles, final String ending) {
32:                 final int endingLen = ending.length();
33:                 final Map<String, File> result = new HashMap<String, File>();
34:                 final File[] files = new File(pathToFiles).listFiles(new FilenameFilter() {
35:                         @Override
36:                         public boolean accept(final File d, final String name) {
37:•                                return name.endsWith(ending) || name.endsWith(ending + ".unix");
38:                         }
39:                 });
40:                 if (files != null) {
41:                         for (final File file : files) {
42:                                 final String name = file.getName();
43:                                 result.put(name.substring(0, name.length() - endingLen), file);
44:                         }
45:                 }
46:                 return result;
47:         }
48:
49: }