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 | * Abstract class for loading data from a folder. The subfolders of a defined
|
---|
13 | * folder define the projects, the file contained in the subfolder are the
|
---|
14 | * versions of a project.
|
---|
15 | *
|
---|
16 | * @author Steffen Herbold
|
---|
17 | */
|
---|
18 | public abstract class AbstractFolderLoader implements IVersionLoader {
|
---|
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()
|
---|
48 | && instancesLoader.filenameFilter(versionFile
|
---|
49 | .getName())) {
|
---|
50 | String versionName = versionFile.getName();
|
---|
51 | Instances data = instancesLoader.load(versionFile);
|
---|
52 | versions.add(new SoftwareVersion(projectName,
|
---|
53 | versionName, data));
|
---|
54 | }
|
---|
55 | }
|
---|
56 | }
|
---|
57 | }
|
---|
58 | return versions;
|
---|
59 | }
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Returns the concrete {@link SingleVersionLoader} to be used with this
|
---|
63 | * folder loader.
|
---|
64 | *
|
---|
65 | * @return
|
---|
66 | */
|
---|
67 | abstract protected SingleVersionLoader getSingleLoader();
|
---|
68 | }
|
---|