aboutsummaryrefslogtreecommitdiffstats
path: root/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/FileProvider.java
blob: 9eb733227eb0188e8582a321a5591235a016a04b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package org.onap.pnfsimulator;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class FileProvider {

    private FileProvider() {}

    public static List<String> getFiles() {

        List<String> files = queryFiles();

        files.sort(Collections.reverseOrder());

        List<String> fileListSorted = new ArrayList<>();
        for (String f : files) {
            fileListSorted.add(f);
        }
        return fileListSorted;
    }

    private static List<String> queryFiles() {

        File folder = new File("./files/onap/");
        File[] listOfFiles = folder.listFiles();
        List<String> results = new ArrayList<>();

        if (listOfFiles.length == 0) {
            return results;
            // TODO: this should be a thrown exception catched in the Simulator class
        }

        for (int i = 0; i < listOfFiles.length; i++) {
            if (listOfFiles[i].isFile()) {
                results.add(listOfFiles[i].getName());
            }
        }

        return results;
    }
}