<commit_before>/**
 * Licensed under Apache License v2. See LICENSE for more information.
 */
package org.inaetics.demonstrator.clusterinfo;

import java.util.Dictionary;

/**
 * Configuration values for cluster info
 */
public class ClusterInfoConfig {
	
	private static final String KEY_CADVISOR_PORT = "cAdvisorPort";	
	private static final String KEY_ETCD_ENDPOINT = "etcdEndpoint";	
	private static final String KEY_FLEET_SELECTION_KEY = "fleetSelectionKey";	
	private static final String KEY_FLEET_SELECTION_VALUE = "fleetSelectionValue";	
	private static final String KEY_UPDATE_PERIOD = "updatePeriod";	

	private final static int DEFAULT_CADVISOR_PORT = 4194;
	private final static String DEFAULT_ETCD_ENDPOINT = "172.17.8.20:2379";
    private final static String DEFAULT_FLEET_SELECTION_KEY = "role";
    private final static String DEFAULT_FLEET_SELECTION_VALUE = "cluster";
	private final static int DEFAULT_UPDATE_PERIOD = 30;

	private final int m_cAdvisorPort;
	private final String m_etcdEndpoint;
	private final String m_fleetSelectionKey;
	private final String m_fleetSelectionValue;
	private final int m_updatePeriod;
	
	public ClusterInfoConfig(Dictionary<String, ?> properties) {
		m_cAdvisorPort = getIntValue(properties, KEY_CADVISOR_PORT, DEFAULT_CADVISOR_PORT);
		m_etcdEndpoint = getStringValue(properties, KEY_ETCD_ENDPOINT, DEFAULT_ETCD_ENDPOINT);
		m_fleetSelectionKey = getStringValue(properties, KEY_FLEET_SELECTION_KEY, DEFAULT_FLEET_SELECTION_KEY);
		m_fleetSelectionValue = getStringValue(properties, KEY_FLEET_SELECTION_VALUE, DEFAULT_FLEET_SELECTION_VALUE);
		m_updatePeriod = getIntValue(properties, KEY_UPDATE_PERIOD, DEFAULT_UPDATE_PERIOD);
	}
	
	private String getStringValue(Dictionary<String, ?> properties, String key, String defaultValue) {
		Object value = properties.get(key);
		if (value != null) {
			return value.toString();
		}
		return defaultValue;
	}

	private int getIntValue(Dictionary<String, ?> properties, String key, int defaultValue) {
		Object value = properties.get(key);
		if (value != null) {
			try {
				return Integer.parseInt(value.toString());
			}
			catch (Exception e) {
			}
		}
		return defaultValue;
	}

	public int getCadvisorPort() {
		return m_cAdvisorPort;
	}

	public String getEtcdEndpoint() {
		return m_etcdEndpoint;
	}

	public String getFleetSelectionKey() {
		return m_fleetSelectionKey;
	}

	public String getFleetSelectionValue() {
		return m_fleetSelectionValue;
	}
	<commit_msg>fixed NPE<commit_after>/**
 * Licensed under Apache License v2. See LICENSE for more information.
 */
package org.inaetics.demonstrator.clusterinfo;

import java.util.Dictionary;

/**
 * Configuration values for cluster info
 */
public class ClusterInfoConfig {
	
	private static final String KEY_CADVISOR_PORT = "cAdvisorPort";	
	private static final String KEY_ETCD_ENDPOINT = "etcdEndpoint";	
	private static final String KEY_FLEET_SELECTION_KEY = "fleetSelectionKey";	
	private static final String KEY_FLEET_SELECTION_VALUE = "fleetSelectionValue";	
	private static final String KEY_UPDATE_PERIOD = "updatePeriod";	

	private final static int DEFAULT_CADVISOR_PORT = 4194;
	private final static String DEFAULT_ETCD_ENDPOINT = "172.17.8.20:2379";
    private final static String DEFAULT_FLEET_SELECTION_KEY = "role";
    private final static String DEFAULT_FLEET_SELECTION_VALUE = "cluster";
	private final static int DEFAULT_UPDATE_PERIOD = 30;

	private final int m_cAdvisorPort;
	private final String m_etcdEndpoint;
	private final String m_fleetSelectionKey;
	private final String m_fleetSelectionValue;
	private final int m_updatePeriod;
	
	public ClusterInfoConfig(Dictionary<String, ?> properties) {
		m_cAdvisorPort = getIntValue(properties, KEY_CADVISOR_PORT, DEFAULT_CADVISOR_PORT);
		m_etcdEndpoint = getStringValue(properties, KEY_ETCD_ENDPOINT, DEFAULT_ETCD_ENDPOINT);
		m_fleetSelectionKey = getStringValue(properties, KEY_FLEET_SELECTION_KEY, DEFAULT_FLEET_SELECTION_KEY);
		m_fleetSelectionValue = getStringValue(properties, KEY_FLEET_SELECTION_VALUE, DEFAULT_FLEET_SELECTION_VALUE);
		m_updatePeriod = getIntValue(properties, KEY_UPDATE_PERIOD, DEFAULT_UPDATE_PERIOD);
	}
	
	private String getStringValue(Dictionary<String, ?> properties, String key, String defaultValue) {
		if (properties != null) {
			Object value = properties.get(key);
			if (value != null) {
				return value.toString();
			}
		}
		return defaultValue;
	}

	private int getIntValue(Dictionary<String, ?> properties, String key, int defaultValue) {
		if (properties != null) {
			Object value = properties.get(key);
			if (value != null) {
				try {
					return Integer.parseInt(value.toString());
				}
				catch (Exception e) {
				}
			}
		}
		return defaultValue;
	}

	public int getCadvisorPort() {
		return m_cAdvisorPort;
	}

	public String getEtcdEndpoint() {
		return m_etcdEndpoint;
	}

	public String getFleetSelectionKey() {
		return m_fleetSelectionKey;
	}

	public String getFleetSelectionValue() {
		return m_fleetSelectionValue;
	}
	
{'fraction_non_alphanumeric': 0.07784431137724551, 'fraction_numerical': 0.007584830339321357, 'mean_word_length': 5.507792207792208, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '988630', 'n_tokens_mistral': 1715, 'n_tokens_neox': 1557, 'n_words': 379}