<commit_before>//
//  MYSection.swift
//  MYTableViewManager
//
//  Created by <NAME> on 2/14/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Foundation

protocol MYSectionDelegate : class {
    func reloadTableView()
    func reloadSections(indexSet: NSIndexSet, animation: MYAnimation)
    func insertRows(indexPaths: [NSIndexPath], animation: MYAnimation)
    func deleteRows(indexPaths: [NSIndexPath], animation: MYAnimation)
    
    func willAddCellViewModels(viewmodels: [MYCellViewModel])
}

public class MYSection {
    internal(set) var index: Int = 0 {
        didSet {
            header?.section = index
            footer?.section = index
            for item in items {
                item.section = index
            }
        }
    }
    weak var delegate: MYSectionDelegate?
    private var items: [MYCellViewModel] = []
    private let reloadTracker = MYReloadTracker()
    
    public var header: MYHeaderFooterViewModel? {
        didSet {
            header?.section = index
            header?.isHeader = true
        }
    }
    public var footer: MYHeaderFooterViewModel? {
        didSet {
            footer?.section = index
            footer?.isHeader = false
        }
    }

    public subscript(index: Int) -> MYCellViewModel? {
        get {
            return items.my_hasIndex(index) ? items[index] : nil
        }
    }
    
    public init() {
    }
}

public extension MYSection {
    // MARK - reset
    func reset() -> Self {
        items = []
        reloadTracker.didReset()
        return self
    }
    
    func reset(viewmodel: MYCellViewModel) -> Self {
        return reset([viewmodel])
    }
    
    func reset(viewmodels: [MYCellViewModel]) -> Self {
        delegate?.willAddCellViewModels(viewmodels)
        items = viewmodels
        resetIndex(0, end: self.count-1)
        reloadTracker.didReset()
        return self
    }
    
    // MARK - apppend
    func append(viewmodel: MYCellViewModel) -> Self {
        return append([viewmodel])
    }
    
    func append(viewmodels: [MYCellViewModel]) -> Self {
        delegate?.willAddCellViewModels(viewmodels)
        let r = items.my_append(viewmodels)
        resetIndex(r.startIndex, end: self.count-1)
        reloadTracker.didAdd(r)
        return self
    }
    
    // MARK - insert
    func insert(viewmodel: MYCellViewModel, atIndex index: Int) -> Self {
        return insert([viewmodel], atIndex: index)
    }
    
    func insert(viewmodels: [MYCellViewModel], atIndex index: Int) -> Self {
        delegate?.willAddCellViewModels(viewmodels)
        let r = items.my_insert(viewmodels, atIndex: index)
        resetIndex(r.startIndex, end: self.count-1)
        reloadTracker.didAdd(r)
        return self
    }
    
    // MARK - remove
    func remove(index: Int) -> Self {
        if let r = items.my_remove(index) {
            resetIndex(r.startIndex, end: self.count-1)
            reloadTracker.didRemove(r)
        }
        return self
    }
    
    func removeLast() -> Self {
        self.remove(items.count - 1)
        return self
    }
    
    func remove(range: Range<Int>) -> Self {
        if let r = items.my_remove(range) {
            resetIndex(r.startIndex, end: self.count-1)
            reloadTracker.didRemove(r)
        }
        return self
    }
    
    // MARK - fire
    func fire(_ animation: MYAnimation = .None) -> Self {
        switch reloadTracker.state {
        case .Add:
            println("ADD")
            delegate?.insertRows(reloadTracker.getIndexPaths(index), animation: animation)
        case .Remove:
            println("REMOVE")
            delegate?.deleteRows(reloadTracker.getIndexPaths(index), animation: animation)
        default:
            println("RESET")
            delegate?.reloadSections(NSIndexSet(index: index), animation: animation)
            break
        }
        reloadTracker.didFire(self.count)
        return self
    }
    
    private func resetIndex(begin: Int, end: Int) {
        if begin > end {
            return
        }
        for i in (begin...end) {
            items[i].row = i
            items[i].section = index
        }
    }
}

public extension MYSection {
    var count: Int {
        return items.count
    }
    
    var isEmpty: Bool {
        return items.count == 0
    }

    var first: MYCellViewModel? {
        return items.first
    }
    
    var last: MYCellViewModel? {
        return items.last
    }
}<commit_msg>remove println<commit_after>//
//  MYSection.swift
//  MYTableViewManager
//
//  Created by <NAME> on 2/14/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Foundation

protocol MYSectionDelegate : class {
    func reloadTableView()
    func reloadSections(indexSet: NSIndexSet, animation: MYAnimation)
    func insertRows(indexPaths: [NSIndexPath], animation: MYAnimation)
    func deleteRows(indexPaths: [NSIndexPath], animation: MYAnimation)
    
    func willAddCellViewModels(viewmodels: [MYCellViewModel])
}

public class MYSection {
    internal(set) var index: Int = 0 {
        didSet {
            header?.section = index
            footer?.section = index
            for item in items {
                item.section = index
            }
        }
    }
    weak var delegate: MYSectionDelegate?
    private var items: [MYCellViewModel] = []
    private let reloadTracker = MYReloadTracker()
    
    public var header: MYHeaderFooterViewModel? {
        didSet {
            header?.section = index
            header?.isHeader = true
        }
    }
    public var footer: MYHeaderFooterViewModel? {
        didSet {
            footer?.section = index
            footer?.isHeader = false
        }
    }

    public subscript(index: Int) -> MYCellViewModel? {
        get {
            return items.my_hasIndex(index) ? items[index] : nil
        }
    }
    
    public init() {
    }
}

public extension MYSection {
    // MARK - reset
    func reset() -> Self {
        items = []
        reloadTracker.didReset()
        return self
    }
    
    func reset(viewmodel: MYCellViewModel) -> Self {
        return reset([viewmodel])
    }
    
    func reset(viewmodels: [MYCellViewModel]) -> Self {
        delegate?.willAddCellViewModels(viewmodels)
        items = viewmodels
        resetIndex(0, end: self.count-1)
        reloadTracker.didReset()
        return self
    }
    
    // MARK - apppend
    func append(viewmodel: MYCellViewModel) -> Self {
        return append([viewmodel])
    }
    
    func append(viewmodels: [MYCellViewModel]) -> Self {
        delegate?.willAddCellViewModels(viewmodels)
        let r = items.my_append(viewmodels)
        resetIndex(r.startIndex, end: self.count-1)
        reloadTracker.didAdd(r)
        return self
    }
    
    // MARK - insert
    func insert(viewmodel: MYCellViewModel, atIndex index: Int) -> Self {
        return insert([viewmodel], atIndex: index)
    }
    
    func insert(viewmodels: [MYCellViewModel], atIndex index: Int) -> Self {
        delegate?.willAddCellViewModels(viewmodels)
        let r = items.my_insert(viewmodels, atIndex: index)
        resetIndex(r.startIndex, end: self.count-1)
        reloadTracker.didAdd(r)
        return self
    }
    
    // MARK - remove
    func remove(index: Int) -> Self {
        if let r = items.my_remove(index) {
            resetIndex(r.startIndex, end: self.count-1)
            reloadTracker.didRemove(r)
        }
        return self
    }
    
    func removeLast() -> Self {
        self.remove(items.count - 1)
        return self
    }
    
    func remove(range: Range<Int>) -> Self {
        if let r = items.my_remove(range) {
            resetIndex(r.startIndex, end: self.count-1)
            reloadTracker.didRemove(r)
        }
        return self
    }
    
    // MARK - fire
    func fire(_ animation: MYAnimation = .None) -> Self {
        switch reloadTracker.state {
        case .Add:
            delegate?.insertRows(reloadTracker.getIndexPaths(index), animation: animation)
        case .Remove:
            delegate?.deleteRows(reloadTracker.getIndexPaths(index), animation: animation)
        default:
            delegate?.reloadSections(NSIndexSet(index: index), animation: animation)
            break
        }
        reloadTracker.didFire(self.count)
        return self
    }
    
    private func resetIndex(begin: Int, end: Int) {
        if begin > end {
            return
        }
        for i in (begin...end) {
            items[i].row = i
            items[i].section = index
        }
    }
}

public extension MYSection {
    var count: Int {
        return items.count
    }
    
    var isEmpty: Bool {
        return items.count == 0
    }

    var first: MYCellViewModel? {
        return items.first
    }
    
    var last: MYCellViewModel? {
        return items.last
    }
}
{'fraction_non_alphanumeric': 0.09953729827333258, 'fraction_numerical': 0.004062746868299289, 'mean_word_length': 1.904621435594887, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 35, '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': '4785572', 'n_tokens_mistral': 2593, 'n_tokens_neox': 2504, 'n_words': 590}