1 | package de.ugoe.cs.cpdp.loader;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.util.LinkedList;
|
---|
5 | import java.util.List;
|
---|
6 |
|
---|
7 | import weka.core.Instances;
|
---|
8 |
|
---|
9 | import de.ugoe.cs.cpdp.versions.SoftwareVersion;
|
---|
10 |
|
---|
11 |
|
---|
12 | public abstract class AbstractFolderLoader implements IVersionLoader {
|
---|
13 |
|
---|
14 | // TODO
|
---|
15 | interface SingleVersionLoader {
|
---|
16 | Instances load(File file);
|
---|
17 | boolean filenameFilter(String filename);
|
---|
18 | }
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Path of the data.
|
---|
22 | */
|
---|
23 | private String path = "";
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * @see de.ugoe.cs.cpdp.loader.IVersionLoader#setLocation(java.lang.String)
|
---|
27 | */
|
---|
28 | @Override
|
---|
29 | public void setLocation(String location) {
|
---|
30 | path=location;
|
---|
31 | }
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * @see de.ugoe.cs.cpdp.loader.IVersionLoader#load()
|
---|
35 | */
|
---|
36 | @Override
|
---|
37 | public List<SoftwareVersion> load() {
|
---|
38 | final List<SoftwareVersion> versions = new LinkedList<SoftwareVersion>();
|
---|
39 |
|
---|
40 | final File dataDir = new File(path);
|
---|
41 | final SingleVersionLoader instancesLoader = getSingleLoader();
|
---|
42 |
|
---|
43 | for( File projectDir : dataDir.listFiles() ) {
|
---|
44 | if( projectDir.isDirectory() ) {
|
---|
45 | String projectName = projectDir.getName();
|
---|
46 | for( File versionFile : projectDir.listFiles() ) {
|
---|
47 | if( versionFile.isFile() && instancesLoader.filenameFilter(versionFile.getName()) ) {
|
---|
48 | String versionName = versionFile.getName();
|
---|
49 | Instances data = instancesLoader.load(versionFile);
|
---|
50 | versions.add(new SoftwareVersion(projectName, versionName, data));
|
---|
51 | }
|
---|
52 | }
|
---|
53 | }
|
---|
54 | }
|
---|
55 | return versions;
|
---|
56 | }
|
---|
57 |
|
---|
58 | abstract protected SingleVersionLoader getSingleLoader();
|
---|
59 | }
|
---|