es.webbeta.serializer.FileMetadataAccessor   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
dl 0
loc 42
c 1
b 0
f 0
rs 10
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setMetadataPath(Path) 0 3 1
A hasYamlMetadata(Class) 0 2 1
A buildPath(Class,String) 0 2 1
A hasMetadata(Class) 0 4 1
A hasYmlMetadata(Class) 0 2 1
A getMetadataContent(Class) 0 12 4
1
package es.webbeta.serializer;
2
3
import es.webbeta.serializer.base.FileUtils;
4
import es.webbeta.serializer.base.MetadataAccessor;
5
6
import java.io.IOException;
7
import java.nio.file.Files;
8
import java.nio.file.Path;
9
import java.nio.file.Paths;
10
11
public class FileMetadataAccessor implements MetadataAccessor {
12
13
    private static final String YAML_EXT = ".yaml";
14
    private static final String YML_EXT = ".yml";
15
16
    protected Path metadataPath = null;
17
18
    private Path buildPath(Class<?> klass, String extension) {
19
        return Paths.get(metadataPath.toString(), klass.getCanonicalName() + extension);
20
    }
21
22
    private Boolean hasYmlMetadata(Class<?> klass) {
23
        return Files.exists(buildPath(klass, YML_EXT));
24
    }
25
26
    private Boolean hasYamlMetadata(Class<?> klass) {
27
        return Files.exists(buildPath(klass, YAML_EXT));
28
    }
29
30
    @Override
31
    public void setMetadataPath(Path path) {
32
        metadataPath = path;
33
    }
34
35
    @Override
36
    public Boolean hasMetadata(Class<?> klass) {
37
        return hasYmlMetadata(klass) ||
38
                hasYamlMetadata(klass);
39
    }
40
41
    @Override
42
    public String getMetadataContent(Class<?> klass) {
43
        String contents = null;
44
45
        try {
46
            if (hasYmlMetadata(klass))
47
                contents = FileUtils.getContent(buildPath(klass, YML_EXT));
48
            else if(hasYamlMetadata(klass))
49
                contents = FileUtils.getContent(buildPath(klass, YAML_EXT));
50
        } catch (IOException ignored) {}
0 ignored issues
show
Bug introduced by
Consider removing the empty block or filling it with code. You can also add a comment to explain the empty block.
Loading history...
51
52
        return contents;
53
    }
54
55
}
56