<commit_before>//
//  ArticleArray.swift
//  NetNewsWire
//
//  Created by <NAME> on 11/1/17.
//  Copyright © 2017 Ranchero Software. All rights reserved.
//

import Foundation
import Articles

typealias ArticleArray = [Article]

extension Array where Element == Article {

	func articleAtRow(_ row: Int) -> Article? {

		if row < 0 || row == NSNotFound || row > count - 1 {
			return nil
		}
		return self[row]
	}

	func rowOfNextUnreadArticle(_ selectedRow: Int) -> Int? {

		if isEmpty {
			return nil
		}

		var rowIndex = selectedRow
		while(true) {

			rowIndex = rowIndex + 1
			if rowIndex >= count {
				break
			}
			let article = articleAtRow(rowIndex)!
			if !article.status.read {
				return rowIndex
			}
		}

		return nil
	}

	func articlesForIndexes(_ indexes: IndexSet) -> Set<Article> {

		return Set(indexes.compactMap{ (oneIndex) -> Article? in
			return articleAtRow(oneIndex)
		})
	}

	func sortedByDate(_ sortDirection: ComparisonResult) -> ArticleArray {

		let articles = sorted { (article1, article2) -> Bool in
			if sortDirection == .orderedDescending {
				return article1.logicalDatePublished > article2.logicalDatePublished
			}
			return article1.logicalDatePublished < article2.logicalDatePublished<commit_msg>Add additional sort criteria for when published date is equal.  Issue #644<commit_after>//
//  ArticleArray.swift
//  NetNewsWire
//
//  Created by <NAME> on 11/1/17.
//  Copyright © 2017 Ranchero Software. All rights reserved.
//

import Foundation
import Articles

typealias ArticleArray = [Article]

extension Array where Element == Article {

	func articleAtRow(_ row: Int) -> Article? {

		if row < 0 || row == NSNotFound || row > count - 1 {
			return nil
		}
		return self[row]
	}

	func rowOfNextUnreadArticle(_ selectedRow: Int) -> Int? {

		if isEmpty {
			return nil
		}

		var rowIndex = selectedRow
		while(true) {

			rowIndex = rowIndex + 1
			if rowIndex >= count {
				break
			}
			let article = articleAtRow(rowIndex)!
			if !article.status.read {
				return rowIndex
			}
		}

		return nil
	}

	func articlesForIndexes(_ indexes: IndexSet) -> Set<Article> {

		return Set(indexes.compactMap{ (oneIndex) -> Article? in
			return articleAtRow(oneIndex)
		})
	}

	func sortedByDate(_ sortDirection: ComparisonResult) -> ArticleArray {

		let articles = sorted { (article1, article2) -> Bool in
			if article1.logicalDatePublished == article2.logicalDatePublished {
				return article1.articleID < article2.articleID
			}
			if sortDirection == .orderedDescending {
				return article1.logicalDatePublished > article2.logicalDatePublished
			}
			return article1.logicalDatePublished < article2.logicalDatePublished
{'fraction_non_alphanumeric': 0.09985041136873597, 'fraction_numerical': 0.016080777860882575, 'mean_word_length': 3.3425324675324677, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 25, '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': '4020795', 'n_tokens_mistral': 984, 'n_tokens_neox': 810, 'n_words': 230}