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

Last change on this file since 86 was 86, checked in by sherbold, 8 years ago
  • switched workspace encoding to UTF-8 and fixed broken characters
  • Property svn:mime-type set to text/plain
File size: 2.8 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        if (dataDir.listFiles() == null) {
56            return versions;
57        }
58        for (File projectDir : dataDir.listFiles()) {
59            if (projectDir.isDirectory()) {
60                String projectName = projectDir.getName();
61                if (projectDir.listFiles() != null) {
62                    for (File versionFile : projectDir.listFiles()) {
63                        if (versionFile.isFile() &&
64                            instancesLoader.filenameFilter(versionFile.getName()))
65                        {
66                            Instances data = instancesLoader.load(versionFile);
67                            String versionName = data.relationName();
68                            versions.add(new SoftwareVersion(projectName, versionName, data));
69                        }
70                    }
71                }
72            }
73        }
74        return versions;
75    }
76
77    /**
78     * Returns the concrete {@link SingleVersionLoader} to be used with this folder loader.
79     *
80     * @return
81     */
82    abstract protected SingleVersionLoader getSingleLoader();
83}
Note: See TracBrowser for help on using the repository browser.