package org.opentosca.toscana.core.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class PreferencesImpl implements Preferences {

    private static final Logger logger = LoggerFactory.getLogger(Preferences.class);


    private final Map<Key, String> defaults;

    public PreferencesImpl() {
        defaults = getDefaults();
    }

    private Map<Key, String> getDefaults() {
        Map<Key, String> defaultMap = new HashMap<>();
        String datadir = System.getenv("user.home");
        if (OsUtils.isUnix() || OsUtils.isMac()) {
            datadir = System.getenv("user.home") + "/.toscana";
        } else if (OsUtils.isWindows()) {
            datadir = System.getenv("user.home") + "/AppData/toscana";
        }
        defaultMap.put(Key.TOSCANA_DATADIR, datadir);
        return defaultMap;
    }

    @Override
    public String get(Key key) {
        String value = System.getenv(key.name());
        if (value == null || value.isEmpty()) {
        }
        return value;
    }

    @Override
    public File getDataDir() {
        String dataDirPath = System.getenv(Key.TOSCANA_DATADIR.name());
        File dataDir = new File(dataDirPath);
        return dataDir;
    }
}

@@ -300,16 +300,26 @@
 es.class
+.getName()
 );%0A%0A%0A   
@@ -1053,24 +1053,185 @@
 sEmpty()) %7B%0A
+            value = defaults.get(key);%0A            if (value == null)%7B%0A                logger.warn(%22No fallback value defined for key '%7B%7D'%22, key);%0A            %7D%0A
         %7D%0A  
@@ -1220,32 +1220,32 @@
     %7D%0A        %7D%0A
-
         return v
@@ -1331,29 +1331,19 @@
 rPath = 
-System.getenv
+get
 (Key.TOS
@@ -1354,23 +1354,16 @@
 _DATADIR
-.name()
 );%0A     

fix PreferenceImpl