<commit_before>//
//  RequestStub.swift
//  Flamingo
//
//  Created by <NAME> on 04.03.2018.
//  Copyright © 2018 ELN. All rights reserved.
//

import Foundation

public struct RequestStub: Hashable {
    public let url: URL
    public let method: HTTPMethod
    public let params: [String: Any]?
    public var hashValue: Int

    public init(url: URL, method: HTTPMethod, params: [String: Any]? = nil) {
        self.url = url
        self.method = method
        self.params = params
        hashValue = "\(url)\(method)\(params ?? [:])".hashValue
    }

    public init?<Request: NetworkRequest>(_ request: Request) {
        guard let requestURL = (try? request.URL.asURL()) else {
            return nil
        }
        self.init(url: requestURL, method: request.method, params: request.parameters)
    }

    public static func ==(lhs: RequestStub, rhs: RequestStub) -> Bool {
        let equalParams = NSDictionary(dictionary: lhs.params ?? [:]).isEqual(to: rhs.params ?? [:])
        return lhs.url == rhs.url &&
            lhs.method == rhs.method &&
            equalParams
    }
}<commit_msg>Use modern hashable method<commit_after>//
//  RequestStub.swift
//  Flamingo
//
//  Created by <NAME> on 04.03.2018.
//  Copyright © 2018 ELN. All rights reserved.
//

import Foundation

public struct RequestStub: Hashable {
    public let url: URL
    public let method: HTTPMethod
    public let params: [String: Any]?
    
    public func hash(into hasher: inout Hasher) {
        hasher.combine(url)
        hasher.combine(method)
        hasher.combine(NSDictionary(dictionary: params ?? [:]))
    }
    
    public init(url: URL, method: HTTPMethod, params: [String: Any]? = nil) {
        self.url = url
        self.method = method
        self.params = params
    }

    public init?<Request: NetworkRequest>(_ request: Request) {
        guard let requestURL = (try? request.URL.asURL()) else {
            return nil
        }
        self.init(url: requestURL, method: request.method, params: request.parameters)
    }

    public static func ==(lhs: RequestStub, rhs: RequestStub) -> Bool {
        let equalParams = NSDictionary(dictionary: lhs.params ?? [:]).isEqual(to: rhs.params ?? [:])
        return lhs.url == rhs.url &&
            lhs.method == rhs.method &&
            equalParams
    }
}
{'fraction_non_alphanumeric': 0.12796208530805686, 'fraction_numerical': 0.01034037052994399, 'mean_word_length': 2.3997071742313323, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '2848740', 'n_tokens_mistral': 726, 'n_tokens_neox': 700, 'n_words': 196}