<commit_before>//
//  DebugViewPickerCell.swift
//  CardinalDebugToolkit
//
//  Created by <NAME> on 10/5/17.
//

import Foundation
import UIKit

public class DebugViewPickerCell: UITableViewCell {
    private var itemId = ""
    private var values: [String] = []

    private let pickerView = UIPickerView()

    private lazy var toolbar: UIView = {
        let toolbar = UIToolbar(frame: CGRect(x: 0.0, y: 0.0, width: 320.0, height: 44.0))
        toolbar.items = [
            UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil),
            UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(resignFirstResponder))
        ]

        return toolbar
    }()

    public override var canBecomeFirstResponder: Bool {
        return true
    }

    public override var inputView: UIView? {
        return pickerView
    }

    public override var inputAccessoryView: UIView? {
        return toolbar
    }

    weak var delegate: DebugViewControllerDelegate?

    public override func awakeFromNib() {
        super.awakeFromNib()

        pickerView.dataSource = self
        pickerView.delegate = self
    }

    public func configure(withItemId itemId: String, title: String, selectedIndex: Int, values: [String]) {
        self.itemId = itemId
        self.values = values

        textLabel?.text = title
        if selectedIndex < values.count {
            detailTextLabel?.text = values[selectedIndex]
        }
    }
}

// MARK: - UIPickerViewDatasource
extension DebugViewPickerCell: UIPickerViewDataSource {
    public func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }

    public func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return values.count
    }
}

// MARK: - UIPickerViewDelegate
extension DebugViewPickerCell: UIPickerViewDelegate {
    public func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return values[row]
    }

    public func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        detailTextLabel?.text = values[row]
        delegate?.didSelectPickerValue(withIndex: row, forItemWithId: itemId)
    }
}
<commit_msg>Fix initial selection bug in DebugViewPickerCell and add missing license header<commit_after>//
//  DebugViewPickerCell.swift
//  CardinalDebugToolkit
//
//  Copyright (c) 2017 Cardinal Solutions (https://www.cardinalsolutions.com/)
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in all
//  copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//  SOFTWARE.
//

import Foundation
import UIKit

public class DebugViewPickerCell: UITableViewCell {
    private var itemId = ""
    private var values: [String] = []

    private let pickerView = UIPickerView()

    private lazy var toolbar: UIView = {
        let toolbar = UIToolbar(frame: CGRect(x: 0.0, y: 0.0, width: 320.0, height: 44.0))
        toolbar.items = [
            UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil),
            UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(resignFirstResponder))
        ]

        return toolbar
    }()

    public override var canBecomeFirstResponder: Bool {
        return true
    }

    public override var inputView: UIView? {
        return pickerView
    }

    public override var inputAccessoryView: UIView? {
        return toolbar
    }

    weak var delegate: DebugViewControllerDelegate?

    public override func awakeFromNib() {
        super.awakeFromNib()

        pickerView.dataSource = self
        pickerView.delegate = self
    }

    public func configure(withItemId itemId: String, title: String, selectedIndex: Int, values: [String]) {
        self.itemId = itemId
        self.values = values

        textLabel?.text = title
        if selectedIndex < values.count {
            detailTextLabel?.text = values[selectedIndex]
            pickerView.selectRow(selectedIndex, inComponent: 0, animated: false)
        }
    }
}

// MARK: - UIPickerViewDatasource
extension DebugViewPickerCell: UIPickerViewDataSource {
    public func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }

    public func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return values.count
    }
}

// MARK: - UIPickerViewDelegate
extension DebugViewPickerCell: UIPickerViewDelegate {
    public func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return values[row]
    }

    public func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        detailTextLabel?.text = values[row]
        delegate?.didSelectPickerValue(withIndex: row, forItemWithId: itemId)
    }
}

{'fraction_non_alphanumeric': 0.08251105818305546, 'fraction_numerical': 0.005784280367471929, 'mean_word_length': 3.0798056904927136, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 10, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, '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': '3091134', 'n_tokens_mistral': 1700, 'n_tokens_neox': 1608, 'n_words': 526}