<commit_before>//
//  DefaultsHandlerType.swift
//  BFWControls
//
//  Created by <NAME> on 24/12/16.
//  Copyright © 2016 BareFeetWare.
//  Free to use at your own risk, with acknowledgement to BareFeetWare.
//

import Foundation

public protocol DefaultsHandlerType {
    
    associatedtype Key: RawRepresentable
    
    static var defaults: UserDefaults { get }
    
}

public extension DefaultsHandlerType where Key.RawValue == String {
    
    public static func setValue(_ value: Any?, for key: Key) {
        defaults.setValue(value, forKey: key.rawValue)
    }

    public static func value(for key: Key) -> Any? {
        return defaults.value(forKey: key.rawValue) as Any?
    }
    
    public static func string(for key: Key) -> String? {
        return defaults.string(forKey: key.rawValue)
    }
    
    public static func date(for key: Key) -> Date? {
        return defaults.value(forKey: key.rawValue) as? Date
    }

    public static func double(for key: Key) -> Double? {
        return defaults.double(forKey: key.rawValue)
    }
    
    public static func bool(for key: Key) -> Bool {
        return defaults.bool(forKey: key.rawValue)
    }
    
}<commit_msg>DefaultsHanderType: Added getters, sorted alphabetically<commit_after>//
//  DefaultsHandlerType.swift
//  BFWControls
//
//  Created by <NAME> on 24/12/16.
//  Copyright © 2016 BareFeetWare.
//  Free to use at your own risk, with acknowledgement to BareFeetWare.
//

import Foundation

public protocol DefaultsHandlerType {
    
    associatedtype Key: RawRepresentable
    
    static var defaults: UserDefaults { get }
    
}

public extension DefaultsHandlerType where Key.RawValue == String {
    
    // MARK: - Get/set value
    
    public static func setValue(_ value: Any?, for key: Key) {
        defaults.setValue(value, forKey: key.rawValue)
    }
    
    public static func value(for key: Key) -> Any? {
        return defaults.value(forKey: key.rawValue) as Any?
    }
    
    // MARK: - Get specific types
    
    static func array(for key: Key) -> [Any]? {
        return defaults.array(forKey: key.rawValue)
    }
    
    public static func bool(for key: Key) -> Bool {
        return defaults.bool(forKey: key.rawValue)
    }
    
    public static func date(for key: Key) -> Date? {
        return defaults.value(forKey: key.rawValue) as? Date
    }
    
    static func data(for key: Key) -> Data? {
        return defaults.data(forKey: key.rawValue)
    }
    
    public static func double(for key: Key) -> Double? {
        return defaults.double(forKey: key.rawValue)
    }
    
    static func int(for key: Key) -> Int? {
        return defaults.value(forKey: key.rawValue) as? Int
    }
    
    public static func string(for key: Key) -> String? {
        return defaults.string(forKey: key.rawValue)
    }
    
}
{'fraction_non_alphanumeric': 0.10346045197740113, 'fraction_numerical': 0.007062146892655367, 'mean_word_length': 2.44228432563791, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, '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': '7320399', 'n_tokens_mistral': 900, 'n_tokens_neox': 866, 'n_words': 256}