<commit_before>//
//  Environment.swift
//  WWDC
//
//  Created by <NAME> on 21/02/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

public extension Notification.Name {
    public static let WWDCEnvironmentDidChange = Notification.Name("WWDCEnvironmentDidChange")
}

public struct Environment {

    public let baseURL: String
    public let videosPath: String
    public let sessionsPath: String
    public let newsPath: String
    public let liveVideosPath: String

    public init(baseURL: String,
                videosPath: String,
                sessionsPath: String,
                newsPath: String,
                liveVideosPath: String) {
        self.baseURL = baseURL
        self.videosPath = videosPath
        self.sessionsPath = sessionsPath
        self.newsPath = newsPath
        self.liveVideosPath = liveVideosPath
    }

    public static func setCurrent(_ environment: Environment) {
        objc_sync_enter(self)
        defer { objc_sync_exit(self) }

        let shouldNotify = (environment != Environment.current)

        _storedEnvironment = environment

        UserDefaults.standard.set(environment.baseURL, forKey: _storedEnvDefaultsKey)

        if shouldNotify {
            DispatchQueue.main.async {
                NSLog("ENVIRONMENT CHANGED! New base URL: \(environment.baseURL)")

                NotificationCenter.default.post(name: .WWDCEnvironmentDidChange, object: environment)
            }
        }
    }

}

private let _storedEnvDefaultsKey = "_confCoreEnvironmentBaseURL"

private var _storedEnvironment: Environment? = Environment.readFromDefaults()

extension Environment {

    static func readFromDefaults() -> Environment? {
        guard let baseURL = UserDefaults.standard.object(forKey: _storedEnvDefaultsKey) as? String else { return nil }

        return Environment(
            baseURL: baseURL,
            videosPath: "/videos.json",
            sessionsPath: "/sessions.json",
            newsPath: "/news.json",
            liveVideosPath: "/videos_live.json"
        )
    }

    public static var current: Environment {
        if ProcessInfo.processInfo.arguments.contains("--test") {
            return .test
        } else {
            if let stored = _storedEnvironment {
                return stored
            } else {
                return .production
            }
        }
    }

    public static let test = Environment(baseURL: "http://localhost:9042",
                                         videosPath: "/videos.json",
                                         sessionsPath: "/contents.json",
                                         newsPath: "/news.json",
                                         liveVideosPath: "/videos_live.json")

    public static let production = Environment(baseURL: "https://api2017.wwdc.io",
                                               videosPath: "/videos.json",
                                               sessionsPath: "/contents.json",
                                               newsPath: "/news.json",
                                               liveVideosPath: "/videos_live.json")

}

extension Environment: Equatable {

    public static func == (lhs: Environment, rhs: Environment) -> Bool {
        return lhs.baseURL == rhs.baseURL
            && lhs.videosPath == rhs.videosPath
            && lhs.sessionsPath == rhs.sessionsPath
            && lhs.newsPath == rhs.newsPath
            && lhs.liveVideosPath == rhs.liveVideosPath
    }

}<commit_msg>Remove manual conformance to Equatable in Structs<commit_after>//
//  Environment.swift
//  WWDC
//
//  Created by <NAME> on 21/02/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

public extension Notification.Name {
    public static let WWDCEnvironmentDidChange = Notification.Name("WWDCEnvironmentDidChange")
}

public struct Environment: Equatable {

    public let baseURL: String
    public let videosPath: String
    public let sessionsPath: String
    public let newsPath: String
    public let liveVideosPath: String

    public init(baseURL: String,
                videosPath: String,
                sessionsPath: String,
                newsPath: String,
                liveVideosPath: String) {
        self.baseURL = baseURL
        self.videosPath = videosPath
        self.sessionsPath = sessionsPath
        self.newsPath = newsPath
        self.liveVideosPath = liveVideosPath
    }

    public static func setCurrent(_ environment: Environment) {
        objc_sync_enter(self)
        defer { objc_sync_exit(self) }

        let shouldNotify = (environment != Environment.current)

        _storedEnvironment = environment

        UserDefaults.standard.set(environment.baseURL, forKey: _storedEnvDefaultsKey)

        if shouldNotify {
            DispatchQueue.main.async {
                NSLog("ENVIRONMENT CHANGED! New base URL: \(environment.baseURL)")

                NotificationCenter.default.post(name: .WWDCEnvironmentDidChange, object: environment)
            }
        }
    }

}

private let _storedEnvDefaultsKey = "_confCoreEnvironmentBaseURL"

private var _storedEnvironment: Environment? = Environment.readFromDefaults()

extension Environment {

    static func readFromDefaults() -> Environment? {
        guard let baseURL = UserDefaults.standard.object(forKey: _storedEnvDefaultsKey) as? String else { return nil }

        return Environment(
            baseURL: baseURL,
            videosPath: "/videos.json",
            sessionsPath: "/sessions.json",
            newsPath: "/news.json",
            liveVideosPath: "/videos_live.json"
        )
    }

    public static var current: Environment {
        if ProcessInfo.processInfo.arguments.contains("--test") {
            return .test
        } else {
            if let stored = _storedEnvironment {
                return stored
            } else {
                return .production
            }
        }
    }

    public static let test = Environment(baseURL: "http://localhost:9042",
                                         videosPath: "/videos.json",
                                         sessionsPath: "/contents.json",
                                         newsPath: "/news.json",
                                         liveVideosPath: "/videos_live.json")

    public static let production = Environment(baseURL: "https://api2017.wwdc.io",
                                               videosPath: "/videos.json",
                                               sessionsPath: "/contents.json",
                                               newsPath: "/news.json",
                                               liveVideosPath: "/videos_live.json")

}
{'fraction_non_alphanumeric': 0.08429973238180197, 'fraction_numerical': 0.0053523639607493305, 'mean_word_length': 1.7535816618911175, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5293369', 'n_tokens_mistral': 1725, 'n_tokens_neox': 1599, 'n_words': 397}