<commit_before>/**
 * Copyright IBM Corporation 2015
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

import Foundation
import KituraNet

public struct Headers {
    
    ///
    /// The header storage
    ///
    internal var headers: HeadersContainer
    
    init(headers: HeadersContainer) {
        self.headers = headers
    }
    
    public subscript(key: String) -> String? {
        get {
            return headers[key]?.first
        }
        
        set(newValue) {
            if let newValue = newValue {
                headers[key] = [newValue]
            }
            else {
                headers[key] = nil
            }
        }
    }
    
    ///
    /// Append values to the header
    ///
    /// - Parameter key: the key
    /// - Parameter value: the value
    ///
    public mutating func append(_ key: String, value: String) {
        
        headers.append(key, value: value)
    }
}
<commit_msg>IBM-Swift/Kitura#478 Implemented conformance to Collection protocol<commit_after>/**
 * Copyright IBM Corporation 2015
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

import Foundation
import KituraNet

public struct Headers {
    
    ///
    /// The header storage
    ///
    internal var headers: HeadersContainer
    
    init(headers: HeadersContainer) {
        self.headers = headers
    }
    
    ///
    /// Append values to the header
    ///
    /// - Parameter key: the key
    /// - Parameter value: the value
    ///
    public mutating func append(_ key: String, value: String) {
        
        headers.append(key, value: value)
    }
}

extension Headers: Collection {
    
    public var startIndex: HeadersIndex {return headers.startIndex }
    public var endIndex: HeadersIndex { return headers.endIndex }
    
    public typealias HeadersIndex = DictionaryIndex<String, [String]>
    
    public subscript(key: String) -> String? {
        get {
            return headers[key]?.first
        }
        
        set(newValue) {
            if let newValue = newValue {
                headers[key] = [newValue]
            }
            else {
                headers[key] = nil
            }
        }
    }
    
    
    public subscript(position: HeadersIndex) -> (String, String?) {
        get {
            let (key, value) = headers[position]
            return (key, value.first)
        }
    }
    
    public func index(after i: HeadersIndex) -> HeadersIndex {
        return headers.index(after: i)
    }
}

{'fraction_non_alphanumeric': 0.08976558033161806, 'fraction_numerical': 0.005431675242995998, 'mean_word_length': 2.018981880931838, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1048604', 'n_tokens_mistral': 931, 'n_tokens_neox': 913, 'n_words': 331}