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

Last change on this file since 42 was 41, checked in by sherbold, 9 years ago
  • formatted code and added copyrights
  • Property svn:mime-type set to text/plain
File size: 2.6 KB
Line 
1// Copyright 2015 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.cpdp.loader;
16
17import java.io.File;
18import java.util.LinkedList;
19import java.util.List;
20
21import weka.core.Instances;
22
23import de.ugoe.cs.cpdp.versions.SoftwareVersion;
24
25/**
26 * Abstract class for loading data from a folder. The subfolders of a defined folder define the
27 * projects, the file contained in the subfolder are the versions of a project.
28 *
29 * @author Steffen Herbold
30 */
31public abstract class AbstractFolderLoader implements IVersionLoader {
32
33    /**
34     * Path of the data.
35     */
36    protected String path = "";
37
38    /**
39     * @see de.ugoe.cs.cpdp.loader.IVersionLoader#setLocation(java.lang.String)
40     */
41    @Override
42    public void setLocation(String location) {
43        path = location;
44    }
45
46    /**
47     * @see de.ugoe.cs.cpdp.loader.IVersionLoader#load()
48     */
49    @Override
50    public List<SoftwareVersion> load() {
51        final List<SoftwareVersion> versions = new LinkedList<SoftwareVersion>();
52
53        final File dataDir = new File(path);
54        final SingleVersionLoader instancesLoader = getSingleLoader();
55
56        for (File projectDir : dataDir.listFiles()) {
57            if (projectDir.isDirectory()) {
58                String projectName = projectDir.getName();
59                for (File versionFile : projectDir.listFiles()) {
60                    if (versionFile.isFile() &&
61                        instancesLoader.filenameFilter(versionFile.getName()))
62                    {
63                        String versionName = versionFile.getName();
64                        Instances data = instancesLoader.load(versionFile);
65                        versions.add(new SoftwareVersion(projectName, versionName, data));
66                    }
67                }
68            }
69        }
70        return versions;
71    }
72
73    /**
74     * Returns the concrete {@link SingleVersionLoader} to be used with this folder loader.
75     *
76     * @return
77     */
78    abstract protected SingleVersionLoader getSingleLoader();
79}
Note: See TracBrowser for help on using the repository browser.