<commit_before>package com.ibm.wiotp.sdk.gateway.config;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Map;

import com.ibm.wiotp.sdk.device.config.DeviceConfig;
import com.ibm.wiotp.sdk.device.config.DeviceConfigAuth;
import com.ibm.wiotp.sdk.device.config.DeviceConfigIdentity;
import com.ibm.wiotp.sdk.device.config.DeviceConfigOptions;

import org.yaml.snakeyaml.Yaml;

public class GatewayConfig extends DeviceConfig {
	
	public GatewayConfig(DeviceConfigIdentity identity, DeviceConfigAuth auth, DeviceConfigOptions options) {
		super(identity, auth, options);
	}

	@Override
	public String getClientId() {
		return "g:" + identity.orgId + ":" + identity.typeId + ":" + identity.deviceId;
	}
	
	
	public static GatewayConfig generateFromEnv() {
		GatewayConfig cfg = new GatewayConfig(
				DeviceConfigIdentity.generateFromEnv(), 
				DeviceConfigAuth.generateFromEnv(), 
				DeviceConfigOptions.generateFromEnv());
		
		return cfg;
	}

	public static GatewayConfig generateFromConfig(String fileName) throws FileNotFoundException {
		Yaml yaml = new Yaml();
		InputStream inputStream = new FileInputStream(fileName);
		Map<String, Object> yamlContents = yaml.load(inputStream);	

		if(yamlContents.get("identity") instanceof Map<?, ?>) {
			if(yamlContents.get("auth") instanceof Map<?, ?>) {
				if(yamlContents.get("options") instanceof Map<?, ?>) {
					GatewayConfig cfg = new GatewayConfig(
					DeviceConfigIdentity.generateFromConfig((Map<String, Object>) yamlContents.get("identity")), 
					DeviceConfigAuth.generateFromConfig((Map<String, Object>) yamlContents.get("auth")), 
					DeviceConfigOptions.generateFromConfig((Map<String, Object>) yamlContents.get("options")));
					//potential green underlined type safety warning here but the casts are checked by the if statements
					return cfg;
				}
				//else options is missing or in the wrong format			
			}		
			//else auth is missing or in the wrong format			
		}
		//else identity is missing or in the wrong format			
		return null;
	}

}<commit_msg>Suppress warnings for unchecked casts in yaml config handling<commit_after>package com.ibm.wiotp.sdk.gateway.config;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Map;

import com.ibm.wiotp.sdk.device.config.DeviceConfig;
import com.ibm.wiotp.sdk.device.config.DeviceConfigAuth;
import com.ibm.wiotp.sdk.device.config.DeviceConfigIdentity;
import com.ibm.wiotp.sdk.device.config.DeviceConfigOptions;

import org.yaml.snakeyaml.Yaml;

public class GatewayConfig extends DeviceConfig {
	
	public GatewayConfig(DeviceConfigIdentity identity, DeviceConfigAuth auth, DeviceConfigOptions options) {
		super(identity, auth, options);
	}

	@Override
	public String getClientId() {
		return "g:" + identity.orgId + ":" + identity.typeId + ":" + identity.deviceId;
	}
	
	
	public static GatewayConfig generateFromEnv() {
		GatewayConfig cfg = new GatewayConfig(
				DeviceConfigIdentity.generateFromEnv(), 
				DeviceConfigAuth.generateFromEnv(), 
				DeviceConfigOptions.generateFromEnv());
		
		return cfg;
	}

	@SuppressWarnings("unchecked")
	public static GatewayConfig generateFromConfig(String fileName) throws FileNotFoundException {
		Yaml yaml = new Yaml();
		InputStream inputStream = new FileInputStream(fileName);
		Map<String, Object> yamlContents = yaml.load(inputStream);	

		if(yamlContents.get("identity") instanceof Map<?, ?>) {
			if(yamlContents.get("auth") instanceof Map<?, ?>) {
				if(yamlContents.get("options") instanceof Map<?, ?>) {
					GatewayConfig cfg = new GatewayConfig(
					DeviceConfigIdentity.generateFromConfig((Map<String, Object>) yamlContents.get("identity")), 
					DeviceConfigAuth.generateFromConfig((Map<String, Object>) yamlContents.get("auth")), 
					DeviceConfigOptions.generateFromConfig((Map<String, Object>) yamlContents.get("options")));
					return cfg;
				}
				//else options is missing or in the wrong format			
			}		
			//else auth is missing or in the wrong format			
		}
		//else identity is missing or in the wrong format			
		return null;
	}

}
{'fraction_non_alphanumeric': 0.10926993275696446, 'fraction_numerical': 0.0, 'mean_word_length': 4.784722222222222, 'pattern_counts': {'":': 4, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6202504', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1192, 'n_words': 283}