<commit_before>//
//  AccordionMenuTableViewController.swift
//  AccordionTableSwift
//
//  Created by Victor on 2/4/15.
//  Copyright (c) 2015 Pentlab. All rights reserved.
//

import UIKit

class AccordionMenuTableViewController: UITableViewController {
    
    var topItems = [String]()
    var subItems = [[String]]()
    
    var currentItemsExpanded = [Int]()
    var actualPositions = [Int]()
    var total = 0
    
    var parentCellIdentifier = "ParentCell"
    var childCellIdentifier = "ChildCell"
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        for (var i = 0; i < 10; i++) {
            topItems.append("Item \(i + 1)")
            actualPositions.append(-1)
            
            var items = [String]()
            for (var i = 0; i < 3; i++) {
                items.append("Subitem \(i)")
            }
            
            self.subItems.append(items)
        }
        
        total = topItems.count
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    
    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.total
    }
    
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        
        let parent = self.findParent(indexPath.row)
        let idx = self.currentItemsExpanded.indexOf(parent)
        
        let isChild = idx != nil && indexPath.row != self.actualPositions[parent]
        
        var cell : UITableViewCell!
        
        
        if isChild {
            cell = tableView.dequeueReusableCellWithIdentifier(childCellIdentifier, forIndexPath: indexPath) as UITableViewCell
            cell.textLabel!.text = self.subItems[parent][indexPath.row - self.actualPositions[parent] - 1]<commit_msg>Create the function setInitialDataSource<commit_after>//
//  AccordionMenuTableViewController.swift
//  AccordionTableSwift
//
//  Created by Victor on 2/4/15.
//  Copyright (c) 2015 Pentlab. All rights reserved.
//

import UIKit

class AccordionMenuTableViewController: UITableViewController {
    
    var topItems = [String]()
    var subItems = [[String]]()
    
    var currentItemsExpanded = [Int]()
    var actualPositions: [Int]!
    var total = 0
    
    var parentCellIdentifier = "ParentCell"
    var childCellIdentifier = "ChildCell"
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.setInitialDataSource(numberOfRowParents: 10, numberOfRowChildPerParent: 3)
    }
    
    /**
     Set the initial data for test the table view.
     
     - parameter parents: The number of parents cells
     - parameter childs:  Then maximun number of child cells per parent.
     */
    private func setInitialDataSource(numberOfRowParents parents: Int, numberOfRowChildPerParent childs: Int) {
        
        // Init the array with all the values in -1
        self.actualPositions = [Int](count: parents, repeatedValue: -1)
        
        // Create an array with the element "Item index".
        self.topItems = (0..<parents).enumerate().map { "Item \($0.0 + 1)"}
        
        // Create the array of childs using a random number between 0..childs+1 for each parent.
        self.subItems = (0..<parents).map({ _ -> [String] in
            
            let random = Int(arc4random_uniform(UInt32(childs + 1)))
            
            var items = [String]()
            for j in 0..<random {
                items.append("Subitem \(j)")
            }
            
            return items
        })
        
        self.total = topItems.count
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    
    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.total
    }
    
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        
        let parent = self.findParent(indexPath.row)
        let idx = self.currentItemsExpanded.indexOf(parent)
        
        let isChild = idx != nil && indexPath.row != self.actualPositions[parent]
        
        var cell : UITableViewCell!
        
        
        if isChild {
            cell = tableView.dequeueReusableCellWithIdentifier(childCellIdentifier, forIndexPath: indexPath) as UITableViewCell
            cell.textLabel!.text = self.subItems[parent][indexPath.row - self.actualPositions[parent] - 1]
{'fraction_non_alphanumeric': 0.0930378423583525, 'fraction_numerical': 0.009617394940413967, 'mean_word_length': 2.1473684210526316, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, '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': '254029', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1323, 'n_words': 330}