<commit_before>package de.qaware.chronix.shared.ServerConfig;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.qaware.chronix.shared.dockerUtil.DockerRunOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.util.LinkedList;

/**
 * Created by mcqueen666 on 05.08.16.
 */
public class ServerConfigAccessor {

    private static ServerConfigAccessor instance;
    private final Logger logger = LoggerFactory.getLogger(ServerConfigAccessor.class);
    private final String configDirectory = System.getProperty("user.home") + File.separator + ".chronixBenchmark_conf" + File.separator;
    private final String serverConfigFileName = "serverConfig.json";
    private LinkedList<ServerConfigRecord> serverConfigRecords;


    private ServerConfigAccessor(){
        new File(configDirectory).mkdir();
        if((new File(configDirectory + serverConfigFileName).exists())) {
            readRecordFile();
        }
        if(serverConfigRecords == null){
            serverConfigRecords =  new LinkedList<ServerConfigRecord>();
            writeRecordFile();
        }
    }

    public static synchronized ServerConfigAccessor getInstance(){
        if(instance == null){
            instance = new ServerConfigAccessor();
        }

        return instance;
    }

    public String getConfigDirectory(){
        return configDirectory;
    }

    public String getServerConfigFileName(){
        return serverConfigFileName;
    }

    public LinkedList<ServerConfigRecord> getServerConfigRecords(){
        readRecordFile();
        return serverConfigRecords;
    }

    public synchronized void setServerConfigRecords(LinkedList<ServerConfigRecord> serverConfigRecords){
        this.serverConfigRecords = serverConfigRecords;
        writeRecordFile();
    }

    /**
     * Returns the host port on given server where given tsdb is available.
     *
     * @param serverAddress
     * @param tsdbName
     * @return
     */
    public String getHostPortForTSDB(String serverAddress, String tsdbName){
        LinkedList<ServerConfigRecord> records = getServerConfigRecords();
        for(ServerConfigRecord r : records){<commit_msg>added methods to get server config record bei server address and to add a new server config record<commit_after>package de.qaware.chronix.shared.ServerConfig;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.qaware.chronix.shared.dockerUtil.DockerRunOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by mcqueen666 on 05.08.16.
 */
public class ServerConfigAccessor {

    private static ServerConfigAccessor instance;
    private final Logger logger = LoggerFactory.getLogger(ServerConfigAccessor.class);
    private final String configDirectory = System.getProperty("user.home") + File.separator + ".chronixBenchmark_conf" + File.separator;
    private final String serverConfigFileName = "serverConfig.json";
    private LinkedList<ServerConfigRecord> serverConfigRecords;


    private ServerConfigAccessor(){
        new File(configDirectory).mkdir();
        if((new File(configDirectory + serverConfigFileName).exists())) {
            readRecordFile();
        }
        if(serverConfigRecords == null){
            serverConfigRecords =  new LinkedList<ServerConfigRecord>();
            writeRecordFile();
        }
    }

    public static synchronized ServerConfigAccessor getInstance(){
        if(instance == null){
            instance = new ServerConfigAccessor();
        }

        return instance;
    }

    public String getConfigDirectory(){
        return configDirectory;
    }

    public String getServerConfigFileName(){
        return serverConfigFileName;
    }

    public LinkedList<ServerConfigRecord> getServerConfigRecords(){
        readRecordFile();
        return serverConfigRecords;
    }

    public synchronized void setServerConfigRecords(LinkedList<ServerConfigRecord> serverConfigRecords){
        this.serverConfigRecords = serverConfigRecords;
        writeRecordFile();
    }

    public synchronized void addServerConfigRecord(ServerConfigRecord serverConfigRecord){
        readRecordFile();
        serverConfigRecords.add(serverConfigRecord);
        writeRecordFile();
    }

    public synchronized void removeServerConfigRecord(ServerConfigRecord serverConfigRecord){
        readRecordFile();
        if(serverConfigRecords.remove(serverConfigRecord)){
            writeRecordFile();
        }
    }


    /**
     * Returns ServerConfigRecord for given server address.
     *
     * @param serverAddress the server address or ip.
     * @return the ServerConfigRecord or null if not contained.
     */
    public ServerConfigRecord getServerConfigRecord(String serverAddress){
        readRecordFile();
        if(!serverConfigRecords.isEmpty()){
            for(ServerConfigRecord serverConfigRecord : serverConfigRecords){
                if(serverConfigRecord.getServerAddress().equals(serverAddress)){
                    return serverConfigRecord;
                }
            }
        }
        return null;
    }


    /**
     * Returns the host port on given server where given tsdb is available.
     *
     * @param serverAddress
     * @param tsdbName
     * @return
     */
    public String getHostPortForTSDB(String serverAddress, String tsdbName){
        LinkedList<ServerConfigRecord> records = getServerConfigRecords();
        for(ServerConfigRecord r : records){
{'fraction_non_alphanumeric': 0.08251748251748252, 'fraction_numerical': 0.0038461538461538464, 'mean_word_length': 3.266219239373602, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5110825', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1381, 'n_words': 329}