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 |
|
---|
15 | package de.ugoe.cs.cpdp.loader;
|
---|
16 |
|
---|
17 | import java.io.File;
|
---|
18 | import java.util.LinkedList;
|
---|
19 | import java.util.List;
|
---|
20 |
|
---|
21 | import weka.core.Instances;
|
---|
22 |
|
---|
23 | import 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 | */
|
---|
31 | public 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 | String versionName = versionFile.getName();
|
---|
67 | Instances data = instancesLoader.load(versionFile);
|
---|
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 | }
|
---|