source: trunk/CrossPare/src/de/ugoe/cs/cpdp/loader/AbstractFolderLoader.java @ 4

Last change on this file since 4 was 4, checked in by sherbold, 10 years ago
  • Property svn:mime-type set to text/plain
File size: 1.7 KB
Line 
1package de.ugoe.cs.cpdp.loader;
2
3import java.io.File;
4import java.util.LinkedList;
5import java.util.List;
6
7import weka.core.Instances;
8
9import 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 */
18public 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}
Note: See TracBrowser for help on using the repository browser.