<commit_before>//
//  ToJSON.swift
//  ObjectMapper
//
//  Created by <NAME> on 2014-10-13.
//  Copyright (c) 2014 hearst. All rights reserved.
//

import Foundation

class ToJSON {
	
	func addObject(object: AnyObject, inout toDictionary dictionary: [String : AnyObject]){
		
	}
	
    func baseType<N>(field: N, key: String, inout dictionary: [String : AnyObject]) {
		
		var temp = dictionary
		var currentKey = key

        switch N.self {
		// basic Types
        case is Bool.Type:
            dictionary[currentKey] = field as Bool
        case is Int.Type:
            dictionary[currentKey] = field as Int
        case is Double.Type:
            dictionary[currentKey] = field as Double
        case is Float.Type:
            dictionary[currentKey] = field as Float
        case is String.Type:
            dictionary[currentKey] = field as String

		// Arrays with basic types
		case is Array<Bool>.Type:
			dictionary[currentKey] = field as Array<Bool>
		case is Array<Int>.Type:
			dictionary[currentKey] = field as Array<Int>
		case is Array<Double>.Type:
			dictionary[currentKey] = field as Array<Double>
		case is Array<Float>.Type:
			dictionary[currentKey] = field as Array<Float>
		case is Array<String>.Type:
			dictionary[currentKey] = field as Array<String>
			
		// Dictionaries with basic types
		case is Dictionary<String, Bool>.Type:
			dictionary[currentKey] = field as Dictionary<String, Bool>
		case is Dictionary<String, Int>.Type:
			dictionary[currentKey] = field as Dictionary<String, Int>
		case is Dictionary<String, Double>.Type:
			dictionary[currentKey] = field as Dictionary<String, Double>
		case is Dictionary<String, Float>.Type:
			dictionary[currentKey] = field as Dictionary<String, Float>
		case is Dictionary<String, String>.Type:
			dictionary[currentKey] = field as Dictionary<String, String>
        default:
            //println("Default")
            return
        }
    }
    
    func optionalBaseType<N>(field: N?, key: String, inout dictionary: [String : AnyObject]) {
        if let field: N = field {
            baseType(field, key: key, dictionary: &dictionary)
        }
    }
    
    func baseArray(field: Array<AnyObject>, key: String, inout dictionary: [String : AnyObject]){
        dictionary[key] = NSArray(array: field)
    }
    
    func optionalBaseArray(field: Array<AnyObject>?, key: String, inout dictionary: [String : AnyObject]){
        if let value = field {
            baseArray(value, key: key, dictionary: &dictionary)
        }
    }
    
    func baseDictionary(field: Dictionary<String, AnyObject>, key: String, inout dictionary: [String : AnyObject]){
        dictionary[key] = NSDictionary(dictionary: field)
    }
    
    func optionalBaseDictionary(field: Dictionary<String, AnyObject>?, key: String, inout dictionary: [String : AnyObject]){
        if let value = field {
            baseDictionary(value, key: key, dictionary: &dictionary)
        }
    }
    
    func object<N: Mappable>(field: N, key: String, inout dictionary: [String : AnyObject]) {
        let mapper = Mapper<N>()<commit_msg>[ToJSON] Refactor switch-case to test `field` directly<commit_after>//
//  ToJSON.swift
//  ObjectMapper
//
//  Created by <NAME> on 2014-10-13.
//  Copyright (c) 2014 hearst. All rights reserved.
//

import Foundation

class ToJSON {
	
	func addObject(object: AnyObject, inout toDictionary dictionary: [String : AnyObject]){
		
	}
	
    func baseType<N>(field: N, key: String, inout dictionary: [String : AnyObject]) {
		
		var temp = dictionary
		var currentKey = key

        switch field {
        // basic Types
        case let x as Bool:
            dictionary[currentKey] = x
        case let x as Int:
            dictionary[currentKey] = x
        case let x as Double:
            dictionary[currentKey] = x
        case let x as Float:
            dictionary[currentKey] = x
        case let x as String:
            dictionary[currentKey] = x

        // Arrays with basic types
        case let x as Array<Bool>:
            dictionary[currentKey] = x
        case let x as Array<Int>:
            dictionary[currentKey] = x
        case let x as Array<Double>:
            dictionary[currentKey] = x
        case let x as Array<Float>:
            dictionary[currentKey] = x
        case let x as Array<String>:
            dictionary[currentKey] = x
			
        // Dictionaries with basic types
        case let x as Dictionary<String, Bool>:
            dictionary[currentKey] = x
        case let x as Dictionary<String, Int>:
            dictionary[currentKey] = x
        case let x as Dictionary<String, Double>:
            dictionary[currentKey] = x
        case let x as Dictionary<String, Float>:
            dictionary[currentKey] = x
        case let x as Dictionary<String, String>:
            dictionary[currentKey] = x
        default:
            //println("Default")
            return
        }
    }
    
    func optionalBaseType<N>(field: N?, key: String, inout dictionary: [String : AnyObject]) {
        if let field = field {
            baseType(field, key: key, dictionary: &dictionary)
        }
    }
    
    func baseArray(field: Array<AnyObject>, key: String, inout dictionary: [String : AnyObject]){
        dictionary[key] = NSArray(array: field)
    }
    
    func optionalBaseArray(field: Array<AnyObject>?, key: String, inout dictionary: [String : AnyObject]){
        if let value = field {
            baseArray(value, key: key, dictionary: &dictionary)
        }
    }
    
    func baseDictionary(field: Dictionary<String, AnyObject>, key: String, inout dictionary: [String : AnyObject]){
        dictionary[key] = NSDictionary(dictionary: field)
    }
    
    func optionalBaseDictionary(field: Dictionary<String, AnyObject>?, key: String, inout dictionary: [String : AnyObject]){
        if let value = field {
            baseDictionary(value, key: key, dictionary: &dictionary)
        }
    }
    
    func object<N: Mappable>(field: N, key: String, inout dictionary: [String : AnyObject]) {
        let mapper = Mapper<N>()
{'fraction_non_alphanumeric': 0.10310804144055254, 'fraction_numerical': 0.003946719289590528, 'mean_word_length': 2.5074971164936564, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 51, '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': '1856408', 'n_tokens_mistral': 1784, 'n_tokens_neox': 1669, 'n_words': 531}