<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import Foundation

let ONE_YEAR_IN_SECONDS = 365 * 24 * 60 * 60;

public class EnvelopeJSON : JSON {
    public init(_ jsonString: String) {
        super.init(JSON.parse(jsonString))
    }

    override public init(_ json: JSON) {
        super.init(json)
    }

    public func isValid() -> Bool {
        return !isError &&
               self["id"].isString &&
               //self["collection"].isString &&
               self["payload"].isString
    }

    public var id: String {
        return self["id"].asString!
    }
    
    public var collection: String {
        return self["collection"].asString ?? ""
    }
    
    public var payload: String {
        return self["payload"].asString!
    }
    
    public var sortindex: Int {
        return self["sortindex"].asInt ?? 0
    }

    public var modified: UInt64 {
        if (self["modified"].isInt) {
            return UInt64(self["modified"].asInt!) * 1000
        }

        if (self["modified"].isDouble) {
            return UInt64(1000 * (self["modified"].asDouble? ?? 0.0))
        }

        return 0
    }
}
<commit_msg>Switch EnvelopeJSON to use encapsulation rather than inheritance.<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import Foundation

let ONE_YEAR_IN_SECONDS = 365 * 24 * 60 * 60;

public class EnvelopeJSON {
    private let json: JSON

    public init(_ jsonString: String) {
        self.json = JSON.parse(jsonString)
    }

    public init(_ json: JSON) {
        self.json = json
    }

    public func isValid() -> Bool {
        return !self.json.isError &&
               self.json["id"].isString &&
               //self["collection"].isString &&
               self.json["payload"].isString
    }

    public var id: String {
        return self.json["id"].asString!
    }
    
    public var collection: String {
        return self.json["collection"].asString ?? ""
    }
    
    public var payload: String {
        return self.json["payload"].asString!
    }
    
    public var sortindex: Int {
        return self.json["sortindex"].asInt ?? 0
    }

    public var modified: UInt64 {
        if (self.json["modified"].isInt) {
            return UInt64(self.json["modified"].asInt!) * 1000
        }

        if (self.json["modified"].isDouble) {
            return UInt64(1000 * (self.json["modified"].asDouble? ?? 0.0))
        }

        return 0
    }
}

{'fraction_non_alphanumeric': 0.12264833574529667, 'fraction_numerical': 0.02243125904486252, 'mean_word_length': 2.0688124306326303, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1730929', 'n_tokens_mistral': 867, 'n_tokens_neox': 797, 'n_words': 229}