FFM-Friend_Face_Matching/src/main/java/dev/mateuszkowalczyk/ffm/app/cache/CacheService.java

48 lines
1.1 KiB
Java
Raw Normal View History

2020-01-14 23:05:39 +01:00
package dev.mateuszkowalczyk.ffm.app.cache;
2020-01-15 22:08:59 +01:00
import dev.mateuszkowalczyk.ffm.utils.PropertiesLoader;
import dev.mateuszkowalczyk.ffm.utils.Property;
2020-01-14 23:05:39 +01:00
public class CacheService {
private static CacheService instance;
private String path = "";
2020-01-14 23:05:39 +01:00
private CacheService () {
2020-01-14 23:34:46 +01:00
this.check();
2020-01-14 23:05:39 +01:00
}
public synchronized static CacheService getInstance() {
if(instance == null) {
instance = new CacheService();
}
2020-01-14 23:05:39 +01:00
return instance;
}
2020-01-14 23:34:46 +01:00
public String getPath(String name) {
return this.getPath() + "/" + name;
}
public String getPath() {
return path;
2020-01-14 23:34:46 +01:00
}
2020-01-15 22:08:59 +01:00
public void check() {
this.updatePath();
if (this.path != null) {
CacheStructureChecker cacheStructureChecker = new CacheStructureChecker();
cacheStructureChecker.check(this.path);
}
}
2020-01-15 22:08:59 +01:00
private String updatePath() {
String path = PropertiesLoader.getInstance().get(Property.PATH_TO_DIRECTORY);
2020-01-15 22:08:59 +01:00
if (path != null) {
this.path = path + "/.cache";
2020-01-15 22:08:59 +01:00
}
return path;
2020-01-15 22:08:59 +01:00
}
2020-01-14 23:05:39 +01:00
}