<commit_before>//
//  BlockedUserManager.swift
//  KomicaViewer
//
//  Created by Craig on 5/09/2016.
//  Copyright © 2016 Craig. All rights reserved.
//

import UIKit

class BlockedUserManager: NSObject {
    static let sharedManager = BlockedUserManager()
    static let updatedNotification = "BlockedUserUpdatedNotification"
    private let BlockedUserIDKey = "BlockedUserIDKey"
    
    private var blockedUserIDs = [String]()
    
    private func save() {
        NSUserDefaults.standardUserDefaults().setObject(blockedUserIDs, forKey: BlockedUserIDKey)
        NSUserDefaults.standardUserDefaults().synchronize()
    }
    
    private func restore() {
        if let restoredObjects = NSUserDefaults.standardUserDefaults().objectForKey(BlockedUserIDKey) as? [String] {
            blockedUserIDs = restoredObjects
        }
    }
    
    override init() {
        super.init()
        restore()
    }
    
    func blockUserID(id: String) {
        blockedUserIDs.append(id)
        save()
        NSNotificationCenter.defaultCenter().postNotificationName(BlockedUserManager.updatedNotification, object: nil)
    }
    
    func unblockUserID(id: String) {
        blockedUserIDs.removeObject(id)
        save()
        NSNotificationCenter.defaultCenter().postNotificationName(BlockedUserManager.updatedNotification, object: nil)
    }
    
    func isUserIDBlocked(id: String) -> Bool {
        return blockedUserIDs.contains(id)
    }
}<commit_msg>Added a bit of safety measure.<commit_after>//
//  BlockedUserManager.swift
//  KomicaViewer
//
//  Created by Craig on 5/09/2016.
//  Copyright © 2016 Craig. All rights reserved.
//

import UIKit

class BlockedUserManager: NSObject {
    static let sharedManager = BlockedUserManager()
    static let updatedNotification = "BlockedUserUpdatedNotification"
    private let BlockedUserIDKey = "BlockedUserIDKey"
    
    private var blockedUserIDs = [String]()
    
    private func save() {
        NSUserDefaults.standardUserDefaults().setObject(blockedUserIDs, forKey: BlockedUserIDKey)
        NSUserDefaults.standardUserDefaults().synchronize()
    }
    
    private func restore() {
        if let restoredObjects = NSUserDefaults.standardUserDefaults().objectForKey(BlockedUserIDKey) as? [String] {
            blockedUserIDs = restoredObjects
        }
    }
    
    override init() {
        super.init()
        restore()
    }
    
    func blockUserID(id: String) {
        blockedUserIDs.append(id)
        // A bit of safty measure, when more than 9999, drop the first entity.
        if blockedUserIDs.count > 9999 {
            blockedUserIDs.removeFirst()
        }
        save()
        NSNotificationCenter.defaultCenter().postNotificationName(BlockedUserManager.updatedNotification, object: nil)
    }
    
    func unblockUserID(id: String) {
        blockedUserIDs.removeObject(id)
        save()
        NSNotificationCenter.defaultCenter().postNotificationName(BlockedUserManager.updatedNotification, object: nil)
    }
    
    func isUserIDBlocked(id: String) -> Bool {
        return blockedUserIDs.contains(id)
    }
}
{'fraction_non_alphanumeric': 0.08976833976833977, 'fraction_numerical': 0.009652509652509652, 'mean_word_length': 2.881398252184769, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '6643671', 'n_tokens_mistral': 897, 'n_tokens_neox': 864, 'n_words': 182}